From 9a1043eac7dbd7177ce032c0f777b5ee2f636621 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 6 Nov 2022 01:59:03 +0000 Subject: [PATCH] Normalize signature when deducing closure signature from supertraits --- compiler/rustc_hir_typeck/src/closure.rs | 10 +++++++--- .../supertrait-hint-references-assoc-ty.rs | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/closures/supertrait-hint-references-assoc-ty.rs diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index 09df50c76b738..3001e79947672 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -10,6 +10,7 @@ use rustc_hir_analysis::astconv::AstConv; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::LateBoundRegionConversionTime; use rustc_infer::infer::{InferOk, InferResult}; +use rustc_macros::{TypeFoldable, TypeVisitable}; use rustc_middle::ty::subst::InternalSubsts; use rustc_middle::ty::visit::TypeVisitable; use rustc_middle::ty::{self, Ty}; @@ -22,7 +23,7 @@ use std::cmp; use std::iter; /// What signature do we *expect* the closure to have from context? -#[derive(Debug)] +#[derive(Debug, Clone, TypeFoldable, TypeVisitable)] struct ExpectedSig<'tcx> { /// Span that gave us this expectation, if we know that. cause_span: Option, @@ -241,9 +242,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if expected_sig.is_none() && let ty::PredicateKind::Projection(proj_predicate) = bound_predicate.skip_binder() { - expected_sig = self.deduce_sig_from_projection( + expected_sig = self.normalize_associated_types_in( + obligation.cause.span, + self.deduce_sig_from_projection( Some(obligation.cause.span), - bound_predicate.rebind(proj_predicate), + bound_predicate.rebind(proj_predicate), + ), ); } diff --git a/src/test/ui/closures/supertrait-hint-references-assoc-ty.rs b/src/test/ui/closures/supertrait-hint-references-assoc-ty.rs new file mode 100644 index 0000000000000..270bf14c35eca --- /dev/null +++ b/src/test/ui/closures/supertrait-hint-references-assoc-ty.rs @@ -0,0 +1,17 @@ +// check-pass + +pub trait Fn0: Fn(i32) -> Self::Out { + type Out; +} + +impl ()> Fn0 for F { + type Out = (); +} + +pub fn closure_typer(_: impl Fn0) {} + +fn main() { + closure_typer(move |x| { + let _: i64 = x.into(); + }); +}