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 }); +}