From 94df4bb7398b201d5151f6bd0a355e823e69f551 Mon Sep 17 00:00:00 2001 From: zakrad <49591476+zakrad@users.noreply.github.com> Date: Thu, 30 Jul 2026 14:08:31 +0330 Subject: [PATCH] Add regression test for HRTB projection in closure return position --- .../hrtb-projection-closure-return-34430.rs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/ui/higher-ranked/hrtb-projection-closure-return-34430.rs diff --git a/tests/ui/higher-ranked/hrtb-projection-closure-return-34430.rs b/tests/ui/higher-ranked/hrtb-projection-closure-return-34430.rs new file mode 100644 index 0000000000000..abdaed95007e2 --- /dev/null +++ b/tests/ui/higher-ranked/hrtb-projection-closure-return-34430.rs @@ -0,0 +1,41 @@ +//! Regression test for . +//! +//! An associated-type projection under a higher-ranked binder +//! (`for<'a> FnOnce(&'a Foo) -> >::Type`) failed to normalize, +//! so returning `&'a Foo` from the closure was rejected even though +//! `>::Type` *is* `&'a Foo`. + +//@ revisions: current next +//@ ignore-compare-mode-next-solver (explicit revisions) +//@[next] compile-flags: -Znext-solver +//@ check-pass + +#![allow(unused)] + +trait WithLifetime<'a> { + type Type; +} + +struct Foo; + +enum FooRef {} + +impl<'a> WithLifetime<'a> for FooRef { + type Type = &'a Foo; +} + +fn wub(f: F) +where + T: for<'a> WithLifetime<'a>, + F: for<'a> FnOnce(&'a Foo) -> >::Type, +{ +} + +fn main() { + wub::(|foo| foo); + + // Annotating the closure's return type used to ICE instead. Both the concrete + // and the projected spelling are checked, since either could regress alone. + wub::(|foo| -> &Foo { foo }); + wub::(|foo| -> ::Type { foo }); +}