@@ -60,10 +60,12 @@ impl<'tcx, 'interner> Visitor<'tcx> for ItemLowerer<'tcx, 'interner> {
60
60
fn visit_item ( & mut self , item : & ' tcx Item ) {
61
61
let mut item_hir_id = None ;
62
62
self . lctx . with_hir_id_owner ( item. id , |lctx| {
63
- if let Some ( hir_item) = lctx. lower_item ( item) {
64
- item_hir_id = Some ( hir_item. hir_id ) ;
65
- lctx. insert_item ( hir_item) ;
66
- }
63
+ lctx. without_in_scope_lifetime_defs ( |lctx| {
64
+ if let Some ( hir_item) = lctx. lower_item ( item) {
65
+ item_hir_id = Some ( hir_item. hir_id ) ;
66
+ lctx. insert_item ( hir_item) ;
67
+ }
68
+ } )
67
69
} ) ;
68
70
69
71
if let Some ( hir_id) = item_hir_id {
@@ -123,7 +125,7 @@ impl LoweringContext<'_> {
123
125
_ => & [ ] ,
124
126
} ;
125
127
let lt_def_names = parent_generics. iter ( ) . filter_map ( |param| match param. kind {
126
- hir:: GenericParamKind :: Lifetime { .. } => Some ( param. name . ident ( ) . modern ( ) ) ,
128
+ hir:: GenericParamKind :: Lifetime { .. } => Some ( param. name . modern ( ) ) ,
127
129
_ => None ,
128
130
} ) ;
129
131
self . in_scope_lifetimes . extend ( lt_def_names) ;
@@ -134,6 +136,28 @@ impl LoweringContext<'_> {
134
136
res
135
137
}
136
138
139
+ // Clears (and restores) the `in_scope_lifetimes` field. Used when
140
+ // visiting nested items, which never inherit in-scope lifetimes
141
+ // from their surrounding environment.
142
+ fn without_in_scope_lifetime_defs < T > (
143
+ & mut self ,
144
+ f : impl FnOnce ( & mut LoweringContext < ' _ > ) -> T ,
145
+ ) -> T {
146
+ let old_in_scope_lifetimes = std:: mem:: replace ( & mut self . in_scope_lifetimes , vec ! [ ] ) ;
147
+
148
+ // this vector is only used when walking over impl headers,
149
+ // input types, and the like, and should not be non-empty in
150
+ // between items
151
+ assert ! ( self . lifetimes_to_define. is_empty( ) ) ;
152
+
153
+ let res = f ( self ) ;
154
+
155
+ assert ! ( self . in_scope_lifetimes. is_empty( ) ) ;
156
+ self . in_scope_lifetimes = old_in_scope_lifetimes;
157
+
158
+ res
159
+ }
160
+
137
161
pub ( super ) fn lower_mod ( & mut self , m : & Mod ) -> hir:: Mod {
138
162
hir:: Mod {
139
163
inner : m. inner ,
0 commit comments