@@ -12,7 +12,7 @@ use rustc_ast::NodeId;
1212use rustc_data_structures:: fx:: FxHashSet ;
1313use rustc_data_structures:: intern:: Interned ;
1414use rustc_errors:: { pluralize, struct_span_err, Applicability , MultiSpan } ;
15- use rustc_hir:: def:: { self , PartialRes } ;
15+ use rustc_hir:: def:: { self , DefKind , PartialRes } ;
1616use rustc_middle:: metadata:: ModChild ;
1717use rustc_middle:: span_bug;
1818use rustc_middle:: ty;
@@ -922,11 +922,35 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
922922 . note ( & format ! ( "consider declaring type or module `{}` with `pub`" , ident) )
923923 . emit ( ) ;
924924 } else {
925- let note_msg =
926- format ! ( "consider marking `{}` as `pub` in the imported module" , ident) ;
927- struct_span_err ! ( self . r. session, import. span, E0364 , "{}" , error_msg)
928- . span_note ( import. span , & note_msg)
929- . emit ( ) ;
925+ let mut err =
926+ struct_span_err ! ( self . r. session, import. span, E0364 , "{error_msg}" ) ;
927+ match binding. kind {
928+ NameBindingKind :: Res ( Res :: Def ( DefKind :: Macro ( _) , _def_id) , _)
929+ // exclude decl_macro
930+ if !self . r . session . features_untracked ( ) . decl_macro
931+ || !self
932+ . r
933+ . session
934+ . source_map ( )
935+ . span_to_snippet ( binding. span )
936+ . map ( |snippet| snippet. starts_with ( "macro " ) )
937+ . unwrap_or ( true ) =>
938+ {
939+ err. span_help (
940+ binding. span ,
941+ "consider adding a `#[macro_export]` to the macro in the imported module" ,
942+ ) ;
943+ }
944+ _ => {
945+ err. span_note (
946+ import. span ,
947+ & format ! (
948+ "consider marking `{ident}` as `pub` in the imported module"
949+ ) ,
950+ ) ;
951+ }
952+ }
953+ err. emit ( ) ;
930954 }
931955 }
932956 }
0 commit comments