@@ -731,8 +731,8 @@ enum RibKind<'a> {
731
731
// We're in a constant item. Can't refer to dynamic stuff.
732
732
ConstantItemRibKind ,
733
733
734
- // We passed through an anonymous module.
735
- AnonymousModuleRibKind ( Module < ' a > ) ,
734
+ // We passed through a module.
735
+ ModuleRibKind ( Module < ' a > ) ,
736
736
}
737
737
738
738
#[ derive( Copy , Clone ) ]
@@ -1653,16 +1653,20 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1653
1653
fn with_scope < F > ( & mut self , id : NodeId , f : F )
1654
1654
where F : FnOnce ( & mut Resolver )
1655
1655
{
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) ) ) ;
1657
1661
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 ) ;
1662
1663
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
+ }
1666
1670
}
1667
1671
1668
1672
/// Searches the current set of local scopes for labels.
@@ -2239,8 +2243,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2239
2243
2240
2244
if let Some ( anonymous_module) = anonymous_module {
2241
2245
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) ) ) ;
2244
2248
self . current_module = anonymous_module;
2245
2249
} else {
2246
2250
self . value_ribs . push ( Rib :: new ( NormalRibKind ) ) ;
@@ -2817,7 +2821,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2817
2821
Def :: Local ( _, node_id) => {
2818
2822
for rib in ribs {
2819
2823
match rib. kind {
2820
- NormalRibKind | AnonymousModuleRibKind ( ..) => {
2824
+ NormalRibKind | ModuleRibKind ( ..) => {
2821
2825
// Nothing to do. Continue.
2822
2826
}
2823
2827
ClosureRibKind ( function_id) => {
@@ -2866,7 +2870,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2866
2870
for rib in ribs {
2867
2871
match rib. kind {
2868
2872
NormalRibKind | MethodRibKind | ClosureRibKind ( ..) |
2869
- AnonymousModuleRibKind ( ..) => {
2873
+ ModuleRibKind ( ..) => {
2870
2874
// Nothing to do. Continue.
2871
2875
}
2872
2876
ItemRibKind => {
@@ -3024,7 +3028,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3024
3028
}
3025
3029
}
3026
3030
3027
- if let AnonymousModuleRibKind ( module) = self . get_ribs ( namespace) [ i] . kind {
3031
+ if let ModuleRibKind ( module) = self . get_ribs ( namespace) [ i] . kind {
3028
3032
if let Success ( binding) = self . resolve_name_in_module ( module,
3029
3033
ident. unhygienic_name ,
3030
3034
namespace,
@@ -3034,6 +3038,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3034
3038
return Some ( LocalDef :: from_def ( def) ) ;
3035
3039
}
3036
3040
}
3041
+ // We can only see through anonymous modules
3042
+ if module. def . is_some ( ) { return None ; }
3037
3043
}
3038
3044
}
3039
3045
0 commit comments