You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here the impl of RangeInclusive delegates to the impl of Range by turning the inclusive range into an exclusive range.
Of course the same goes for IndexMut.
The warning is:
warning: an inclusive range would be more readable
--> src/lib.rs:15:20
|
15 | self.index(*i.start()..(*i.end() + 1))
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use: `*i.start()..=*i.end()`
|
= note: #[warn(clippy::range_plus_one)] on by default
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/master/index.html#range_plus_one
Just checking whether ..= is used inside a .. impl isn't enough to cover all cases (though it might be good enough), since it could call other functions that use ..= instead. Would be hard to check against that, though.
Maybe it would make sense to change the lint to detect such ranges being directly passing a function/method expecting an implementation of Iterator/IntoIterator/RangeBounds trait. If a function accepts one of those traits, then barring bugs, ranges should be identical to inclusive ranges. Such an implementation would also fix #3307.
When implementing indexing on
RangeInclusive
, we obviously cannot replacestart .. end+1
withstart ..= end
, as that would be an infinite loop.My situation is something like the following:
Here the impl of
RangeInclusive
delegates to the impl ofRange
by turning the inclusive range into an exclusive range.Of course the same goes for
IndexMut
.The warning is:
Version:
The text was updated successfully, but these errors were encountered: