@@ -14,7 +14,7 @@ use rustc_middle::span_bug;
14
14
use rustc_middle:: ty:: visit:: { TypeVisitable , TypeVisitableExt } ;
15
15
use rustc_middle:: ty:: { self , GenericArgs , Ty , TyCtxt , TypeSuperVisitable , TypeVisitor } ;
16
16
use rustc_span:: def_id:: LocalDefId ;
17
- use rustc_span:: Span ;
17
+ use rustc_span:: { Span , DUMMY_SP } ;
18
18
use rustc_target:: spec:: abi:: Abi ;
19
19
use rustc_trait_selection:: error_reporting:: traits:: ArgKind ;
20
20
use rustc_trait_selection:: traits;
@@ -563,25 +563,35 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
563
563
return None ;
564
564
} ;
565
565
566
- // FIXME: We may want to elaborate here, though I assume this will be exceedingly rare.
566
+ let mut return_ty = None ;
567
567
for bound in self . obligations_for_self_ty ( return_vid) {
568
568
if let Some ( ret_projection) = bound. predicate . as_projection_clause ( )
569
569
&& let Some ( ret_projection) = ret_projection. no_bound_vars ( )
570
570
&& self . tcx . is_lang_item ( ret_projection. def_id ( ) , LangItem :: FutureOutput )
571
571
{
572
- let sig = projection. rebind ( self . tcx . mk_fn_sig (
573
- input_tys,
574
- ret_projection. term . expect_type ( ) ,
575
- false ,
576
- hir:: Safety :: Safe ,
577
- Abi :: Rust ,
578
- ) ) ;
579
-
580
- return Some ( ExpectedSig { cause_span, sig } ) ;
572
+ return_ty = Some ( ret_projection. term . expect_type ( ) ) ;
581
573
}
582
574
}
583
575
584
- None
576
+ // SUBTLE: If we didn't find a `Future<Output = ...>` bound for the return
577
+ // vid, we still want to attempt to provide inference guidance for the async
578
+ // closure's arguments. Instantiate a new vid to plug into the output type.
579
+ //
580
+ // You may be wondering, what if it's higher-ranked? Well, given that we
581
+ // found a type variable for the `FnOnce::Output` projection above, we know
582
+ // that the output can't mention any of the vars.
583
+ let return_ty =
584
+ return_ty. unwrap_or_else ( || self . next_ty_var ( cause_span. unwrap_or ( DUMMY_SP ) ) ) ;
585
+
586
+ let sig = projection. rebind ( self . tcx . mk_fn_sig (
587
+ input_tys,
588
+ return_ty,
589
+ false ,
590
+ hir:: Safety :: Safe ,
591
+ Abi :: Rust ,
592
+ ) ) ;
593
+
594
+ return Some ( ExpectedSig { cause_span, sig } ) ;
585
595
}
586
596
587
597
fn sig_of_closure (
0 commit comments