-
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
Passing a lifetime GAT to a closure can cause the compiler to run indefinitely #108826
Comments
It looks like it's not the reference part, I found a case that also causes it where the predicate doesn't take the value by reference, and another case where taking it by reference doesn't cause this behavior |
This comment was marked as resolved.
This comment was marked as resolved.
Backtrace
repeating stack is frame 62 to 85 + select() call @ 2543 |
Alright, I've investigated this a bit. This regressed in #81055 which set out to make some overflow errors recoverable (undoing parts of #80246). If I locally revert the change made in #81055, the modified compiler correctly bails out early and reports the following overflow error:
Issue #81091 seems very relevant here (if a PR implements the proposal in #81091, I assume this issue will be fixed by it, too). |
Further minimized: trait LendingIterator {
type Item<'a>
where
Self: 'a;
}
struct Filter<S, P>(S, P);
impl<S, P> LendingIterator for Filter<S, P>
where
S: LendingIterator,
P: FnMut(&Self::Item<'_>),
{
type Item<'a> = S::Item<'a> where S: 'a;
} |
Sorry if this is the wrong place to ask, but is there a way to accomplish a similar thing without running into the trait evaluation recursion? |
To make it compile, - fn next<'a>(&'a mut self) -> Self::Item<'a>
+ fn next<'a>(&'a mut self) -> Option<Self::Item<'a>> |
And to work around the borrow checker limitation mentioned on that playground, you may want to consider using polonius-the-crab. |
Awesome, thanks! |
Fixed by next solver (
@rustbot label fixed-by-next-solver |
Found a similar issue that doesn't use GATs directly, in case that's useful: pub trait LendingIteratorItem<'item> {
type Item;
}
impl<'item, F> LendingIteratorItem<'item> for (F,)
where
F: for<'a> FnMut(<Self as LendingIteratorItem<'a>>::Item),
{
type Item = ();
} |
Code
I tried to pair it down more, but so far this is the smallest version I could get to cause the issue:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=5042463788e49bf6964dfa80dcb5b9bb
Meta
rustc --version --verbose
:and
Error output
There isn't any error output, since the compiler runs indefinitely when encountering this issue.
The text was updated successfully, but these errors were encountered: