Skip to content

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ pub trait Iterator {
fn peekable(self) -> Peekable<Self>
where
Self: Sized,
Self::Item: Sized,
{
Peekable::new(self)
}
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/iterators/unsized-peekable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@ compile-flags: -Zmir-enable-passes=+Inline -Zmir-enable-passes=+JumpThreading --crate-type=lib

pub fn problem_thingy(items: &mut impl Iterator<Item = str>) {
let mut peeker = items.peekable();
//~^ ERROR: the size for values of type `str` cannot be known at compilation time [E0277]
// ^^^ doesn't have a size known at compile-time
match peeker.peek() {
Some(_) => (),
None => return (),
}
}
13 changes: 13 additions & 0 deletions tests/ui/iterators/unsized-peekable.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/unsized-peekable.rs:4:28
|
LL | let mut peeker = items.peekable();
| ^^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait `Sized` is not implemented for `str`
note: required by a bound in `peekable`
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
Loading