Skip to content

Commit 1b8ea65

Browse files
Infer args from for closure from Fn* bound even if it has no inferrable return
1 parent fc4da00 commit 1b8ea65

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

compiler/rustc_hir_typeck/src/closure.rs

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

567+
let mut return_ty = None;
568+
567569
// FIXME: We may want to elaborate here, though I assume this will be exceedingly rare.
568570
for bound in self.obligations_for_self_ty(return_vid) {
569571
if let Some(ret_projection) = bound.predicate.as_projection_clause()
570572
&& let Some(ret_projection) = ret_projection.no_bound_vars()
571573
&& self.tcx.is_lang_item(ret_projection.def_id(), LangItem::FutureOutput)
572574
{
573-
let sig = projection.rebind(self.tcx.mk_fn_sig(
574-
input_tys,
575-
ret_projection.term.expect_type(),
576-
false,
577-
hir::Safety::Safe,
578-
Abi::Rust,
579-
));
580-
581-
return Some(ExpectedSig { cause_span, sig });
575+
return_ty = Some(ret_projection.term.expect_type());
582576
}
583577
}
584578

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

588590
fn sig_of_closure(

0 commit comments

Comments
 (0)