@@ -32,8 +32,8 @@ use rustc_middle::{bug, span_bug};
32
32
use rustc_session:: config:: CrateType ;
33
33
use rustc_session:: lint;
34
34
use 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 ,
37
37
} ;
38
38
use rustc_session:: parse:: feature_err;
39
39
use rustc_span:: edition:: Edition ;
@@ -209,6 +209,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
209
209
| AttributeKind :: ConstStabilityIndirect
210
210
| AttributeKind :: MacroTransparency ( _) ,
211
211
) => { /* do nothing */ }
212
+ Attribute :: Parsed ( AttributeKind :: MacroExport { span, .. } ) => {
213
+ self . check_macro_export ( hir_id, * span, target)
214
+ }
212
215
Attribute :: Parsed ( AttributeKind :: AsPtr ( attr_span) ) => {
213
216
self . check_applied_to_fn_or_method ( hir_id, * attr_span, span, target)
214
217
}
@@ -308,7 +311,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
308
311
self . check_macro_use ( hir_id, attr, target)
309
312
}
310
313
[ sym:: path, ..] => self . check_generic_attr_unparsed ( hir_id, attr, target, Target :: Mod ) ,
311
- [ sym:: macro_export, ..] => self . check_macro_export ( hir_id, attr, target) ,
312
314
[ sym:: should_panic, ..] => {
313
315
self . check_generic_attr_unparsed ( hir_id, attr, target, Target :: Fn )
314
316
}
@@ -2280,32 +2282,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2280
2282
}
2281
2283
}
2282
2284
2283
- fn check_macro_export ( & self , hir_id : HirId , attr : & Attribute , target : Target ) {
2285
+ fn check_macro_export ( & self , hir_id : HirId , attr_span : Span , target : Target ) {
2284
2286
if target != Target :: MacroDef {
2285
2287
self . tcx . emit_node_span_lint (
2286
2288
UNUSED_ATTRIBUTES ,
2287
2289
hir_id,
2288
- attr . span ( ) ,
2290
+ attr_span ,
2289
2291
errors:: MacroExport :: Normal ,
2290
2292
) ;
2291
- } else if let Some ( meta_item_list) = attr. meta_item_list ( )
2292
- && !meta_item_list. is_empty ( )
2293
- {
2294
- if meta_item_list. len ( ) > 1 {
2295
- self . tcx . emit_node_span_lint (
2296
- INVALID_MACRO_EXPORT_ARGUMENTS ,
2297
- hir_id,
2298
- attr. span ( ) ,
2299
- errors:: MacroExport :: TooManyItems ,
2300
- ) ;
2301
- } else if !meta_item_list[ 0 ] . has_name ( sym:: local_inner_macros) {
2302
- self . tcx . emit_node_span_lint (
2303
- INVALID_MACRO_EXPORT_ARGUMENTS ,
2304
- hir_id,
2305
- meta_item_list[ 0 ] . span ( ) ,
2306
- errors:: MacroExport :: InvalidArgument ,
2307
- ) ;
2308
- }
2309
2293
} else {
2310
2294
// special case when `#[macro_export]` is applied to a macro 2.0
2311
2295
let ( _, macro_definition, _) = self . tcx . hir_node ( hir_id) . expect_item ( ) . expect_macro ( ) ;
@@ -2315,7 +2299,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2315
2299
self . tcx . emit_node_span_lint (
2316
2300
UNUSED_ATTRIBUTES ,
2317
2301
hir_id,
2318
- attr . span ( ) ,
2302
+ attr_span ,
2319
2303
errors:: MacroExport :: OnDeclMacro ,
2320
2304
) ;
2321
2305
}
@@ -2669,7 +2653,9 @@ impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
2669
2653
// In the long run, the checks should be harmonized.
2670
2654
if let ItemKind :: Macro ( _, macro_def, _) = item. kind {
2671
2655
let def_id = item. owner_id . to_def_id ( ) ;
2672
- if macro_def. macro_rules && !self . tcx . has_attr ( def_id, sym:: macro_export) {
2656
+ if macro_def. macro_rules
2657
+ && !find_attr ! ( self . tcx. get_all_attrs( def_id) , AttributeKind :: MacroExport { .. } )
2658
+ {
2673
2659
check_non_exported_macro_for_invalid_attrs ( self . tcx , item) ;
2674
2660
}
2675
2661
}
@@ -2799,7 +2785,6 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
2799
2785
// which were unsuccessfully resolved due to cannot determine
2800
2786
// resolution for the attribute macro error.
2801
2787
const ATTRS_TO_CHECK : & [ Symbol ] = & [
2802
- sym:: macro_export,
2803
2788
sym:: automatically_derived,
2804
2789
sym:: rustc_main,
2805
2790
sym:: derive,
@@ -2823,6 +2808,8 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
2823
2808
( * first_attr_span, sym:: repr)
2824
2809
} else if let Attribute :: Parsed ( AttributeKind :: Path ( .., span) ) = attr {
2825
2810
( * span, sym:: path)
2811
+ } else if let Attribute :: Parsed ( AttributeKind :: MacroExport { span, .. } ) = attr {
2812
+ ( * span, sym:: macro_export)
2826
2813
} else {
2827
2814
continue ;
2828
2815
} ;
0 commit comments