-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support higher-rank lifetimes in traits (e.g. <'a>Trait<'a>) #15067
Comments
Why only traits? :) |
To elaborate on my drive-by comment: I'm not sufficiently familiar with the innards of the compiler to make a direct judgment, but in the abstract, I don't see why trait objects with higher-rank lifetimes should work any differently than the other candidates like |
(I'll be putting an addendum PR on the unboxed closures RFC as a follow-up for this. -- removing I-nominated tag.) |
Since procs do not have lifetime bounds, we must do this to maintain safety. This can break code that incorrectly captured references in procedure types. Change such code to not do this, perhaps with a trait object instead. A better solution would be to add higher-rank lifetime support to procs. However, this would be a lot of work for a feature we want to remove in favor of unboxed closures. The corresponding "real fix" is rust-lang#15067. Closes rust-lang#14036. [breaking-change]
(actually there was already a section in the unboxed closures RFC saying that we need a separate RFC to describe the need for trait references like |
With the new unboxed closure trait syntax ( |
I agree with @P1start that |
According to @huonw and @BurntSushi, higher-rank lifetimes may be the easiest way to write some sort of zero-allocation The basic goal is to take a trait similar to the standard library's pub trait Buffer: Reader {
fn fill_buf<'a>(&'a mut self) -> IoResult<&'a [u8]>;
// ...
} …but which returns a generic value: pub trait StreamingIterator<T<'*>> {
fn next<'a>(&'a mut self) -> Option<T<'a>>;
// Can we implement _any_ reasonable version of `fold` here?
fn fold<'a,S>(&'a mut self, init: B, f: |S, T<'a>| -> S) -> S { ... }
} This would be a really nice use-case for Rust: It would allow performing high-speed generic computations on streaming I/O. Right now, we can pick any two of "high-speed," "generic" and "streaming," as far as I can tell. After several days of picking people's brains, it feels like we can almost get all three, but it's just barely of reach. |
@emk Since |
(Whoops, got the terminology wrong, sorry.) |
Will higher-rank lifetimes be inferred where possible? For instance, if I understand correctly, this proposal allows for the following unboxed-closure type: <'a> Fn<&'a [int], uint> will the following be possible? Fn<&[int], uint> |
@danburkert Yes, I believe. |
Closing as a dupe of #17661, which is accepted for P-backcompat-lang |
internal: Add more context to overly long loop turn message
This will be needed as part of unboxed closures to complete the transition.
Nominating for P-backcompat-lang as a dependency of #14798.
The text was updated successfully, but these errors were encountered: