missing_asserts_for_indexing
understands assert!(x.len()==2)
but not assert_eq!(x.len(), 2)
#14255
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-positive
Issue: The lint was triggered on code it shouldn't have
Summary
missing_asserts_for_indexing
is saying to get bounds checking done up-front, I should add an assert on the length of the slice. Great.Because I happen to be writing a test, I know exactly the length, and chose to write an equality and not a
>
check.Generally,
assert_eq!
is to be preferred overassert!(a == b)
, so I used that.Clippy didn't recognize that as satisfactory, and the warning is still there. Adding
assert!(s.len() == 2)
right next to the other assert silences Clippy.Either one should have been enough.
Lint Name
missing_asserts_for_indexing
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen:
No warning, behave like with the commented-out
assert!(demo.len() == 2);
.Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: