You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fnmain(){fnid_type<T:Fn(&i32) -> &i32>(t:T) -> T{ t }let id = id_type(|x:&i32| x);{let a:Box<i32> = Box::new(42);id(&a);}{let b:Box<i32> = Box::new(43);id(&b);}}
I see two issues: one, rustc is terrible at inferring lifetimes for closures (rust-lang/rust#28092rust-lang/rust#26937 etc.). Two, it would be nice to have more direct syntax for explicitly specifying the lifetimes you want.
nrc
added
the
T-lang
Relevant to the language team, which will review and decide on the RFC.
label
Aug 19, 2016
The following example doesn't compile in current Rust:
This is because
a
andb
have non-overlapping lifetimes, soid
cannot be fixed to either of them.The typical solution is to lift
id
into afn
, making the lifetime parameter polymorphic:But then we lose the ability to close over the environment.
Ideally, I'd like the compiler to accept something like this:
that is, a closure which is polymorphic over the lifetime rather than fixed to a particular one.
The text was updated successfully, but these errors were encountered: