-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when appliedgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Description
Summary
The suggested solution for while_let_on_iterator fails to compile when applied in a default trait implementation that doesn't have an explicit Sized bound.
Reproducer
I tried this code:
pub trait CertainTrait: Iterator<Item = Result<u8, ()>> {
fn parse(&mut self) {
let mut data = Vec::new();
while let Some(r) = self.next() {
match r {
Err(_) => {},
Ok(v) => data.push(v),
}
}
}
}I expected to see this happen:
The suggestion should have possibly used self.into_iter(), as that works without additional requirements; Or it simply shouldn't have been suggested.
Instead, this happened:
The suggestion (for r in self.by_ref()) didn't compile, and the compiler suggested to add where Self: Sized to the function definition, which works.
Version
https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=af6bab9b98cca79a75748f4f8963a7cb
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when appliedgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy