-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
A-documentationArea: Adding or improving documentationArea: Adding or improving documentationC-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
In the following example, it is not possible to fix the clippy lint, since the iter() trait is not implemented:
struct Test {
inner: Vec<usize>,
}
impl std::ops::Index<usize> for Test {
type Output = usize;
fn index(&self, index: usize) -> &Self::Output {
&self.inner[index]
}
}
fn main() {
let test = Test {
inner: vec![1, 2, 3, 4],
};
for i in 0..2 {
println!("{}", test[i]);
}
}It is likely not always possible to implement Iterator for a struct that implements Index, so there are some cases where it will be impossible to fix this lint.
I'd assume this is something that should either be fixed by checking if Iterator is implemented for usize, or it should be added to the Known Issues section.
This is likely a rare issue since usually both Index and Iterator are implemented, however I don't think the assumption can be made that this is always the case.
Metadata
Metadata
Assignees
Labels
A-documentationArea: Adding or improving documentationArea: Adding or improving documentationC-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