@@ -547,6 +547,13 @@ impl ModuleKind {
547547 ModuleKind :: Def ( .., name) => name,
548548 }
549549 }
550+
551+ fn opt_def_id ( & self ) -> Option < DefId > {
552+ match self {
553+ ModuleKind :: Def ( _, def_id, _) => Some ( * def_id) ,
554+ _ => None ,
555+ }
556+ }
550557}
551558
552559/// Combination of a symbol and its macros 2.0 normalized hygiene context.
@@ -784,10 +791,7 @@ impl<'ra> Module<'ra> {
784791 }
785792
786793 fn opt_def_id ( self ) -> Option < DefId > {
787- match self . kind {
788- ModuleKind :: Def ( _, def_id, _) => Some ( def_id) ,
789- _ => None ,
790- }
794+ self . kind . opt_def_id ( )
791795 }
792796
793797 // `self` resolves to the first module ancestor that `is_normal`.
@@ -1450,14 +1454,19 @@ impl<'ra> ResolverArenas<'ra> {
14501454 & ' ra self ,
14511455 parent : Option < Module < ' ra > > ,
14521456 kind : ModuleKind ,
1457+ vis : Visibility < DefId > ,
14531458 expn_id : ExpnId ,
14541459 span : Span ,
14551460 no_implicit_prelude : bool ,
14561461 ) -> Module < ' ra > {
14571462 let self_decl = match kind {
1458- ModuleKind :: Def ( def_kind, def_id, _) => {
1459- Some ( self . new_pub_def_decl ( Res :: Def ( def_kind, def_id) , span, LocalExpnId :: ROOT ) )
1460- }
1463+ ModuleKind :: Def ( def_kind, def_id, _) => Some ( self . new_def_decl (
1464+ Res :: Def ( def_kind, def_id) ,
1465+ vis,
1466+ span,
1467+ LocalExpnId :: ROOT ,
1468+ None ,
1469+ ) ) ,
14611470 ModuleKind :: Block => None ,
14621471 } ;
14631472 Module ( Interned :: new_unchecked ( self . modules . alloc ( ModuleData :: new (
@@ -1639,6 +1648,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16391648 let graph_root = arenas. new_module (
16401649 None ,
16411650 ModuleKind :: Def ( DefKind :: Mod , root_def_id, None ) ,
1651+ Visibility :: Public ,
16421652 ExpnId :: root ( ) ,
16431653 crate_span,
16441654 attr:: contains_name ( attrs, sym:: no_implicit_prelude) ,
@@ -1648,6 +1658,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16481658 let empty_module = arenas. new_module (
16491659 None ,
16501660 ModuleKind :: Def ( DefKind :: Mod , root_def_id, None ) ,
1661+ Visibility :: Public ,
16511662 ExpnId :: root ( ) ,
16521663 DUMMY_SP ,
16531664 true ,
@@ -1749,7 +1760,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17491760 span : Span ,
17501761 no_implicit_prelude : bool ,
17511762 ) -> Module < ' ra > {
1752- let module = self . arenas . new_module ( parent, kind, expn_id, span, no_implicit_prelude) ;
1763+ let vis =
1764+ kind. opt_def_id ( ) . map_or ( Visibility :: Public , |def_id| self . tcx . visibility ( def_id) ) ;
1765+ let module = self . arenas . new_module ( parent, kind, vis, expn_id, span, no_implicit_prelude) ;
17531766 self . local_modules . push ( module) ;
17541767 if let Some ( def_id) = module. opt_def_id ( ) {
17551768 self . local_module_map . insert ( def_id. expect_local ( ) , module) ;
@@ -1765,7 +1778,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17651778 span : Span ,
17661779 no_implicit_prelude : bool ,
17671780 ) -> Module < ' ra > {
1768- let module = self . arenas . new_module ( parent, kind, expn_id, span, no_implicit_prelude) ;
1781+ let vis =
1782+ kind. opt_def_id ( ) . map_or ( Visibility :: Public , |def_id| self . tcx . visibility ( def_id) ) ;
1783+ let module = self . arenas . new_module ( parent, kind, vis, expn_id, span, no_implicit_prelude) ;
17691784 self . extern_module_map . borrow_mut ( ) . insert ( module. def_id ( ) , module) ;
17701785 module
17711786 }
0 commit comments