Skip to content

Commit 9a1043e

Browse files
Normalize signature when deducing closure signature from supertraits
1 parent 1286ee2 commit 9a1043e

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

compiler/rustc_hir_typeck/src/closure.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_hir_analysis::astconv::AstConv;
1010
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
1111
use rustc_infer::infer::LateBoundRegionConversionTime;
1212
use rustc_infer::infer::{InferOk, InferResult};
13+
use rustc_macros::{TypeFoldable, TypeVisitable};
1314
use rustc_middle::ty::subst::InternalSubsts;
1415
use rustc_middle::ty::visit::TypeVisitable;
1516
use rustc_middle::ty::{self, Ty};
@@ -22,7 +23,7 @@ use std::cmp;
2223
use std::iter;
2324

2425
/// What signature do we *expect* the closure to have from context?
25-
#[derive(Debug)]
26+
#[derive(Debug, Clone, TypeFoldable, TypeVisitable)]
2627
struct ExpectedSig<'tcx> {
2728
/// Span that gave us this expectation, if we know that.
2829
cause_span: Option<Span>,
@@ -241,9 +242,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
241242
if expected_sig.is_none()
242243
&& let ty::PredicateKind::Projection(proj_predicate) = bound_predicate.skip_binder()
243244
{
244-
expected_sig = self.deduce_sig_from_projection(
245+
expected_sig = self.normalize_associated_types_in(
246+
obligation.cause.span,
247+
self.deduce_sig_from_projection(
245248
Some(obligation.cause.span),
246-
bound_predicate.rebind(proj_predicate),
249+
bound_predicate.rebind(proj_predicate),
250+
),
247251
);
248252
}
249253

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// check-pass
2+
3+
pub trait Fn0: Fn(i32) -> Self::Out {
4+
type Out;
5+
}
6+
7+
impl<F: Fn(i32) -> ()> Fn0 for F {
8+
type Out = ();
9+
}
10+
11+
pub fn closure_typer(_: impl Fn0) {}
12+
13+
fn main() {
14+
closure_typer(move |x| {
15+
let _: i64 = x.into();
16+
});
17+
}

0 commit comments

Comments
 (0)