@@ -10,7 +10,7 @@ use rustc_span::symbol::kw;
1010use rustc_span:: { DUMMY_SP , Ident , Span } ;
1111use thin_vec:: { ThinVec , thin_vec} ;
1212
13- use crate :: { AstOwner , LoweringContext } ;
13+ use crate :: { LoweringContext , ResolverAstLoweringExt } ;
1414
1515pub ( super ) enum DelegationGenerics < T > {
1616 /// User-specified args are present: `reuse foo::<String>;`.
@@ -60,7 +60,7 @@ impl<T> DelegationGenerics<T> {
6060impl < ' hir > HirOrAstGenerics < ' hir > {
6161 pub ( super ) fn into_hir_generics (
6262 & mut self ,
63- ctx : & mut LoweringContext < ' _ , ' hir > ,
63+ ctx : & mut LoweringContext < ' _ , ' _ , ' hir > ,
6464 item_id : NodeId ,
6565 span : Span ,
6666 ) -> & mut HirOrAstGenerics < ' hir > {
@@ -100,7 +100,7 @@ impl<'hir> HirOrAstGenerics<'hir> {
100100
101101 pub ( super ) fn into_generic_args (
102102 & self ,
103- ctx : & mut LoweringContext < ' _ , ' hir > ,
103+ ctx : & mut LoweringContext < ' _ , ' _ , ' hir > ,
104104 add_lifetimes : bool ,
105105 span : Span ,
106106 ) -> Option < & ' hir hir:: GenericArgs < ' hir > > {
@@ -140,7 +140,7 @@ impl<'hir> GenericsGenerationResults<'hir> {
140140 & mut self ,
141141 item_id : NodeId ,
142142 span : Span ,
143- ctx : & mut LoweringContext < ' _ , ' hir > ,
143+ ctx : & mut LoweringContext < ' _ , ' _ , ' hir > ,
144144 ) -> impl Iterator < Item = hir:: GenericParam < ' hir > > {
145145 // Now we always call `into_hir_generics` both on child and parent,
146146 // however in future we would not do that, when scenarios like
@@ -182,7 +182,7 @@ impl<'hir> GenericsGenerationResults<'hir> {
182182 & mut self ,
183183 item_id : NodeId ,
184184 span : Span ,
185- ctx : & mut LoweringContext < ' _ , ' hir > ,
185+ ctx : & mut LoweringContext < ' _ , ' _ , ' hir > ,
186186 ) -> impl Iterator < Item = hir:: WherePredicate < ' hir > > {
187187 // Now we always call `into_hir_generics` both on child and parent,
188188 // however in future we would not do that, when scenarios like
@@ -207,11 +207,11 @@ impl<'hir> GenericsGenerationResults<'hir> {
207207 }
208208}
209209
210- impl < ' hir > LoweringContext < ' _ , ' hir > {
210+ impl < ' hir > LoweringContext < ' _ , ' _ , ' hir > {
211211 pub ( super ) fn lower_delegation_generics (
212212 & mut self ,
213213 delegation : & Delegation ,
214- root_fn_id : DefId ,
214+ delegee_id : DefId ,
215215 item_id : NodeId ,
216216 span : Span ,
217217 ) -> GenericsGenerationResults < ' hir > {
@@ -221,13 +221,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
221221 ) ;
222222
223223 let root_function_in_trait =
224- matches ! ( self . tcx. def_kind( self . tcx. parent( root_fn_id ) ) , DefKind :: Trait ) ;
224+ matches ! ( self . tcx. def_kind( self . tcx. parent( delegee_id ) ) , DefKind :: Trait ) ;
225225
226226 let generate_self = delegation_in_free_ctx && root_function_in_trait;
227227
228228 let parent_generics_factory = |this : & mut Self , user_specified : bool | {
229229 this. get_parent_generics (
230- this. tcx . parent ( root_fn_id ) ,
230+ this. tcx . parent ( delegee_id ) ,
231231 generate_self,
232232 user_specified,
233233 span,
@@ -259,7 +259,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
259259 let child_generics = if segments[ len - 1 ] . args . is_some ( ) {
260260 DelegationGenerics :: UserSpecified
261261 } else {
262- DelegationGenerics :: Default ( self . get_fn_like_generics ( root_fn_id , span) )
262+ DelegationGenerics :: Default ( self . get_fn_like_generics ( delegee_id , span) )
263263 } ;
264264
265265 GenericsGenerationResults {
@@ -289,11 +289,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
289289
290290 // Note that we use self.disambiguator here, if we will create new every time
291291 // we will get ICE if params have the same name.
292- self . resolver . node_id_to_def_id . insert (
292+ self . resolver . mut_part . node_id_to_def_id . insert (
293293 p. id ,
294294 self . tcx
295295 . create_def (
296- self . resolver . node_id_to_def_id [ & item_id] ,
296+ self . resolver . def_id ( item_id) . unwrap ( ) ,
297297 Some ( p. ident . name ) ,
298298 match p. kind {
299299 GenericParamKind :: Lifetime => DefKind :: LifetimeParam ,
@@ -394,7 +394,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
394394 res,
395395 } ] ) ,
396396 res,
397- span : p . span ,
397+ span,
398398 } ) ,
399399 )
400400 } ;
@@ -415,15 +415,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
415415 hir:: GenericParamKind :: Type { .. } => {
416416 Some ( hir:: GenericArg :: Type ( self . arena . alloc ( hir:: Ty {
417417 hir_id : self . next_id ( ) ,
418- span : p . span ,
418+ span,
419419 kind : hir:: TyKind :: Path ( create_path ( self ) ) ,
420420 } ) ) )
421421 }
422422 hir:: GenericParamKind :: Const { .. } => {
423423 Some ( hir:: GenericArg :: Const ( self . arena . alloc ( hir:: ConstArg {
424424 hir_id : self . next_id ( ) ,
425425 kind : hir:: ConstArgKind :: Path ( create_path ( self ) ) ,
426- span : p . span ,
426+ span,
427427 } ) ) )
428428 }
429429 }
@@ -435,19 +435,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
435435 }
436436
437437 fn get_fn_like_generics ( & mut self , id : DefId , span : Span ) -> Option < Generics > {
438- if let Some ( local_id) = id. as_local ( ) {
439- match self . ast_index . get ( local_id) {
440- Some ( AstOwner :: Item ( item) ) if let ItemKind :: Fn ( f) = & item. kind => {
441- Some ( f. generics . clone ( ) )
442- }
443- Some ( AstOwner :: AssocItem ( item, _) ) if let AssocItemKind :: Fn ( f) = & item. kind => {
444- Some ( f. generics . clone ( ) )
445- }
446- _ => None ,
447- }
448- } else {
449- self . get_external_generics ( id, false , span)
450- }
438+ self . get_external_generics ( id, false , span)
451439 }
452440
453441 fn get_external_generics (
@@ -509,7 +497,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
509497
510498 let node_id = self . next_node_id ( ) ;
511499
512- self . resolver . partial_res_map . insert ( node_id, hir:: def:: PartialRes :: new ( res) ) ;
500+ self . resolver . mut_part . partial_res_map . insert ( node_id, hir:: def:: PartialRes :: new ( res) ) ;
513501
514502 GenericParamKind :: Const {
515503 ty : Box :: new ( Ty {
@@ -542,21 +530,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
542530 span : Span ,
543531 ) -> Option < Generics > {
544532 // If args are user-specified we still maybe need to add self.
545- let mut generics = if user_specified {
546- None
547- } else {
548- if let Some ( local_id) = id. as_local ( ) {
549- if let Some ( AstOwner :: Item ( item) ) = self . ast_index . get ( local_id)
550- && matches ! ( item. kind, ItemKind :: Trait ( ..) )
551- {
552- item. opt_generics ( ) . cloned ( )
553- } else {
554- None
555- }
556- } else {
557- self . get_external_generics ( id, true , span)
558- }
559- } ;
533+ let mut generics =
534+ if user_specified { None } else { self . get_external_generics ( id, true , span) } ;
560535
561536 if add_self {
562537 generics. get_or_insert_default ( ) . params . insert (
0 commit comments