@@ -9,7 +9,6 @@ use rustc_data_structures::fx::FxHashSet;
9
9
use rustc_errors:: struct_span_err;
10
10
use rustc_hir as hir;
11
11
use rustc_hir:: def:: { DefKind , Res } ;
12
- use rustc_hir:: def_id:: LocalDefId ;
13
12
use rustc_index:: vec:: Idx ;
14
13
use rustc_span:: source_map:: { respan, DesugaringKind } ;
15
14
use rustc_span:: symbol:: { kw, sym, Ident } ;
@@ -19,7 +18,6 @@ use smallvec::{smallvec, SmallVec};
19
18
use tracing:: debug;
20
19
21
20
use std:: iter;
22
- use std:: mem;
23
21
24
22
pub ( super ) struct ItemLowerer < ' a , ' lowering , ' hir > {
25
23
pub ( super ) lctx : & ' a mut LoweringContext < ' lowering , ' hir > ,
@@ -46,20 +44,14 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
46
44
}
47
45
48
46
fn visit_item ( & mut self , item : & ' a Item ) {
49
- let hir_id = self . lctx . with_hir_id_owner ( item. id , |lctx| {
50
- let node = lctx. without_in_scope_lifetime_defs ( |lctx| lctx. lower_item ( item) ) ;
51
- hir:: OwnerNode :: Item ( node)
52
- } ) ;
47
+ self . lctx . with_hir_id_owner ( item. id , |lctx| hir:: OwnerNode :: Item ( lctx. lower_item ( item) ) ) ;
53
48
54
- self . lctx . with_parent_item_lifetime_defs ( hir_id, |this| {
55
- let this = & mut ItemLowerer { lctx : this } ;
56
- match item. kind {
57
- ItemKind :: Impl ( box Impl { ref of_trait, .. } ) => {
58
- this. with_trait_impl_ref ( of_trait, |this| visit:: walk_item ( this, item) ) ;
59
- }
60
- _ => visit:: walk_item ( this, item) ,
49
+ match item. kind {
50
+ ItemKind :: Impl ( box Impl { ref of_trait, .. } ) => {
51
+ self . with_trait_impl_ref ( of_trait, |this| visit:: walk_item ( this, item) ) ;
61
52
}
62
- } ) ;
53
+ _ => visit:: walk_item ( self , item) ,
54
+ }
63
55
}
64
56
65
57
fn visit_fn ( & mut self , fk : FnKind < ' a > , sp : Span , _: NodeId ) {
@@ -94,55 +86,6 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
94
86
}
95
87
96
88
impl < ' hir > LoweringContext < ' _ , ' hir > {
97
- // Same as the method above, but accepts `hir::GenericParam`s
98
- // instead of `ast::GenericParam`s.
99
- // This should only be used with generics that have already had their
100
- // in-band lifetimes added. In practice, this means that this function is
101
- // only used when lowering a child item of a trait or impl.
102
- fn with_parent_item_lifetime_defs < T > (
103
- & mut self ,
104
- parent_hir_id : LocalDefId ,
105
- f : impl FnOnce ( & mut Self ) -> T ,
106
- ) -> T {
107
- let old_len = self . in_scope_lifetimes . len ( ) ;
108
-
109
- let parent_generics =
110
- match self . owners [ parent_hir_id] . as_ref ( ) . unwrap ( ) . node ( ) . expect_item ( ) . kind {
111
- hir:: ItemKind :: Impl ( hir:: Impl { ref generics, .. } )
112
- | hir:: ItemKind :: Trait ( _, _, ref generics, ..) => generics. params ,
113
- _ => & [ ] ,
114
- } ;
115
- let lt_def_names = parent_generics. iter ( ) . filter_map ( |param| match param. kind {
116
- hir:: GenericParamKind :: Lifetime { .. } => Some ( param. name . normalize_to_macros_2_0 ( ) ) ,
117
- _ => None ,
118
- } ) ;
119
- self . in_scope_lifetimes . extend ( lt_def_names) ;
120
-
121
- let res = f ( self ) ;
122
-
123
- self . in_scope_lifetimes . truncate ( old_len) ;
124
- res
125
- }
126
-
127
- // Clears (and restores) the `in_scope_lifetimes` field. Used when
128
- // visiting nested items, which never inherit in-scope lifetimes
129
- // from their surrounding environment.
130
- fn without_in_scope_lifetime_defs < T > ( & mut self , f : impl FnOnce ( & mut Self ) -> T ) -> T {
131
- let old_in_scope_lifetimes = mem:: replace ( & mut self . in_scope_lifetimes , vec ! [ ] ) ;
132
-
133
- // this vector is only used when walking over impl headers,
134
- // input types, and the like, and should not be non-empty in
135
- // between items
136
- assert ! ( self . lifetimes_to_define. is_empty( ) ) ;
137
-
138
- let res = f ( self ) ;
139
-
140
- assert ! ( self . in_scope_lifetimes. is_empty( ) ) ;
141
- self . in_scope_lifetimes = old_in_scope_lifetimes;
142
-
143
- res
144
- }
145
-
146
89
pub ( super ) fn lower_mod ( & mut self , items : & [ P < Item > ] , inner : Span ) -> hir:: Mod < ' hir > {
147
90
hir:: Mod {
148
91
inner : self . lower_span ( inner) ,
@@ -248,7 +191,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
248
191
AnonymousLifetimeMode :: PassThrough ,
249
192
|this, idty| {
250
193
let ret_id = asyncness. opt_return_id ( ) ;
251
- this. lower_fn_decl ( & decl, Some ( ( fn_def_id , idty) ) , true , ret_id)
194
+ this. lower_fn_decl ( & decl, Some ( ( id , idty) ) , true , ret_id)
252
195
} ,
253
196
) ;
254
197
let sig = hir:: FnSig {
@@ -358,12 +301,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
358
301
} ,
359
302
) ;
360
303
361
- let new_impl_items =
362
- self . with_in_scope_lifetime_defs ( & ast_generics. params , |this| {
363
- this. arena . alloc_from_iter (
364
- impl_items. iter ( ) . map ( |item| this. lower_impl_item_ref ( item) ) ,
365
- )
366
- } ) ;
304
+ let new_impl_items = self
305
+ . arena
306
+ . alloc_from_iter ( impl_items. iter ( ) . map ( |item| self . lower_impl_item_ref ( item) ) ) ;
367
307
368
308
// `defaultness.has_value()` is never called for an `impl`, always `true` in order
369
309
// to not cause an assertion failure inside the `lower_defaultness` function.
@@ -775,21 +715,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
775
715
}
776
716
AssocItemKind :: Fn ( box Fn { ref sig, ref generics, body : None , .. } ) => {
777
717
let names = self . lower_fn_params_to_names ( & sig. decl ) ;
778
- let ( generics, sig) =
779
- self . lower_method_sig ( generics, sig, trait_item_def_id, false , None ) ;
718
+ let ( generics, sig) = self . lower_method_sig ( generics, sig, i. id , false , None ) ;
780
719
( generics, hir:: TraitItemKind :: Fn ( sig, hir:: TraitFn :: Required ( names) ) )
781
720
}
782
721
AssocItemKind :: Fn ( box Fn { ref sig, ref generics, body : Some ( ref body) , .. } ) => {
783
722
let asyncness = sig. header . asyncness ;
784
723
let body_id =
785
724
self . lower_maybe_async_body ( i. span , & sig. decl , asyncness, Some ( & body) ) ;
786
- let ( generics, sig) = self . lower_method_sig (
787
- generics,
788
- sig,
789
- trait_item_def_id,
790
- false ,
791
- asyncness. opt_return_id ( ) ,
792
- ) ;
725
+ let ( generics, sig) =
726
+ self . lower_method_sig ( generics, sig, i. id , false , asyncness. opt_return_id ( ) ) ;
793
727
( generics, hir:: TraitItemKind :: Fn ( sig, hir:: TraitFn :: Provided ( body_id) ) )
794
728
}
795
729
AssocItemKind :: TyAlias ( box TyAlias { ref generics, ref bounds, ref ty, .. } ) => {
@@ -844,8 +778,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
844
778
}
845
779
846
780
fn lower_impl_item ( & mut self , i : & AssocItem ) -> & ' hir hir:: ImplItem < ' hir > {
847
- let impl_item_def_id = self . resolver . local_def_id ( i. id ) ;
848
-
849
781
let ( generics, kind) = match & i. kind {
850
782
AssocItemKind :: Const ( _, ty, expr) => {
851
783
let ty = self . lower_ty ( ty, ImplTraitContext :: disallowed ( ) ) ;
@@ -863,7 +795,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
863
795
let ( generics, sig) = self . lower_method_sig (
864
796
generics,
865
797
sig,
866
- impl_item_def_id ,
798
+ i . id ,
867
799
impl_trait_return_allow,
868
800
asyncness. opt_return_id ( ) ,
869
801
) ;
@@ -1248,22 +1180,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
1248
1180
& mut self ,
1249
1181
generics : & Generics ,
1250
1182
sig : & FnSig ,
1251
- fn_def_id : LocalDefId ,
1183
+ id : NodeId ,
1252
1184
impl_trait_return_allow : bool ,
1253
1185
is_async : Option < NodeId > ,
1254
1186
) -> ( hir:: Generics < ' hir > , hir:: FnSig < ' hir > ) {
1187
+ let fn_def_id = self . resolver . local_def_id ( id) ;
1255
1188
let header = self . lower_fn_header ( sig. header ) ;
1256
1189
let ( generics, decl) = self . add_in_band_defs (
1257
1190
generics,
1258
1191
fn_def_id,
1259
1192
AnonymousLifetimeMode :: PassThrough ,
1260
1193
|this, idty| {
1261
- this. lower_fn_decl (
1262
- & sig. decl ,
1263
- Some ( ( fn_def_id, idty) ) ,
1264
- impl_trait_return_allow,
1265
- is_async,
1266
- )
1194
+ this. lower_fn_decl ( & sig. decl , Some ( ( id, idty) ) , impl_trait_return_allow, is_async)
1267
1195
} ,
1268
1196
) ;
1269
1197
( generics, hir:: FnSig { header, decl, span : self . lower_span ( sig. span ) } )
@@ -1408,17 +1336,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
1408
1336
ref bounded_ty,
1409
1337
ref bounds,
1410
1338
span,
1411
- } ) => self . with_in_scope_lifetime_defs ( & bound_generic_params , |this| {
1339
+ } ) => {
1412
1340
hir:: WherePredicate :: BoundPredicate ( hir:: WhereBoundPredicate {
1413
- bound_generic_params : this
1341
+ bound_generic_params : self
1414
1342
. lower_generic_params ( bound_generic_params, ImplTraitContext :: disallowed ( ) ) ,
1415
- bounded_ty : this . lower_ty ( bounded_ty, ImplTraitContext :: disallowed ( ) ) ,
1416
- bounds : this . arena . alloc_from_iter ( bounds. iter ( ) . map ( |bound| {
1417
- this . lower_param_bound ( bound, ImplTraitContext :: disallowed ( ) )
1343
+ bounded_ty : self . lower_ty ( bounded_ty, ImplTraitContext :: disallowed ( ) ) ,
1344
+ bounds : self . arena . alloc_from_iter ( bounds. iter ( ) . map ( |bound| {
1345
+ self . lower_param_bound ( bound, ImplTraitContext :: disallowed ( ) )
1418
1346
} ) ) ,
1419
- span : this . lower_span ( span) ,
1347
+ span : self . lower_span ( span) ,
1420
1348
} )
1421
- } ) ,
1349
+ }
1422
1350
WherePredicate :: RegionPredicate ( WhereRegionPredicate {
1423
1351
ref lifetime,
1424
1352
ref bounds,
0 commit comments