Structs with non-matching Index and Iter impls cause bad suggestions #2847
Labels
C-bug
Category: Clippy is not doing the correct thing
I-suggestion-causes-error
Issue: The suggestions provided by this Lint cause an ICE/error when applied
L-suggestion
Lint: Improving, adding or fixing lint suggestions
I'm using the
llvm-alt
library, which exports aFunction
type representing a function embedded in an llvm module. Callingiter
on a function iterates through its basic blocks, but indexing into it accesses the function parameter values.Yes, this is a bizarre design decision, but it's a wart on an otherwise great library.
Under this setup I wrote the following code:
When I run clippy on my crate, I get the following diagnostic:
This warning and suggestion do not make sense, since the
iter
implementation would do something totally different. (Iterate through basic blocks.) Now I know this isn't a common case, or even a useful one. But it would be nice if Clippy didn't produce this spurious diagnostic. (This is bad library code, not badness in my code.)I think this could probably be avoided if Clippy just compared the existing
Iterator
andIndex
implementations on the type, and made sure they both operated on the same kind of value. I don't know how hard this would be to implement. I can have a go at it myself if someone points me in the right direction.Obviously this isn't a very important bug, but it appears to technically be a spurious diagnostic, so I thought I'd report it.
The text was updated successfully, but these errors were encountered: