-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
ICE with core::iter::adapters::peekable
+ recursion + pattern matching on peek
#131342
Comments
@rustbot label T-compiler A-allocators A-traits |
core::iter::adapters::peekable
+ recursion + pattern matching on peek
causes compiler paniccore::iter::adapters::peekable
+ recursion + pattern matching on peek
fn main() {
let mut items = vec![1, 2, 3, 4, 5].into_iter();
problem_thingy(&mut items);
}
fn problem_thingy(items: &mut impl Iterator<Item = u8>) {
let mut peeker = items.peekable();
problem_thingy(&mut peeker);
} This correctly doesn't panic with error[E0275]: overflow evaluating the requirement `Peekable<&mut std::vec::IntoIter<u8>>: Iterator` Looks like that operation in the middle makes the compiler somehow not catch it. |
core::iter::adapters::peekable
+ recursion + pattern matching on peek
core::iter::adapters::peekable
+ recursion + pattern matching on peek
Reduced to not depend on fn main() {
problem_thingy(Once);
}
struct Once;
impl Iterator for Once {
type Item = ();
}
fn problem_thingy(items: impl Iterator) {
let peeker = items.peekable();
problem_thingy(&peeker);
}
trait Iterator {
type Item;
fn peekable(self) -> Peekable<Self>
where
Self: Sized,
{
loop {}
}
}
struct Peekable<I: Iterator> {
_peeked: I::Item,
}
impl<I: Iterator> Iterator for Peekable<I> {
type Item = I::Item;
}
impl<I: Iterator + ?Sized> Iterator for &I {
type Item = I::Item;
} This also ICEs with just It's possible to construct some other horrible error messages from this too, such as by replacing the last impl<I: Iterator> Iterator for &I {
type Item = ();
} |
FWIW #127731 makes the reduced example above not crash any more, for unknown reasons. The original example still crashes. |
I tried this code:
I expected to see this happen: either continuously have the first item be "peeked" at, or return
()
on the final iteration after exhausting other peeks.Instead, this happened: compiler panicked with an unbearably large error message. I believe this has to do with allocation and pointer safety with
Peekable
, but I could be way off.Meta
rustc --version --verbose
:Backtrace and compiler output are unbearably large for this issue, so I've attached them below.
bare_build.txt
backtrace_build.txt
The text was updated successfully, but these errors were encountered: