@@ -25,7 +25,7 @@ use rustc_middle::ty::subst::{InternalSubsts, Subst};
2525use rustc_middle:: ty:: { self , Const , GenericParamDefKind , TraitRef , Ty , TyCtxt , TypeFoldable } ;
2626use rustc_session:: lint;
2727use rustc_span:: hygiene:: Transparency ;
28- use rustc_span:: symbol:: { kw, Ident } ;
28+ use rustc_span:: symbol:: { kw, sym , Ident } ;
2929use rustc_span:: Span ;
3030use rustc_trait_selection:: traits:: const_evaluatable:: { self , AbstractConst } ;
3131
@@ -507,11 +507,7 @@ impl EmbargoVisitor<'tcx> {
507507 }
508508 match def_kind {
509509 // No type privacy, so can be directly marked as reachable.
510- DefKind :: Const
511- | DefKind :: Macro ( _)
512- | DefKind :: Static
513- | DefKind :: TraitAlias
514- | DefKind :: TyAlias => {
510+ DefKind :: Const | DefKind :: Static | DefKind :: TraitAlias | DefKind :: TyAlias => {
515511 if vis. is_accessible_from ( module. to_def_id ( ) , self . tcx ) {
516512 self . update ( def_id, level) ;
517513 }
@@ -566,6 +562,7 @@ impl EmbargoVisitor<'tcx> {
566562 | DefKind :: ExternCrate
567563 | DefKind :: Use
568564 | DefKind :: ForeignMod
565+ | DefKind :: Macro ( _)
569566 | DefKind :: AnonConst
570567 | DefKind :: Field
571568 | DefKind :: GlobalAsm
@@ -642,11 +639,23 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
642639 }
643640 // Foreign modules inherit level from parents.
644641 hir:: ItemKind :: ForeignMod { .. } => self . prev_level ,
645- // Non-exported macros can't be visible by definition;
646- hir:: ItemKind :: Macro { is_exported : false , .. } => None ,
642+ hir:: ItemKind :: Macro ( ref macro_def) => {
643+ let def_id = item. def_id . to_def_id ( ) ;
644+ let is_macro_export = self . tcx . has_attr ( def_id, sym:: macro_export) ;
645+ match ( macro_def. ast . macro_rules , is_macro_export) {
646+ ( true , true ) => Some ( AccessLevel :: Public ) ,
647+ ( true , false ) => None ,
648+ ( false , _) => {
649+ if item. vis . node . is_pub ( ) {
650+ self . prev_level
651+ } else {
652+ None
653+ }
654+ }
655+ }
656+ }
647657 // Other `pub` items inherit levels from parents.
648- hir:: ItemKind :: Macro { is_exported : true , .. }
649- | hir:: ItemKind :: Const ( ..)
658+ hir:: ItemKind :: Const ( ..)
650659 | hir:: ItemKind :: Enum ( ..)
651660 | hir:: ItemKind :: ExternCrate ( ..)
652661 | hir:: ItemKind :: GlobalAsm ( ..)
@@ -714,17 +723,15 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
714723 }
715724 }
716725 }
717- hir:: ItemKind :: Macro { macro_def : ref md, .. } => {
726+ hir:: ItemKind :: Macro ( ref md) => {
727+ // We have to make sure that the items that macros might reference
728+ // are reachable, since they might be exported transitively.
729+
718730 // Non-opaque macros cannot make other items more accessible than they already are.
719731 let attrs = self . tcx . hir ( ) . attrs ( md. hir_id ( ) ) ;
720732 if attr:: find_transparency ( & self . tcx . sess , & attrs, md. ast . macro_rules ) . 0
721733 != Transparency :: Opaque
722734 {
723- // `#[macro_export]`-ed `macro_rules!` are `Public` since they
724- // ignore their containing path to always appear at the crate root.
725- if md. ast . macro_rules {
726- self . update ( item. def_id , Some ( AccessLevel :: Public ) ) ;
727- }
728735 return ;
729736 }
730737
0 commit comments