Skip to content

Commit 16781a1

Browse files
committed
Add tests for range_plus_one and range_minus_one
1 parent e9be753 commit 16781a1

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

tests/ui/range_plus_minus_one.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#![feature(inclusive_range_syntax)]
2+
3+
fn f() -> usize {
4+
42
5+
}
6+
7+
#[warn(range_plus_one)]
8+
fn main() {
9+
for _ in 0..2 { }
10+
for _ in 0..=2 { }
11+
12+
for _ in 0..3+1 { }
13+
for _ in 0..=3+1 { }
14+
15+
for _ in 0..1+5 { }
16+
for _ in 0..=1+5 { }
17+
18+
for _ in 1..1+1 { }
19+
for _ in 1..=1+1 { }
20+
21+
for _ in 0..13+13 { }
22+
for _ in 0..=13-7 { }
23+
24+
for _ in 0..(1+f()) { }
25+
for _ in 0..=(1+f()) { }
26+
27+
let _ = ..11-1;
28+
let _ = ..=11-1;
29+
let _ = ..=(11-1);
30+
let _ = (f()+1)..(f()+1);
31+
32+
let mut vec: Vec<()> = std::vec::Vec::new();
33+
vec.drain(..);
34+
}

tests/ui/range_plus_minus_one.stderr

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
error: an inclusive range would be more readable
2+
--> $DIR/range_plus_minus_one.rs:12:14
3+
|
4+
12 | for _ in 0..3+1 { }
5+
| ------
6+
| |
7+
| help: use: `0..=3`
8+
| in this macro invocation
9+
|
10+
= note: `-D range-plus-one` implied by `-D warnings`
11+
12+
error: an inclusive range would be more readable
13+
--> $DIR/range_plus_minus_one.rs:15:14
14+
|
15+
15 | for _ in 0..1+5 { }
16+
| ------
17+
| |
18+
| help: use: `0..=5`
19+
| in this macro invocation
20+
21+
error: an inclusive range would be more readable
22+
--> $DIR/range_plus_minus_one.rs:18:14
23+
|
24+
18 | for _ in 1..1+1 { }
25+
| ------
26+
| |
27+
| help: use: `1..=1`
28+
| in this macro invocation
29+
30+
error: an inclusive range would be more readable
31+
--> $DIR/range_plus_minus_one.rs:24:14
32+
|
33+
24 | for _ in 0..(1+f()) { }
34+
| ----------
35+
| |
36+
| help: use: `0..=f()`
37+
| in this macro invocation
38+
39+
error: an exclusive range would be more readable
40+
--> $DIR/range_plus_minus_one.rs:28:13
41+
|
42+
28 | let _ = ..=11-1;
43+
| -------
44+
| |
45+
| help: use: `..11`
46+
| in this macro invocation
47+
|
48+
= note: `-D range-minus-one` implied by `-D warnings`
49+
50+
error: an exclusive range would be more readable
51+
--> $DIR/range_plus_minus_one.rs:29:13
52+
|
53+
29 | let _ = ..=(11-1);
54+
| ---------
55+
| |
56+
| help: use: `..11`
57+
| in this macro invocation
58+
59+
error: an inclusive range would be more readable
60+
--> $DIR/range_plus_minus_one.rs:30:13
61+
|
62+
30 | let _ = (f()+1)..(f()+1);
63+
| ----------------
64+
| |
65+
| help: use: `(f()+1)..=f()`
66+
| in this macro invocation
67+

0 commit comments

Comments
 (0)