2626//!
2727//! Where `callee_path` is a path in delegation item e.g. `<Type as Trait>::name`.
2828//! `sig_id` is a id of item from which the signature is inherited. It may be a delegation
29- //! item id (`item_id`) in case of impl trait or path resolution id (`path_id`) otherwise.
29+ //! item id (`item_id`) in case of impl trait or path res id (`path_id`) otherwise.
3030//!
31- //! Since we do not have a proper way to obtain function type information by path resolution
31+ //! Since we do not have a proper way to obtain function type information by path res
3232//! in AST, we mark each function parameter type as `InferDelegation` and inherit it during
3333//! HIR ty lowering.
3434//!
@@ -80,25 +80,26 @@ impl<'hir> LoweringContext<'_, 'hir> {
8080 let span = self . lower_span ( delegation. last_segment_span ( ) ) ;
8181
8282 let resolver = DelegationResolverForLowering ( self ) ;
83- let Ok ( ( res , mut generics ) ) = resolver. resolve_delegation ( delegation, span) else {
83+ let Ok ( mut res ) = resolver. resolve_delegation ( delegation, span) else {
8484 return self . generate_delegation_error ( span, delegation) ;
8585 } ;
8686
8787 self . add_attributes_if_needed ( & res) ;
8888
8989 let ( body_id, call_expr_id, unused_target_expr) =
90- self . lower_delegation_body ( delegation, & res , & mut generics ) ;
90+ self . lower_delegation_body ( delegation, & mut res ) ;
9191
92- let decl = self . lower_delegation_decl ( & res, & generics, call_expr_id, unused_target_expr) ;
92+ let decl =
93+ self . lower_delegation_decl ( & res, & res. generics , call_expr_id, unused_target_expr) ;
9394
9495 let sig = self . lower_delegation_sig ( res. sig_id , decl, span) ;
9596
9697 let ident = self . lower_ident ( delegation. ident ) ;
9798
9899 let generics = self . arena . alloc ( hir:: Generics {
99100 has_where_clause_predicates : false ,
100- params : self . arena . alloc_from_iter ( generics. all_params ( ) ) ,
101- predicates : self . arena . alloc_from_iter ( generics. all_predicates ( ) ) ,
101+ params : self . arena . alloc_from_iter ( res . generics . all_params ( ) ) ,
102+ predicates : self . arena . alloc_from_iter ( res . generics . all_predicates ( ) ) ,
102103 span,
103104 where_clause_span : span,
104105 } ) ;
@@ -112,21 +113,21 @@ impl<'hir> LoweringContext<'_, 'hir> {
112113
113114 fn lower_delegation_decl (
114115 & mut self ,
115- resolution : & DelegationResolution < ' hir > ,
116+ res : & DelegationResolution < ' hir > ,
116117 generics : & GenericsGenerationResults < ' hir > ,
117118 call_expr_id : HirId ,
118119 unused_target_expr : bool ,
119120 ) -> & ' hir hir:: FnDecl < ' hir > {
120- let & DelegationResolution { source, call_path_node_id, span, .. } = resolution ;
121- let ParamInfo { param_count, c_variadic, splatted } = resolution . param_info ;
121+ let & DelegationResolution { source, call_path_node_id, span, .. } = res ;
122+ let ParamInfo { param_count, c_variadic, splatted } = res . param_info ;
122123
123124 // The last parameter in C variadic functions is skipped in the signature,
124125 // like during regular lowering.
125126 let decl_param_count = param_count - c_variadic as usize ;
126127 let inputs = self . arena . alloc_from_iter ( ( 0 ..decl_param_count) . map ( |arg| hir:: Ty {
127128 hir_id : self . next_id ( ) ,
128129 kind : hir:: TyKind :: InferDelegation ( hir:: InferDelegation :: Sig (
129- resolution . sig_id ,
130+ res . sig_id ,
130131 hir:: InferDelegationSig :: Input ( arg) ,
131132 ) ) ,
132133 span,
@@ -135,7 +136,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
135136 let output = self . arena . alloc ( hir:: Ty {
136137 hir_id : self . next_id ( ) ,
137138 kind : hir:: TyKind :: InferDelegation ( hir:: InferDelegation :: Sig (
138- resolution . sig_id ,
139+ res . sig_id ,
139140 hir:: InferDelegationSig :: Output ( self . arena . alloc ( hir:: DelegationInfo {
140141 call_expr_id,
141142 call_path_res : self . get_resolution_id ( call_path_node_id) ,
@@ -250,17 +251,20 @@ impl<'hir> LoweringContext<'_, 'hir> {
250251 fn lower_delegation_body (
251252 & mut self ,
252253 delegation : & Delegation ,
253- resolution : & DelegationResolution < ' hir > ,
254- generics : & mut GenericsGenerationResults < ' hir > ,
254+ res : & mut DelegationResolution < ' hir > ,
255255 ) -> ( BodyId , HirId , bool ) {
256256 let block = delegation. body . as_deref ( ) ;
257257 let mut call_expr_id = HirId :: INVALID ;
258258 let mut unused_target_expr = false ;
259259
260260 let block_id = self . lower_body ( |this| {
261- let & DelegationResolution {
262- param_info, span, should_generate_block, is_method, ..
263- } = resolution;
261+ let & mut DelegationResolution {
262+ param_info,
263+ span,
264+ should_generate_block,
265+ is_method,
266+ ..
267+ } = res;
264268
265269 let ParamInfo { param_count, .. } = param_info;
266270
@@ -314,7 +318,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
314318 }
315319
316320 let ( final_expr, hir_id) =
317- this. finalize_body_lowering ( delegation, stmts, args, generics , resolution , span) ;
321+ this. finalize_body_lowering ( delegation, stmts, args, res , span) ;
318322
319323 call_expr_id = hir_id;
320324
@@ -331,8 +335,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
331335 delegation : & Delegation ,
332336 stmts : & ' hir [ hir:: Stmt < ' hir > ] ,
333337 args : Vec < hir:: Expr < ' hir > > ,
334- generics : & mut GenericsGenerationResults < ' hir > ,
335- resolution : & DelegationResolution < ' hir > ,
338+ res : & mut DelegationResolution < ' hir > ,
336339 span : Span ,
337340 ) -> ( hir:: Expr < ' hir > , HirId ) {
338341 let path = self . lower_qpath (
@@ -353,9 +356,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
353356 new_path. segments = self . arena . alloc_from_iter (
354357 new_path. segments . iter ( ) . enumerate ( ) . map ( |( idx, segment) | {
355358 if idx + 2 == len {
356- self . process_segment ( span, segment, & mut generics. parent )
359+ self . process_segment ( span, segment, & mut res . generics . parent )
357360 } else if idx + 1 == len {
358- self . process_segment ( span, segment, & mut generics. child )
361+ self . process_segment ( span, segment, & mut res . generics . child )
359362 } else {
360363 segment. clone ( )
361364 }
@@ -364,9 +367,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
364367
365368 // Explicitly create `Self` self-type in case of infers or static
366369 // free-to-trait reuses.
367- let ty = match generics. self_ty_propagation_kind {
370+ let ty = match res . generics . self_ty_propagation_kind {
368371 Some ( hir:: DelegationSelfTyPropagationKind :: SelfParam ) => {
369- let self_param = generics. parent . generics . find_self_param ( ) ;
372+ let self_param = res . generics . parent . generics . find_self_param ( ) ;
370373 let path = self . create_generic_arg_path ( self_param) ;
371374 let kind = hir:: TyKind :: Path ( path) ;
372375
@@ -386,7 +389,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
386389 } ;
387390
388391 if let Some ( hir:: DelegationSelfTyPropagationKind :: SelfTy ( id) ) =
389- generics. self_ty_propagation_kind . as_mut ( )
392+ res . generics . self_ty_propagation_kind . as_mut ( )
390393 {
391394 * id = match new_path {
392395 hir:: QPath :: Resolved ( ty, _) => {
@@ -401,7 +404,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
401404 let args = self . arena . alloc_from_iter ( args) ;
402405 let call = self . mk_expr ( hir:: ExprKind :: Call ( callee_path, args) , span) ;
403406
404- let expr = if let Some ( new_type) = resolution . parent_newtype {
407+ let expr = if let Some ( new_type) = res . parent_newtype {
405408 let variant = new_type. variant ( VariantIdx :: ZERO ) ;
406409 let res = Res :: Def ( DefKind :: Fn , variant. ctor . expect ( "must have constructor" ) . 1 ) ;
407410
0 commit comments