-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Apparent infinite loop when passing infinitely recursive type using Iterator::filter #91498
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
|
I think I came across this problem too - Constructing an infinite type for a recursive iterator function doesn't ever finish or error out. My repro: https://github.com/tocklime/rustc_iterwrapper_hang/blob/main/src/main.rs |
Related issue: sometimes the instantiation does stop - by reaching a type that requires 128 steps to verify its bounds - and then blames the leaf node for it!
|
A slight variation on (probably) the same bug: fn foo(iter: &mut impl Iterator<Item = ()>) {
foo(&mut std::iter::once(()).chain(iter))
}
fn main() {
foo(&mut std::iter::repeat(()));
} Here, The (last) error is:
|
I ran into what I think is a similar problem, although in my case the hang happens even though the code doesn't call the iterator. Repro here: https://github.com/dceddia/rustc-iterator-hang/blob/main/src/main.rs It hangs on both This is my first foray into writing an iterator extension so I'm probably doing something terribly wrong, but still, I figure it's not supposed to hang forever 😅 edit - I found that the compile will finish normally (with errors, because my code is broken) if I comment out the code that implements the iterator (this section) edit 2 - I narrowed it down to this one difference in how I was specifying one of the trait bounds, using impl<T, Cond, F> Iterator for OnChange<T, Cond, F>
where
Cond: Fn(&Option<Self::Item>) -> bool, // (a) hangs the compiler
Cond: Fn(&Option<T>) -> bool, // (b) does not hang
F: Fn((Option<T>, Option<T>)) -> Option<T>,
{
type Item = T;
fn next(&mut self) -> Option<Self::Item> {
todo!()
}
} |
I tried this code:
I expected the compiler would provide an error message, akin to
reached the recursion limit while instantiating
.Instead, the compiler appears to hang indefinitely — I killed the process after a while.
Meta
The text was updated successfully, but these errors were encountered: