Skip to content

Commit 61e2719

Browse files
Infer args from for closure from Fn* bound even if it has no inferrable return
1 parent 20e9c9e commit 61e2719

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

Diff for: compiler/rustc_hir_typeck/src/closure.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_middle::span_bug;
1414
use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt};
1515
use rustc_middle::ty::{self, GenericArgs, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor};
1616
use rustc_span::def_id::LocalDefId;
17-
use rustc_span::Span;
17+
use rustc_span::{Span, DUMMY_SP};
1818
use rustc_target::spec::abi::Abi;
1919
use rustc_trait_selection::error_reporting::traits::ArgKind;
2020
use rustc_trait_selection::traits;
@@ -563,25 +563,27 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
563563
return None;
564564
};
565565

566+
let mut return_ty = None;
567+
566568
// FIXME: We may want to elaborate here, though I assume this will be exceedingly rare.
567569
for bound in self.obligations_for_self_ty(return_vid) {
568570
if let Some(ret_projection) = bound.predicate.as_projection_clause()
569571
&& let Some(ret_projection) = ret_projection.no_bound_vars()
570572
&& self.tcx.is_lang_item(ret_projection.def_id(), LangItem::FutureOutput)
571573
{
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 });
574+
return_ty = Some(ret_projection.term.expect_type());
581575
}
582576
}
583577

584-
None
578+
let sig = projection.rebind(self.tcx.mk_fn_sig(
579+
input_tys,
580+
return_ty.unwrap_or_else(|| self.next_ty_var(cause_span.unwrap_or(DUMMY_SP))),
581+
false,
582+
hir::Safety::Safe,
583+
Abi::Rust,
584+
));
585+
586+
return Some(ExpectedSig { cause_span, sig });
585587
}
586588

587589
fn sig_of_closure(

0 commit comments

Comments
 (0)