-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Lending iterator through GAT / HRTB implies unexpected lifetime despite being 'static #96669
Comments
This is a slightly less contrived example, which is what motivated me to open this issue originally. Whatever constraint is being applied is projected across another trait as well: #![feature(generic_associated_types)]
trait Iterator {
type Item<'this>: Get
where
Self: 'this;
fn next(&mut self) -> Self::Item<'_>;
}
trait Get {
type Value: 'static;
fn get(self) -> Self::Value;
}
fn not_ok<T>(mut it: T)
where
T: Iterator,
{
let mut _out;
loop {
let item = it.next(); // `it` was mutably borrowed here in the previous iteration of the loop
_out = item.get();
}
} |
Repro without GATs: trait IteratorItem<'a> {
type Item: 'static;
}
trait Iterator: for<'a> IteratorItem<'a> {
fn next(&mut self) -> <Self as IteratorItem<'_>>::Item;
}
fn not_ok<T>(mut it: T) where T: Iterator {
let mut _a = it.next();
let mut _b = it.next();
} |
Any news on this? It makes lending iterators very difficult to use when loops are involved... |
We fixed this somewhere along the way. These all work fine now. Thanks to @udoprog for providing straightforward reproductions. |
Thanks for the follow up! |
I guess I'm not 100% sure this is the same error, but it seems to manifest in very similar ways. Is this related? |
@archshift Since you're dealing with non- |
Oh, did some more digging and it turns out #92985 is exactly my issue. |
I tried this code:
Since
next
returns an associated type with a'static
constraint, it seems like the associated type could be assumed to not have a lifetime associated with theIterator
that produces it and allow the program to compile.Instead some lifetime constraint I can't wrap my head around is present, resulting in the above error.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: