From dfbb1bfc892d442cd9456f52ebc99a95c7dfbdcd Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 5 Oct 2023 00:05:04 +0000 Subject: [PATCH] Also closures --- compiler/rustc_hir_typeck/src/closure.rs | 4 +++- .../deduce-closure-signature-after-normalization.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/ui/traits/new-solver/deduce-closure-signature-after-normalization.rs diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index d4d62a40328d..e506c150f7d3 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -56,7 +56,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // closure sooner rather than later, so first examine the expected // type, and see if can glean a closure kind from there. let (expected_sig, expected_kind) = match expected.to_option(self) { - Some(ty) => self.deduce_closure_signature(ty), + Some(ty) => { + self.deduce_closure_signature(self.try_structurally_resolve_type(expr_span, ty)) + } None => (None, None), }; let body = self.tcx.hir().body(closure.body); diff --git a/tests/ui/traits/new-solver/deduce-closure-signature-after-normalization.rs b/tests/ui/traits/new-solver/deduce-closure-signature-after-normalization.rs new file mode 100644 index 000000000000..d67fc65032ca --- /dev/null +++ b/tests/ui/traits/new-solver/deduce-closure-signature-after-normalization.rs @@ -0,0 +1,12 @@ +// compile-flags: -Ztrait-solver=next +// check-pass + +#![feature(return_position_impl_trait_in_trait)] + +trait Foo { + fn test() -> impl Fn(u32) -> u32 { + |x| x.count_ones() + } +} + +fn main() {}