@@ -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 ;
@@ -209,6 +209,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
209209 | AttributeKind :: ConstStabilityIndirect
210210 | AttributeKind :: MacroTransparency ( _) ,
211211 ) => { /* do nothing */ }
212+ Attribute :: Parsed ( AttributeKind :: MacroExport { span, .. } ) => {
213+ self . check_macro_export ( hir_id, * span, target)
214+ }
212215 Attribute :: Parsed ( AttributeKind :: AsPtr ( attr_span) ) => {
213216 self . check_applied_to_fn_or_method ( hir_id, * attr_span, span, target)
214217 }
@@ -308,7 +311,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
308311 self . check_macro_use ( hir_id, attr, target)
309312 }
310313 [ 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) ,
312314 [ sym:: should_panic, ..] => {
313315 self . check_generic_attr_unparsed ( hir_id, attr, target, Target :: Fn )
314316 }
@@ -2280,32 +2282,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22802282 }
22812283 }
22822284
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 ) {
22842286 if target != Target :: MacroDef {
22852287 self . tcx . emit_node_span_lint (
22862288 UNUSED_ATTRIBUTES ,
22872289 hir_id,
2288- attr . span ( ) ,
2290+ attr_span ,
22892291 errors:: MacroExport :: Normal ,
22902292 ) ;
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- }
23092293 } else {
23102294 // special case when `#[macro_export]` is applied to a macro 2.0
23112295 let ( _, macro_definition, _) = self . tcx . hir_node ( hir_id) . expect_item ( ) . expect_macro ( ) ;
@@ -2315,7 +2299,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23152299 self . tcx . emit_node_span_lint (
23162300 UNUSED_ATTRIBUTES ,
23172301 hir_id,
2318- attr . span ( ) ,
2302+ attr_span ,
23192303 errors:: MacroExport :: OnDeclMacro ,
23202304 ) ;
23212305 }
@@ -2669,7 +2653,9 @@ impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
26692653 // In the long run, the checks should be harmonized.
26702654 if let ItemKind :: Macro ( _, macro_def, _) = item. kind {
26712655 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+ {
26732659 check_non_exported_macro_for_invalid_attrs ( self . tcx , item) ;
26742660 }
26752661 }
@@ -2799,7 +2785,6 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
27992785 // which were unsuccessfully resolved due to cannot determine
28002786 // resolution for the attribute macro error.
28012787 const ATTRS_TO_CHECK : & [ Symbol ] = & [
2802- sym:: macro_export,
28032788 sym:: automatically_derived,
28042789 sym:: rustc_main,
28052790 sym:: derive,
@@ -2823,6 +2808,8 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) {
28232808 ( * first_attr_span, sym:: repr)
28242809 } else if let Attribute :: Parsed ( AttributeKind :: Path ( .., span) ) = attr {
28252810 ( * span, sym:: path)
2811+ } else if let Attribute :: Parsed ( AttributeKind :: MacroExport { span, .. } ) = attr {
2812+ ( * span, sym:: macro_export)
28262813 } else {
28272814 continue ;
28282815 } ;
0 commit comments