]> git.lizzy.rs Git - rust.git/blob - src/docs/range_minus_one.txt
Auto merge of #9425 - kraktus:patch-1, r=xFrednet
[rust.git] / src / docs / range_minus_one.txt
1 ### What it does
2 Checks for inclusive ranges where 1 is subtracted from
3 the upper bound, e.g., `x..=(y-1)`.
4
5 ### Why is this bad?
6 The code is more readable with an exclusive range
7 like `x..y`.
8
9 ### Known problems
10 This will cause a warning that cannot be fixed if
11 the consumer of the range only accepts a specific range type, instead of
12 the generic `RangeBounds` trait
13 ([#3307](https://github.com/rust-lang/rust-clippy/issues/3307)).
14
15 ### Example
16 ```
17 for i in x..=(y-1) {
18     // ..
19 }
20 ```
21
22 Use instead:
23 ```
24 for i in x..y {
25     // ..
26 }
27 ```