@@ -731,8 +731,8 @@ enum RibKind<'a> {
731731 // We're in a constant item. Can't refer to dynamic stuff.
732732 ConstantItemRibKind ,
733733
734- // We passed through an anonymous module.
735- AnonymousModuleRibKind ( Module < ' a > ) ,
734+ // We passed through a module.
735+ ModuleRibKind ( Module < ' a > ) ,
736736}
737737
738738#[ derive( Copy , Clone ) ]
@@ -1653,16 +1653,20 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
16531653 fn with_scope < F > ( & mut self , id : NodeId , f : F )
16541654 where F : FnOnce ( & mut Resolver )
16551655 {
1656- let orig_module = self . current_module ;
1656+ if let Some ( module) = self . current_module . module_children . borrow ( ) . get ( & id) {
1657+ // Move down in the graph.
1658+ let orig_module = :: std:: mem:: replace ( & mut self . current_module , module) ;
1659+ self . value_ribs . push ( Rib :: new ( ModuleRibKind ( module) ) ) ;
1660+ self . type_ribs . push ( Rib :: new ( ModuleRibKind ( module) ) ) ;
16571661
1658- // Move down in the graph.
1659- if let Some ( module) = orig_module. module_children . borrow ( ) . get ( & id) {
1660- self . current_module = module;
1661- }
1662+ f ( self ) ;
16621663
1663- f ( self ) ;
1664-
1665- self . current_module = orig_module;
1664+ self . current_module = orig_module;
1665+ self . value_ribs . pop ( ) ;
1666+ self . type_ribs . pop ( ) ;
1667+ } else {
1668+ f ( self ) ;
1669+ }
16661670 }
16671671
16681672 /// Searches the current set of local scopes for labels.
@@ -2239,8 +2243,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
22392243
22402244 if let Some ( anonymous_module) = anonymous_module {
22412245 debug ! ( "(resolving block) found anonymous module, moving down" ) ;
2242- self . value_ribs . push ( Rib :: new ( AnonymousModuleRibKind ( anonymous_module) ) ) ;
2243- self . type_ribs . push ( Rib :: new ( AnonymousModuleRibKind ( anonymous_module) ) ) ;
2246+ self . value_ribs . push ( Rib :: new ( ModuleRibKind ( anonymous_module) ) ) ;
2247+ self . type_ribs . push ( Rib :: new ( ModuleRibKind ( anonymous_module) ) ) ;
22442248 self . current_module = anonymous_module;
22452249 } else {
22462250 self . value_ribs . push ( Rib :: new ( NormalRibKind ) ) ;
@@ -2817,7 +2821,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
28172821 Def :: Local ( _, node_id) => {
28182822 for rib in ribs {
28192823 match rib. kind {
2820- NormalRibKind | AnonymousModuleRibKind ( ..) => {
2824+ NormalRibKind | ModuleRibKind ( ..) => {
28212825 // Nothing to do. Continue.
28222826 }
28232827 ClosureRibKind ( function_id) => {
@@ -2866,7 +2870,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
28662870 for rib in ribs {
28672871 match rib. kind {
28682872 NormalRibKind | MethodRibKind | ClosureRibKind ( ..) |
2869- AnonymousModuleRibKind ( ..) => {
2873+ ModuleRibKind ( ..) => {
28702874 // Nothing to do. Continue.
28712875 }
28722876 ItemRibKind => {
@@ -3024,7 +3028,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
30243028 }
30253029 }
30263030
3027- if let AnonymousModuleRibKind ( module) = self . get_ribs ( namespace) [ i] . kind {
3031+ if let ModuleRibKind ( module) = self . get_ribs ( namespace) [ i] . kind {
30283032 if let Success ( binding) = self . resolve_name_in_module ( module,
30293033 ident. unhygienic_name ,
30303034 namespace,
@@ -3034,6 +3038,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
30343038 return Some ( LocalDef :: from_def ( def) ) ;
30353039 }
30363040 }
3041+ // We can only see through anonymous modules
3042+ if module. def . is_some ( ) { return None ; }
30373043 }
30383044 }
30393045
0 commit comments