@@ -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 ;
@@ -242,6 +242,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
242
242
| AttributeKind :: MacroTransparency ( _)
243
243
| AttributeKind :: Dummy ,
244
244
) => { /* do nothing */ }
245
+ Attribute :: Parsed ( AttributeKind :: MacroExport { span, .. } ) => {
246
+ self . check_macro_export ( hir_id, * span, target)
247
+ }
245
248
Attribute :: Parsed ( AttributeKind :: AsPtr ( attr_span) ) => {
246
249
self . check_applied_to_fn_or_method ( hir_id, * attr_span, span, target)
247
250
}
@@ -331,7 +334,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
331
334
self . check_macro_use ( hir_id, attr, target)
332
335
}
333
336
[ 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) ,
335
337
[ sym:: should_panic, ..] => {
336
338
self . check_generic_attr_unparsed ( hir_id, attr, target, Target :: Fn )
337
339
}
@@ -2294,32 +2296,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2294
2296
}
2295
2297
}
2296
2298
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 ) {
2298
2300
if target != Target :: MacroDef {
2299
2301
self . tcx . emit_node_span_lint (
2300
2302
UNUSED_ATTRIBUTES ,
2301
2303
hir_id,
2302
- attr . span ( ) ,
2304
+ attr_span ,
2303
2305
errors:: MacroExport :: Normal ,
2304
2306
) ;
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
- }
2323
2307
} else {
2324
2308
// special case when `#[macro_export]` is applied to a macro 2.0
2325
2309
let ( _, macro_definition, _) = self . tcx . hir_node ( hir_id) . expect_item ( ) . expect_macro ( ) ;
@@ -2329,7 +2313,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
2329
2313
self . tcx . emit_node_span_lint (
2330
2314
UNUSED_ATTRIBUTES ,
2331
2315
hir_id,
2332
- attr . span ( ) ,
2316
+ attr_span ,
2333
2317
errors:: MacroExport :: OnDeclMacro ,
2334
2318
) ;
2335
2319
}
@@ -2683,7 +2667,9 @@ impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
2683
2667
// In the long run, the checks should be harmonized.
2684
2668
if let ItemKind :: Macro ( _, macro_def, _) = item. kind {
2685
2669
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
+ {
2687
2673
check_non_exported_macro_for_invalid_attrs ( self . tcx , item) ;
2688
2674
}
2689
2675
}
@@ -2813,7 +2799,6 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
2813
2799
// which were unsuccessfully resolved due to cannot determine
2814
2800
// resolution for the attribute macro error.
2815
2801
const ATTRS_TO_CHECK : & [ Symbol ] = & [
2816
- sym:: macro_export,
2817
2802
sym:: automatically_derived,
2818
2803
sym:: rustc_main,
2819
2804
sym:: derive,
@@ -2837,6 +2822,8 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
2837
2822
( * first_attr_span, sym:: repr)
2838
2823
} else if let Attribute :: Parsed ( AttributeKind :: Path ( .., span) ) = attr {
2839
2824
( * span, sym:: path)
2825
+ } else if let Attribute :: Parsed ( AttributeKind :: MacroExport { span, .. } ) = attr {
2826
+ ( * span, sym:: macro_export)
2840
2827
} else {
2841
2828
continue ;
2842
2829
} ;
0 commit comments