Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions tests/ui/higher-ranked/hrtb-projection-closure-return-34430.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//! Regression test for <https://github.com/rust-lang/rust/issues/34430>.
//!
//! An associated-type projection under a higher-ranked binder
//! (`for<'a> FnOnce(&'a Foo) -> <T as WithLifetime<'a>>::Type`) failed to normalize,
//! so returning `&'a Foo` from the closure was rejected even though
//! `<FooRef as WithLifetime<'a>>::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<T, F>(f: F)
where
T: for<'a> WithLifetime<'a>,
F: for<'a> FnOnce(&'a Foo) -> <T as WithLifetime<'a>>::Type,
{
}

fn main() {
wub::<FooRef, _>(|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::<FooRef, _>(|foo| -> &Foo { foo });
wub::<FooRef, _>(|foo| -> <FooRef as WithLifetime>::Type { foo });
}
Loading