rust-clippy
rust-clippy copied to clipboard
Propose to exchange ranges only when it is safe to do so
To avoid false positives, the range_plus_one and range_minus_one lints will restrict themselves to situations where the iterator types can be easily switched from exclusive to inclusive or vice-versa. This includes situations where the range is used as an iterator, or is used for indexing.
On the other hand, assignments of the range to variables, including automatically typed ones or wildcards, will no longer trigger the lint. However, the cases where such an assignment would benefit from the lint are probably rare.
In a second commit, the range_plus_one and range_minus_one logic are unified, in order to properly emit parentheses around the suggestion when needed.
Fix rust-lang/rust-clippy#3307 Fix rust-lang/rust-clippy#9908
changelog: [range_plus_one, range_minus_one]: restrict lint to cases where it is safe to switch the range type
Edit: as a consequence, this led to the removal of three #[expect(clippy::range_plus_one)] in the Clippy sources to avoid those false positives.