@@ -62,7 +62,7 @@ use crate::diagnostics::{
6262} ;
6363use crate :: {
6464 AllowReturnTypeNotation , ImplTraitContext , ImplTraitPosition , LoweringContext , ParamMode ,
65- ResolverAstLoweringExt , index_crate,
65+ index_crate,
6666} ;
6767
6868mod generics;
@@ -126,7 +126,7 @@ pub(crate) fn delegations_resolutions(
126126 let delegation = ast_index[ def_id] . delegation ( ) . expect ( "processing delegations" ) ;
127127 let span = delegation. last_segment_span ( ) ;
128128
129- if let Some ( info) = resolver . delegation_info ( def_id) {
129+ if let Some ( info) = tcx . resolutions ( ( ) ) . delegation_infos . get ( & def_id) {
130130 let res = info. resolution_id . map ( |id| check_for_cycles ( tcx, id, span) . map ( |_| id) ) ;
131131 result. insert ( def_id, res. flatten ( ) ) ;
132132 } else {
@@ -143,16 +143,14 @@ pub(crate) fn delegations_resolutions(
143143fn check_for_cycles ( tcx : TyCtxt < ' _ > , mut def_id : DefId , span : Span ) -> Result < ( ) , ErrorGuaranteed > {
144144 let mut visited: FxHashSet < DefId > = Default :: default ( ) ;
145145
146- let ( resolver, _) = & * tcx. hir_crate ( ( ) ) . delayed_resolver . borrow ( ) ;
147-
148146 loop {
149147 visited. insert ( def_id) ;
150148
151149 // If def_id is in local crate and it corresponds to another delegation
152150 // it means that we refer to another delegation as a callee, so in order to obtain
153151 // a signature DefId we obtain NodeId of the callee delegation and try to get signature from it.
154152 if let Some ( local_id) = def_id. as_local ( )
155- && let Some ( info) = resolver . delegation_info ( local_id)
153+ && let Some ( info) = tcx . resolutions ( ( ) ) . delegation_infos . get ( & local_id)
156154 && let Ok ( id) = info. resolution_id
157155 {
158156 def_id = id;
@@ -209,17 +207,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
209207
210208 let mut generics = self . uplift_delegation_generics ( delegation, sig_id, is_method) ;
211209
212- let ( body_id, call_expr_id) =
210+ let ( body_id, call_expr_id, unused_target_expr ) =
213211 self . lower_delegation_body ( delegation, sig_id, param_count, & mut generics, span) ;
214212
215213 let decl = self . lower_delegation_decl (
214+ delegation. source ,
216215 sig_id,
217216 param_count,
218217 c_variadic,
219218 span,
220219 & generics,
221220 delegation. id ,
222221 call_expr_id,
222+ unused_target_expr,
223223 ) ;
224224
225225 let sig = self . lower_delegation_sig ( sig_id, decl, span) ;
@@ -375,13 +375,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
375375
376376 fn lower_delegation_decl (
377377 & mut self ,
378+ source : DelegationSource ,
378379 sig_id : DefId ,
379380 param_count : usize ,
380381 c_variadic : bool ,
381382 span : Span ,
382383 generics : & GenericsGenerationResults < ' hir > ,
383384 call_path_node_id : NodeId ,
384385 call_expr_id : HirId ,
386+ unused_target_expr : bool ,
385387 ) -> & ' hir hir:: FnDecl < ' hir > {
386388 // The last parameter in C variadic functions is skipped in the signature,
387389 // like during regular lowering.
@@ -406,6 +408,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
406408 parent_args_segment_id : generics. parent . args_segment_id ,
407409 self_ty_id : generics. self_ty_id ,
408410 propagate_self_ty : generics. propagate_self_ty ,
411+ group_id : {
412+ let id = match source {
413+ DelegationSource :: Single => None ,
414+ DelegationSource :: List ( expn_id) => Some ( expn_id) ,
415+ DelegationSource :: Glob => {
416+ Some ( self . tcx . expn_that_defined ( self . owner . def_id ) . expect_local ( ) )
417+ }
418+ } ;
419+
420+ id. map ( |id| ( id, unused_target_expr) )
421+ } ,
409422 } ) ) ,
410423 ) ) ,
411424 span,
@@ -504,16 +517,23 @@ impl<'hir> LoweringContext<'_, 'hir> {
504517 param_count : usize ,
505518 generics : & mut GenericsGenerationResults < ' hir > ,
506519 span : Span ,
507- ) -> ( BodyId , HirId ) {
520+ ) -> ( BodyId , HirId , bool ) {
508521 let block = delegation. body . as_deref ( ) ;
509522 let mut call_expr_id = HirId :: INVALID ;
523+ let mut unused_target_expr = false ;
510524
511525 let block_id = self . lower_body ( |this| {
512526 let mut parameters: Vec < hir:: Param < ' _ > > = Vec :: with_capacity ( param_count) ;
513527 let mut args: Vec < hir:: Expr < ' _ > > = Vec :: with_capacity ( param_count) ;
514528 let mut stmts: & [ hir:: Stmt < ' hir > ] = & [ ] ;
515529
516530 let is_method = this. is_method ( sig_id, span) ;
531+ let should_generate_block = this. should_generate_block ( delegation, sig_id, is_method) ;
532+
533+ // Consider non-specified target expression as generated,
534+ // as we do not want to emit error when target expression is
535+ // not specified.
536+ unused_target_expr = block. is_some ( ) && ( param_count == 0 || !should_generate_block) ;
517537
518538 for idx in 0 ..param_count {
519539 let ( param, pat_node_id) = this. generate_param ( is_method, idx, span) ;
@@ -524,7 +544,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
524544
525545 let arg = if let Some ( block) = block
526546 && idx == 0
527- && this . should_generate_block ( delegation , sig_id , is_method )
547+ && should_generate_block
528548 {
529549 let mut self_resolver = SelfResolver {
530550 ctxt : this,
@@ -565,7 +585,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
565585
566586 debug_assert_ne ! ( call_expr_id, HirId :: INVALID ) ;
567587
568- ( block_id, call_expr_id)
588+ ( block_id, call_expr_id, unused_target_expr )
569589 }
570590
571591 fn finalize_body_lowering (
0 commit comments