3737//! also be emitted during HIR ty lowering.
3838
3939use std:: iter;
40- use std:: marker:: PhantomData ;
4140
4241use ast:: visit:: Visitor ;
4342use hir:: def:: { DefKind , PartialRes , Res } ;
@@ -128,14 +127,12 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
128127 {
129128 self . get_sig_id ( delegation_info. resolution_node , span)
130129 } else {
131- return self . generate_delegation_error (
132- self . dcx ( ) . span_delayed_bug (
133- span,
134- format ! ( "LoweringContext: the delegation {:?} is unresolved" , item_id) ,
135- ) ,
130+ self . dcx ( ) . span_delayed_bug (
136131 span,
137- delegation,
132+ format ! ( "LoweringContext: the delegation {:?} is unresolved" , item_id ) ,
138133 ) ;
134+
135+ return self . generate_delegation_error ( span, delegation) ;
139136 } ;
140137
141138 match sig_id {
@@ -172,7 +169,7 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
172169
173170 DelegationResults { body_id, sig, ident, generics }
174171 }
175- Err ( err ) => self . generate_delegation_error ( err , span, delegation) ,
172+ Err ( _ ) => self . generate_delegation_error ( span, delegation) ,
176173 }
177174 }
178175
@@ -420,7 +417,6 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
420417 resolver : this. resolver ,
421418 path_id : delegation. id ,
422419 self_param_id : pat_node_id,
423- phantom : PhantomData ,
424420 } ;
425421 self_resolver. visit_block ( block) ;
426422 // Target expr needs to lower `self` path.
@@ -604,7 +600,6 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
604600
605601 fn generate_delegation_error (
606602 & mut self ,
607- err : ErrorGuaranteed ,
608603 span : Span ,
609604 delegation : & Delegation ,
610605 ) -> DelegationResults < ' hir > {
@@ -622,36 +617,35 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
622617 let ident = self . lower_ident ( delegation. ident ) ;
623618
624619 let body_id = self . lower_body ( |this| {
625- let body_expr = match delegation. body . as_ref ( ) {
626- Some ( box block) => {
627- // Generates a block when we failed to resolve delegation, where a target expression is its only statement,
628- // thus there will be no ICEs on further stages of analysis (see #144594)
629-
630- // As we generate a void function we want to convert target expression to statement to avoid additional
631- // errors, such as mismatched return type
632- let stmts = this. arena . alloc_from_iter ( [ hir:: Stmt {
633- hir_id : this. next_id ( ) ,
634- kind : rustc_hir:: StmtKind :: Semi (
635- this. arena . alloc ( this. lower_target_expr ( block) ) ,
636- ) ,
637- span,
638- } ] ) ;
639-
640- let block = this. arena . alloc ( hir:: Block {
641- stmts,
642- expr : None ,
643- hir_id : this. next_id ( ) ,
644- rules : hir:: BlockCheckMode :: DefaultBlock ,
645- span,
646- targeted_by_break : false ,
647- } ) ;
620+ let path = this. lower_qpath (
621+ delegation. id ,
622+ & delegation. qself ,
623+ & delegation. path ,
624+ ParamMode :: Optional ,
625+ AllowReturnTypeNotation :: No ,
626+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Path ) ,
627+ None ,
628+ ) ;
648629
649- hir:: ExprKind :: Block ( block, None )
650- }
651- None => hir:: ExprKind :: Err ( err) ,
630+ let callee_path = this. arena . alloc ( this. mk_expr ( hir:: ExprKind :: Path ( path) , span) ) ;
631+ let args = if let Some ( box block) = delegation. body . as_ref ( ) {
632+ this. arena . alloc_slice ( & [ this. lower_target_expr ( block) ] )
633+ } else {
634+ & mut [ ]
652635 } ;
653636
654- ( & [ ] , this. mk_expr ( body_expr, span) )
637+ let call = this. arena . alloc ( this. mk_expr ( hir:: ExprKind :: Call ( callee_path, args) , span) ) ;
638+
639+ let block = this. arena . alloc ( hir:: Block {
640+ stmts : & [ ] ,
641+ expr : Some ( call) ,
642+ hir_id : this. next_id ( ) ,
643+ rules : hir:: BlockCheckMode :: DefaultBlock ,
644+ span,
645+ targeted_by_break : false ,
646+ } ) ;
647+
648+ ( & [ ] , this. mk_expr ( hir:: ExprKind :: Block ( block, None ) , span) )
655649 } ) ;
656650
657651 let generics = hir:: Generics :: empty ( ) ;
@@ -673,14 +667,13 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
673667 }
674668}
675669
676- struct SelfResolver < ' a , ' tcx , R > {
670+ struct SelfResolver < ' a , R > {
677671 resolver : & ' a mut R ,
678672 path_id : NodeId ,
679673 self_param_id : NodeId ,
680- phantom : PhantomData < & ' tcx ( ) > ,
681674}
682675
683- impl < ' tcx , R : ResolverAstLoweringExt < ' tcx > > SelfResolver < ' _ , ' tcx , R > {
676+ impl < ' tcx , R : ResolverAstLoweringExt < ' tcx > > SelfResolver < ' _ , R > {
684677 fn try_replace_id ( & mut self , id : NodeId ) {
685678 if let Some ( res) = self . resolver . get_partial_res ( id)
686679 && let Some ( Res :: Local ( sig_id) ) = res. full_res ( )
@@ -692,7 +685,7 @@ impl<'tcx, R: ResolverAstLoweringExt<'tcx>> SelfResolver<'_, 'tcx, R> {
692685 }
693686}
694687
695- impl < ' ast , ' a , ' tcx , R : ResolverAstLoweringExt < ' tcx > > Visitor < ' ast > for SelfResolver < ' a , ' tcx , R > {
688+ impl < ' ast , ' tcx , R : ResolverAstLoweringExt < ' tcx > > Visitor < ' ast > for SelfResolver < ' _ , R > {
696689 fn visit_id ( & mut self , id : NodeId ) {
697690 self . try_replace_id ( id) ;
698691 }
0 commit comments