-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Fix ICE in peekable
with unsized types
#136451
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
Conversation
This commit resolves an Internal Compiler Error (ICE) caused by calling `peekable` on iterators with unsized item types. The issue arises due to MIR optimizations (`Inline` and `JumpThreading`) encountering invalid states when handling unsized types. Changes: - Added a `Self::Item: Sized` bound to the `peekable` method in `Iterator` trait to prevent usage with unsized types. - Introduced a new test case (`tests/ui/iterators/unsized-peekable.rs`) to verify that attempting to use `peekable` with unsized types results in a proper compile-time error instead of an ICE. This fix ensures that the compiler provides a clear and actionable error message (`E0277`) when `peekable` is used with unsized types, avoiding invalid intermediate representations during MIR optimization. Signed-off-by: Charalampos Mitrodimas <[email protected]>
r? @SparrowLii rustbot has assigned @SparrowLii. Use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the right fix for this issue: for one, it would break some existing uses of peekable
, and secondly, the error is not specific to Peekable
and could be caused with other types too.
The actual fix would need to update the jump threading or inlining optimization logic to prevent any such errors.
The job Click to see the possible cause of the failure (guessed by this bot)
|
This commit resolves an Internal Compiler Error (ICE) caused by calling
peekable
on iterators with unsized item types. The issue arises due to MIR optimizations (Inline
andJumpThreading
) encountering invalid states when handling unsized types.Changes:
Self::Item: Sized
bound to thepeekable
method inIterator
trait to prevent usage with unsized types.tests/ui/iterators/unsized-peekable.rs
) to verify that attempting to usepeekable
with unsized types results in a proper compile-time error instead of an ICE.This fix ensures that the compiler provides a clear and actionable error message (
E0277
) whenpeekable
is used with unsized types, avoiding invalid intermediate representations during MIR optimization.Closes #136442