-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Lifetime inference failure #19875
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
Comments
You're going to have to write out the explicit lifetimes in this case. The 'inference' is just a set of simple rules: https://github.com/rust-lang/rfcs/blob/master/text/0141-lifetime-elision.md#the-rules The elisison assigns the same lifetime to the I'm not going to close this because I might be missing something, but that's what I see. |
@tomaka Your code is not safe, and that's why it doesn't compile. If you call // Calling `next` on an `Iterator` never freezes it, because of the signature of `next()`:
// `next(&mut self) -> T` // no lifetime "glue" between `self` and `T`
let head_mut: &mut T = iter.next();
let another_head_mut: &mut T = iter.next();
One possible (future) safe solution is HKT. The trait Iterator<T> {
// note: `T` is a "type constructor": lifetime -> concrete type
fn next<'a>(&'a mut self) -> T<'a>;
} With that definition and your implementation the iterator will "freeze" when let head_mut: &mut T = iter.next(); // `iter` gets frozen here
let another_head_mut: &mut T = iter.next(); //~ error: `iter` is already mutably borrowed See this blog post (warning: old syntax) for more details. |
Thanks |
fix: Skip pattern analysis on type mismatches
fix: Skip pattern analysis on type mismatches
This code: (http://is.gd/tif86V)
Produces this:
I don't think there is anything unsafe with what I want to do (it's the exact same signature as
MutItems
).This code does work but is incompatible with the
Iterator
trait definition: (http://is.gd/rMwbe6)Sorry if this is a duplicate.
The text was updated successfully, but these errors were encountered: