@@ -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 ) ]
@@ -1680,16 +1680,20 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1680
1680
fn with_scope < F > ( & mut self , id : NodeId , f : F )
1681
1681
where F : FnOnce ( & mut Resolver )
1682
1682
{
1683
- let orig_module = self . current_module ;
1683
+ if let Some ( module) = self . current_module . module_children . borrow ( ) . get ( & id) {
1684
+ // Move down in the graph.
1685
+ let orig_module = :: std:: mem:: replace ( & mut self . current_module , module) ;
1686
+ self . value_ribs . push ( Rib :: new ( ModuleRibKind ( module) ) ) ;
1687
+ self . type_ribs . push ( Rib :: new ( ModuleRibKind ( module) ) ) ;
1684
1688
1685
- // Move down in the graph.
1686
- if let Some ( module) = orig_module. module_children . borrow ( ) . get ( & id) {
1687
- self . current_module = module;
1688
- }
1689
+ f ( self ) ;
1689
1690
1690
- f ( self ) ;
1691
-
1692
- self . current_module = orig_module;
1691
+ self . current_module = orig_module;
1692
+ self . value_ribs . pop ( ) ;
1693
+ self . type_ribs . pop ( ) ;
1694
+ } else {
1695
+ f ( self ) ;
1696
+ }
1693
1697
}
1694
1698
1695
1699
/// Searches the current set of local scopes for labels.
@@ -2266,8 +2270,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2266
2270
2267
2271
if let Some ( anonymous_module) = anonymous_module {
2268
2272
debug ! ( "(resolving block) found anonymous module, moving down" ) ;
2269
- self . value_ribs . push ( Rib :: new ( AnonymousModuleRibKind ( anonymous_module) ) ) ;
2270
- self . type_ribs . push ( Rib :: new ( AnonymousModuleRibKind ( anonymous_module) ) ) ;
2273
+ self . value_ribs . push ( Rib :: new ( ModuleRibKind ( anonymous_module) ) ) ;
2274
+ self . type_ribs . push ( Rib :: new ( ModuleRibKind ( anonymous_module) ) ) ;
2271
2275
self . current_module = anonymous_module;
2272
2276
} else {
2273
2277
self . value_ribs . push ( Rib :: new ( NormalRibKind ) ) ;
@@ -2811,8 +2815,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2811
2815
}
2812
2816
2813
2817
if check_ribs {
2814
- if let Some ( def) = self . resolve_identifier_in_local_ribs ( identifier, namespace) {
2815
- return Some ( def) ;
2818
+ match self . resolve_identifier_in_local_ribs ( identifier, namespace, record_used) {
2819
+ Some ( def) => return Some ( def) ,
2820
+ None => { }
2816
2821
}
2817
2822
}
2818
2823
@@ -2844,7 +2849,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2844
2849
Def :: Local ( _, node_id) => {
2845
2850
for rib in ribs {
2846
2851
match rib. kind {
2847
- NormalRibKind | AnonymousModuleRibKind ( ..) => {
2852
+ NormalRibKind | ModuleRibKind ( ..) => {
2848
2853
// Nothing to do. Continue.
2849
2854
}
2850
2855
ClosureRibKind ( function_id) => {
@@ -2893,7 +2898,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2893
2898
for rib in ribs {
2894
2899
match rib. kind {
2895
2900
NormalRibKind | MethodRibKind | ClosureRibKind ( ..) |
2896
- AnonymousModuleRibKind ( ..) => {
2901
+ ModuleRibKind ( ..) => {
2897
2902
// Nothing to do. Continue.
2898
2903
}
2899
2904
ItemRibKind => {
@@ -3024,7 +3029,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3024
3029
3025
3030
fn resolve_identifier_in_local_ribs ( & mut self ,
3026
3031
ident : hir:: Ident ,
3027
- namespace : Namespace )
3032
+ namespace : Namespace ,
3033
+ record_used : bool )
3028
3034
-> Option < LocalDef > {
3029
3035
// Check the local set of ribs.
3030
3036
let name = match namespace { ValueNS => ident. name , TypeNS => ident. unhygienic_name } ;
@@ -3051,16 +3057,18 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3051
3057
}
3052
3058
}
3053
3059
3054
- if let AnonymousModuleRibKind ( module) = self . get_ribs ( namespace) [ i] . kind {
3060
+ if let ModuleRibKind ( module) = self . get_ribs ( namespace) [ i] . kind {
3055
3061
if let Success ( binding) = self . resolve_name_in_module ( module,
3056
3062
ident. unhygienic_name ,
3057
3063
namespace,
3058
3064
true ,
3059
- true ) {
3065
+ record_used ) {
3060
3066
if let Some ( def) = binding. def ( ) {
3061
3067
return Some ( LocalDef :: from_def ( def) ) ;
3062
3068
}
3063
3069
}
3070
+ // We can only see through anonymous modules
3071
+ if module. def . is_some ( ) { return None ; }
3064
3072
}
3065
3073
}
3066
3074
0 commit comments