@@ -723,7 +723,7 @@ enum FallbackSuggestion {
723
723
}
724
724
725
725
#[ derive( Copy , Clone ) ]
726
- enum TypeParameters < ' tcx , ' a > {
726
+ enum TypeParameters < ' a > {
727
727
NoTypeParameters ,
728
728
HasTypeParameters ( // Type parameters.
729
729
& ' a Generics ,
@@ -733,13 +733,13 @@ enum TypeParameters<'tcx, 'a> {
733
733
ParamSpace ,
734
734
735
735
// The kind of the rib used for type parameters.
736
- RibKind < ' tcx > ) ,
736
+ RibKind ) ,
737
737
}
738
738
739
739
// The rib kind controls the translation of local
740
740
// definitions (`Def::Local`) to upvars (`Def::Upvar`).
741
741
#[ derive( Copy , Clone , Debug ) ]
742
- enum RibKind < ' a > {
742
+ enum RibKind {
743
743
// No translation needs to be applied.
744
744
NormalRibKind ,
745
745
@@ -758,9 +758,6 @@ enum RibKind<'a> {
758
758
759
759
// We're in a constant item. Can't refer to dynamic stuff.
760
760
ConstantItemRibKind ,
761
-
762
- // We passed through an anonymous module.
763
- AnonymousModuleRibKind ( Module < ' a > ) ,
764
761
}
765
762
766
763
#[ derive( Copy , Clone ) ]
@@ -802,13 +799,13 @@ enum BareIdentifierPatternResolution {
802
799
803
800
/// One local scope.
804
801
#[ derive( Debug ) ]
805
- struct Rib < ' a > {
802
+ struct Rib {
806
803
bindings : HashMap < Name , DefLike > ,
807
- kind : RibKind < ' a > ,
804
+ kind : RibKind ,
808
805
}
809
806
810
- impl < ' a > Rib < ' a > {
811
- fn new ( kind : RibKind < ' a > ) -> Rib < ' a > {
807
+ impl Rib {
808
+ fn new ( kind : RibKind ) -> Rib {
812
809
Rib {
813
810
bindings : HashMap :: new ( ) ,
814
811
kind : kind,
@@ -1183,13 +1180,13 @@ pub struct Resolver<'a, 'tcx: 'a> {
1183
1180
1184
1181
// The current set of local scopes, for values.
1185
1182
// FIXME #4948: Reuse ribs to avoid allocation.
1186
- value_ribs : Vec < Rib < ' a > > ,
1183
+ value_ribs : Vec < Rib > ,
1187
1184
1188
1185
// The current set of local scopes, for types.
1189
- type_ribs : Vec < Rib < ' a > > ,
1186
+ type_ribs : Vec < Rib > ,
1190
1187
1191
1188
// The current set of local scopes, for labels.
1192
- label_ribs : Vec < Rib < ' a > > ,
1189
+ label_ribs : Vec < Rib > ,
1193
1190
1194
1191
// The trait that the current context can refer to.
1195
1192
current_trait_ref : Option < ( DefId , TraitRef ) > ,
@@ -1307,10 +1304,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1307
1304
self . arenas . modules . alloc ( ModuleS :: new ( parent_link, def, external, is_public) )
1308
1305
}
1309
1306
1310
- fn get_ribs < ' b > ( & ' b mut self , ns : Namespace ) -> & ' b mut Vec < Rib < ' a > > {
1311
- match ns { ValueNS => & mut self . value_ribs , TypeNS => & mut self . type_ribs }
1312
- }
1313
-
1314
1307
#[ inline]
1315
1308
fn record_import_use ( & mut self , import_id : NodeId , name : Name ) {
1316
1309
if !self . make_glob_map {
@@ -2129,7 +2122,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2129
2122
}
2130
2123
}
2131
2124
2132
- fn with_type_parameter_rib < ' b , F > ( & ' b mut self , type_parameters : TypeParameters < ' a , ' b > , f : F )
2125
+ fn with_type_parameter_rib < F > ( & mut self , type_parameters : TypeParameters , f : F )
2133
2126
where F : FnOnce ( & mut Resolver )
2134
2127
{
2135
2128
match type_parameters {
@@ -2198,7 +2191,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2198
2191
}
2199
2192
}
2200
2193
2201
- fn resolve_function ( & mut self , rib_kind : RibKind < ' a > , declaration : & FnDecl , block : & Block ) {
2194
+ fn resolve_function ( & mut self , rib_kind : RibKind , declaration : & FnDecl , block : & Block ) {
2202
2195
// Create a value rib for the function.
2203
2196
self . value_ribs . push ( Rib :: new ( rib_kind) ) ;
2204
2197
@@ -2501,18 +2494,18 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2501
2494
2502
2495
fn resolve_block ( & mut self , block : & Block ) {
2503
2496
debug ! ( "(resolving block) entering block" ) ;
2497
+ self . value_ribs . push ( Rib :: new ( NormalRibKind ) ) ;
2498
+
2504
2499
// Move down in the graph, if there's an anonymous module rooted here.
2505
2500
let orig_module = self . current_module ;
2506
- let anonymous_module =
2507
- orig_module. anonymous_children . borrow ( ) . get ( & block. id ) . map ( |module| * module) ;
2508
-
2509
- if let Some ( anonymous_module) = anonymous_module {
2510
- debug ! ( "(resolving block) found anonymous module, moving down" ) ;
2511
- self . value_ribs . push ( Rib :: new ( AnonymousModuleRibKind ( anonymous_module) ) ) ;
2512
- self . type_ribs . push ( Rib :: new ( AnonymousModuleRibKind ( anonymous_module) ) ) ;
2513
- self . current_module = anonymous_module;
2514
- } else {
2515
- self . value_ribs . push ( Rib :: new ( NormalRibKind ) ) ;
2501
+ match orig_module. anonymous_children . borrow ( ) . get ( & block. id ) {
2502
+ None => {
2503
+ // Nothing to do.
2504
+ }
2505
+ Some ( anonymous_module) => {
2506
+ debug ! ( "(resolving block) found anonymous module, moving down" ) ;
2507
+ self . current_module = anonymous_module;
2508
+ }
2516
2509
}
2517
2510
2518
2511
// Check for imports appearing after non-item statements.
@@ -2545,9 +2538,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2545
2538
if !self . resolved {
2546
2539
self . current_module = orig_module;
2547
2540
self . value_ribs . pop ( ) ;
2548
- if let Some ( _) = anonymous_module {
2549
- self . type_ribs . pop ( ) ;
2550
- }
2551
2541
}
2552
2542
debug ! ( "(resolving block) leaving block" ) ;
2553
2543
}
@@ -3086,7 +3076,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3086
3076
Def :: Local ( _, node_id) => {
3087
3077
for rib in ribs {
3088
3078
match rib. kind {
3089
- NormalRibKind | AnonymousModuleRibKind ( .. ) => {
3079
+ NormalRibKind => {
3090
3080
// Nothing to do. Continue.
3091
3081
}
3092
3082
ClosureRibKind ( function_id) => {
@@ -3134,8 +3124,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3134
3124
Def :: TyParam ( ..) | Def :: SelfTy ( ..) => {
3135
3125
for rib in ribs {
3136
3126
match rib. kind {
3137
- NormalRibKind | MethodRibKind | ClosureRibKind ( ..) |
3138
- AnonymousModuleRibKind ( ..) => {
3127
+ NormalRibKind | MethodRibKind | ClosureRibKind ( ..) => {
3139
3128
// Nothing to do. Continue.
3140
3129
}
3141
3130
ItemRibKind => {
@@ -3286,10 +3275,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3286
3275
namespace : Namespace )
3287
3276
-> Option < LocalDef > {
3288
3277
// Check the local set of ribs.
3289
- let name = match namespace { ValueNS => ident. name , TypeNS => ident. unhygienic_name } ;
3278
+ let ( name, ribs) = match namespace {
3279
+ ValueNS => ( ident. name , & self . value_ribs ) ,
3280
+ TypeNS => ( ident. unhygienic_name , & self . type_ribs ) ,
3281
+ } ;
3290
3282
3291
- for i in ( 0 .. self . get_ribs ( namespace ) . len ( ) ) . rev ( ) {
3292
- if let Some ( def_like) = self . get_ribs ( namespace ) [ i ] . bindings . get ( & name) . cloned ( ) {
3283
+ for ( i , rib ) in ribs . iter ( ) . enumerate ( ) . rev ( ) {
3284
+ if let Some ( def_like) = rib . bindings . get ( & name) . cloned ( ) {
3293
3285
match def_like {
3294
3286
DlDef ( def) => {
3295
3287
debug ! ( "(resolving path in local ribs) resolved `{}` to {:?} at {}" ,
@@ -3309,18 +3301,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3309
3301
}
3310
3302
}
3311
3303
}
3312
-
3313
- if let AnonymousModuleRibKind ( module) = self . get_ribs ( namespace) [ i] . kind {
3314
- if let Success ( ( target, _) ) = self . resolve_name_in_module ( module,
3315
- ident. unhygienic_name ,
3316
- namespace,
3317
- PathSearch ,
3318
- true ) {
3319
- if let Some ( def) = target. binding . def ( ) {
3320
- return Some ( LocalDef :: from_def ( def) ) ;
3321
- }
3322
- }
3323
- }
3324
3304
}
3325
3305
3326
3306
None
0 commit comments