@@ -32,8 +32,8 @@ use rustc_middle::{bug, span_bug};
3232use rustc_session:: config:: CrateType ;
3333use rustc_session:: lint;
3434use rustc_session:: lint:: builtin:: {
35- CONFLICTING_REPR_HINTS , INVALID_DOC_ATTRIBUTES , INVALID_MACRO_EXPORT_ARGUMENTS ,
36- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES , UNUSED_ATTRIBUTES ,
35+ CONFLICTING_REPR_HINTS , INVALID_DOC_ATTRIBUTES , UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
36+ UNUSED_ATTRIBUTES ,
3737} ;
3838use rustc_session:: parse:: feature_err;
3939use rustc_span:: edition:: Edition ;
@@ -242,6 +242,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
242242 | AttributeKind :: MacroTransparency ( _)
243243 | AttributeKind :: Dummy ,
244244 ) => { /* do nothing */ }
245+ Attribute :: Parsed ( AttributeKind :: MacroExport { span, .. } ) => {
246+ self . check_macro_export ( hir_id, * span, target)
247+ }
245248 Attribute :: Parsed ( AttributeKind :: AsPtr ( attr_span) ) => {
246249 self . check_applied_to_fn_or_method ( hir_id, * attr_span, span, target)
247250 }
@@ -331,7 +334,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
331334 self . check_macro_use ( hir_id, attr, target)
332335 }
333336 [ sym:: path, ..] => self . check_generic_attr_unparsed ( hir_id, attr, target, Target :: Mod ) ,
334- [ sym:: macro_export, ..] => self . check_macro_export ( hir_id, attr, target) ,
335337 [ sym:: should_panic, ..] => {
336338 self . check_generic_attr_unparsed ( hir_id, attr, target, Target :: Fn )
337339 }
@@ -2294,32 +2296,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22942296 }
22952297 }
22962298
2297- fn check_macro_export ( & self , hir_id : HirId , attr : & Attribute , target : Target ) {
2299+ fn check_macro_export ( & self , hir_id : HirId , attr_span : Span , target : Target ) {
22982300 if target != Target :: MacroDef {
22992301 self . tcx . emit_node_span_lint (
23002302 UNUSED_ATTRIBUTES ,
23012303 hir_id,
2302- attr . span ( ) ,
2304+ attr_span ,
23032305 errors:: MacroExport :: Normal ,
23042306 ) ;
2305- } else if let Some ( meta_item_list) = attr. meta_item_list ( )
2306- && !meta_item_list. is_empty ( )
2307- {
2308- if meta_item_list. len ( ) > 1 {
2309- self . tcx . emit_node_span_lint (
2310- INVALID_MACRO_EXPORT_ARGUMENTS ,
2311- hir_id,
2312- attr. span ( ) ,
2313- errors:: MacroExport :: TooManyItems ,
2314- ) ;
2315- } else if !meta_item_list[ 0 ] . has_name ( sym:: local_inner_macros) {
2316- self . tcx . emit_node_span_lint (
2317- INVALID_MACRO_EXPORT_ARGUMENTS ,
2318- hir_id,
2319- meta_item_list[ 0 ] . span ( ) ,
2320- errors:: MacroExport :: InvalidArgument ,
2321- ) ;
2322- }
23232307 } else {
23242308 // special case when `#[macro_export]` is applied to a macro 2.0
23252309 let ( _, macro_definition, _) = self . tcx . hir_node ( hir_id) . expect_item ( ) . expect_macro ( ) ;
@@ -2329,7 +2313,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23292313 self . tcx . emit_node_span_lint (
23302314 UNUSED_ATTRIBUTES ,
23312315 hir_id,
2332- attr . span ( ) ,
2316+ attr_span ,
23332317 errors:: MacroExport :: OnDeclMacro ,
23342318 ) ;
23352319 }
@@ -2683,7 +2667,9 @@ impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
26832667 // In the long run, the checks should be harmonized.
26842668 if let ItemKind :: Macro ( _, macro_def, _) = item. kind {
26852669 let def_id = item. owner_id . to_def_id ( ) ;
2686- if macro_def. macro_rules && !self . tcx . has_attr ( def_id, sym:: macro_export) {
2670+ if macro_def. macro_rules
2671+ && !find_attr ! ( self . tcx. get_all_attrs( def_id) , AttributeKind :: MacroExport { .. } )
2672+ {
26872673 check_non_exported_macro_for_invalid_attrs ( self . tcx , item) ;
26882674 }
26892675 }
@@ -2813,7 +2799,6 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
28132799 // which were unsuccessfully resolved due to cannot determine
28142800 // resolution for the attribute macro error.
28152801 const ATTRS_TO_CHECK : & [ Symbol ] = & [
2816- sym:: macro_export,
28172802 sym:: automatically_derived,
28182803 sym:: rustc_main,
28192804 sym:: derive,
@@ -2837,6 +2822,8 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
28372822 ( * first_attr_span, sym:: repr)
28382823 } else if let Attribute :: Parsed ( AttributeKind :: Path ( .., span) ) = attr {
28392824 ( * span, sym:: path)
2825+ } else if let Attribute :: Parsed ( AttributeKind :: MacroExport { span, .. } ) = attr {
2826+ ( * span, sym:: macro_export)
28402827 } else {
28412828 continue ;
28422829 } ;
0 commit comments