@@ -9,7 +9,6 @@ use rustc_data_structures::fx::FxHashSet;
99use rustc_errors:: struct_span_err;
1010use rustc_hir as hir;
1111use rustc_hir:: def:: { DefKind , Res } ;
12- use rustc_hir:: def_id:: LocalDefId ;
1312use rustc_index:: vec:: Idx ;
1413use rustc_span:: source_map:: { respan, DesugaringKind } ;
1514use rustc_span:: symbol:: { kw, sym, Ident } ;
@@ -19,7 +18,6 @@ use smallvec::{smallvec, SmallVec};
1918use tracing:: debug;
2019
2120use std:: iter;
22- use std:: mem;
2321
2422pub ( super ) struct ItemLowerer < ' a , ' lowering , ' hir > {
2523 pub ( super ) lctx : & ' a mut LoweringContext < ' lowering , ' hir > ,
@@ -46,20 +44,14 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
4644 }
4745
4846 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) ) ) ;
5348
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) ) ;
6152 }
62- } ) ;
53+ _ => visit:: walk_item ( self , item) ,
54+ }
6355 }
6456
6557 fn visit_fn ( & mut self , fk : FnKind < ' a > , sp : Span , _: NodeId ) {
@@ -94,55 +86,6 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> {
9486}
9587
9688impl < ' 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-
14689 pub ( super ) fn lower_mod ( & mut self , items : & [ P < Item > ] , inner : Span ) -> hir:: Mod < ' hir > {
14790 hir:: Mod {
14891 inner : self . lower_span ( inner) ,
@@ -248,7 +191,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
248191 AnonymousLifetimeMode :: PassThrough ,
249192 |this, idty| {
250193 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)
252195 } ,
253196 ) ;
254197 let sig = hir:: FnSig {
@@ -358,12 +301,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
358301 } ,
359302 ) ;
360303
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) ) ) ;
367307
368308 // `defaultness.has_value()` is never called for an `impl`, always `true` in order
369309 // to not cause an assertion failure inside the `lower_defaultness` function.
@@ -775,21 +715,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
775715 }
776716 AssocItemKind :: Fn ( box Fn { ref sig, ref generics, body : None , .. } ) => {
777717 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 ) ;
780719 ( generics, hir:: TraitItemKind :: Fn ( sig, hir:: TraitFn :: Required ( names) ) )
781720 }
782721 AssocItemKind :: Fn ( box Fn { ref sig, ref generics, body : Some ( ref body) , .. } ) => {
783722 let asyncness = sig. header . asyncness ;
784723 let body_id =
785724 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 ( ) ) ;
793727 ( generics, hir:: TraitItemKind :: Fn ( sig, hir:: TraitFn :: Provided ( body_id) ) )
794728 }
795729 AssocItemKind :: TyAlias ( box TyAlias { ref generics, ref bounds, ref ty, .. } ) => {
@@ -844,8 +778,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
844778 }
845779
846780 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-
849781 let ( generics, kind) = match & i. kind {
850782 AssocItemKind :: Const ( _, ty, expr) => {
851783 let ty = self . lower_ty ( ty, ImplTraitContext :: disallowed ( ) ) ;
@@ -863,7 +795,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
863795 let ( generics, sig) = self . lower_method_sig (
864796 generics,
865797 sig,
866- impl_item_def_id ,
798+ i . id ,
867799 impl_trait_return_allow,
868800 asyncness. opt_return_id ( ) ,
869801 ) ;
@@ -1248,22 +1180,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
12481180 & mut self ,
12491181 generics : & Generics ,
12501182 sig : & FnSig ,
1251- fn_def_id : LocalDefId ,
1183+ id : NodeId ,
12521184 impl_trait_return_allow : bool ,
12531185 is_async : Option < NodeId > ,
12541186 ) -> ( hir:: Generics < ' hir > , hir:: FnSig < ' hir > ) {
1187+ let fn_def_id = self . resolver . local_def_id ( id) ;
12551188 let header = self . lower_fn_header ( sig. header ) ;
12561189 let ( generics, decl) = self . add_in_band_defs (
12571190 generics,
12581191 fn_def_id,
12591192 AnonymousLifetimeMode :: PassThrough ,
12601193 |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)
12671195 } ,
12681196 ) ;
12691197 ( generics, hir:: FnSig { header, decl, span : self . lower_span ( sig. span ) } )
@@ -1408,17 +1336,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
14081336 ref bounded_ty,
14091337 ref bounds,
14101338 span,
1411- } ) => self . with_in_scope_lifetime_defs ( & bound_generic_params , |this| {
1339+ } ) => {
14121340 hir:: WherePredicate :: BoundPredicate ( hir:: WhereBoundPredicate {
1413- bound_generic_params : this
1341+ bound_generic_params : self
14141342 . 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 ( ) )
14181346 } ) ) ,
1419- span : this . lower_span ( span) ,
1347+ span : self . lower_span ( span) ,
14201348 } )
1421- } ) ,
1349+ }
14221350 WherePredicate :: RegionPredicate ( WhereRegionPredicate {
14231351 ref lifetime,
14241352 ref bounds,
0 commit comments