Open samsartor opened 4 years ago
cc @nikomatsakis @matthewjasper @lqd
Seeing as it's been a while since the last activity on this and I just hit it, I'm just allowing myself to say this is still an issue :)
Here is a playground link if it can help reproducing with the latest nightly for future people who might come in here without having hit the issue themselves.
Current error:
error: lifetime may not live long enough
--> src/lib.rs:8:23
|
8 | Wrapper(|x: &u32| x)
| - - ^ returning this value requires that `'1` must outlive `'2`
| | |
| | return type of closure is &'2 u32
| let's call the lifetime of this reference `'1`
error: higher-ranked lifetime error
--> src/lib.rs:8:5
|
8 | Wrapper(|x: &u32| x)
| ^^^^^^^^^^^^^^^^^^^^
"Fixed"[^1] by feature https://github.com/rust-lang/rust/labels/F-closure_lifetime_binder:
#![feature(closure_lifetime_binder)]
struct Wrapper<T>(T);
fn allowed() -> impl for<'a> Fn(&'a u32) -> &'a u32 {
|x: &u32| x
}
fn not_allowed() -> Wrapper<impl for<'a> Fn(&'a u32) -> &'a u32> {
Wrapper(for<'a> |x: &'a u32| -> &'a u32 { x })
}
[^1]: Or rather, "workaround". Though we will likely never infer a higher-ranked lifetime for the closure in this case (see closure_lifetime_binder
's RFC / tracking issue).
This code fails to compile:
The message is:
I think this may be related to #54729 but it isn't quite clear. Certainly the workaround mentioned there does not work in this case.