Skip to content

Commit f3b905d

Browse files
committed
use span_suggestion_verbose
1 parent 4b021f6 commit f3b905d

File tree

2 files changed

+90
-38
lines changed

2 files changed

+90
-38
lines changed

clippy_lints/src/missing_asserts_for_indexing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ fn report_indexes(cx: &LateContext<'_>, map: UnindexMap<u64, Vec<IndexEntry<'_>>
401401
indexes,
402402
"indexing into a slice multiple times with an `assert` that does not cover the highest index",
403403
|diag| {
404-
diag.span_suggestion(
404+
diag.span_suggestion_verbose(
405405
assert_span,
406406
"provide the highest index that is indexed with",
407407
sugg,
Lines changed: 89 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,191 @@
11
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
22
--> tests/ui/missing_asserts_for_indexing.rs:30:5
33
|
4-
LL | assert!(v.len() < 5);
5-
| -------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)`
64
LL | v[0] + v[1] + v[2] + v[3] + v[4]
75
| ^^^^ ^^^^ ^^^^ ^^^^ ^^^^
86
|
97
= note: asserting the length before indexing will elide bounds checks
108
= note: `-D clippy::missing-asserts-for-indexing` implied by `-D warnings`
119
= help: to override `-D warnings` add `#[allow(clippy::missing_asserts_for_indexing)]`
10+
help: provide the highest index that is indexed with
11+
|
12+
LL - assert!(v.len() < 5);
13+
LL + assert!(v.len() > 4);
14+
|
1215

1316
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
1417
--> tests/ui/missing_asserts_for_indexing.rs:36:5
1518
|
16-
LL | assert!(v.len() <= 5);
17-
| --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)`
1819
LL | v[0] + v[1] + v[2] + v[3] + v[4]
1920
| ^^^^ ^^^^ ^^^^ ^^^^ ^^^^
21+
|
22+
help: provide the highest index that is indexed with
23+
|
24+
LL - assert!(v.len() <= 5);
25+
LL + assert!(v.len() > 4);
26+
|
2027

2128
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
2229
--> tests/ui/missing_asserts_for_indexing.rs:42:5
2330
|
24-
LL | assert!(v.len() > 3);
25-
| -------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)`
2631
LL | v[0] + v[1] + v[2] + v[3] + v[4]
2732
| ^^^^ ^^^^ ^^^^ ^^^^ ^^^^
33+
|
34+
help: provide the highest index that is indexed with
35+
|
36+
LL - assert!(v.len() > 3);
37+
LL + assert!(v.len() > 4);
38+
|
2839

2940
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
3041
--> tests/ui/missing_asserts_for_indexing.rs:48:5
3142
|
32-
LL | assert!(v.len() >= 4);
33-
| --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)`
3443
LL | v[0] + v[1] + v[2] + v[3] + v[4]
3544
| ^^^^ ^^^^ ^^^^ ^^^^ ^^^^
45+
|
46+
help: provide the highest index that is indexed with
47+
|
48+
LL - assert!(v.len() >= 4);
49+
LL + assert!(v.len() > 4);
50+
|
3651

3752
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
3853
--> tests/ui/missing_asserts_for_indexing.rs:66:13
3954
|
40-
LL | assert!(v.len() >= 3);
41-
| --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 3)`
4255
LL | let _ = v[0];
4356
| ^^^^
4457
...
4558
LL | let _ = v[1..4];
4659
| ^^^^^^^
60+
|
61+
help: provide the highest index that is indexed with
62+
|
63+
LL - assert!(v.len() >= 3);
64+
LL + assert!(v.len() > 3);
65+
|
4766

4867
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
4968
--> tests/ui/missing_asserts_for_indexing.rs:81:13
5069
|
51-
LL | assert!(v.len() >= 4);
52-
| --------------------- help: provide the highest index that is indexed with: `assert!(v.len() > 4)`
5370
LL | let _ = v[0];
5471
| ^^^^
5572
...
5673
LL | let _ = v[1..=4];
5774
| ^^^^^^^^
75+
|
76+
help: provide the highest index that is indexed with
77+
|
78+
LL - assert!(v.len() >= 4);
79+
LL + assert!(v.len() > 4);
80+
|
5881

5982
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
6083
--> tests/ui/missing_asserts_for_indexing.rs:97:13
6184
|
62-
LL | assert!(v1.len() >= 12);
63-
| ----------------------- help: provide the highest index that is indexed with: `assert!(v1.len() > 12)`
64-
LL | assert!(v2.len() >= 15);
6585
LL | let _ = v1[0] + v1[12];
6686
| ^^^^^ ^^^^^^
87+
|
88+
help: provide the highest index that is indexed with
89+
|
90+
LL - assert!(v1.len() >= 12);
91+
LL + assert!(v1.len() > 12);
92+
|
6793

6894
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
6995
--> tests/ui/missing_asserts_for_indexing.rs:100:13
7096
|
71-
LL | assert!(v2.len() >= 15);
72-
| ----------------------- help: provide the highest index that is indexed with: `assert!(v2.len() > 15)`
73-
...
7497
LL | let _ = v2[5] + v2[15];
7598
| ^^^^^ ^^^^^^
99+
|
100+
help: provide the highest index that is indexed with
101+
|
102+
LL - assert!(v2.len() >= 15);
103+
LL + assert!(v2.len() > 15);
104+
|
76105

77106
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
78107
--> tests/ui/missing_asserts_for_indexing.rs:106:13
79108
|
80-
LL | assert!(v1.len() >= 12);
81-
| ----------------------- help: provide the highest index that is indexed with: `assert!(v1.len() > 12)`
82-
LL | assert!(v2.len() > 15);
83109
LL | let _ = v1[0] + v1[12];
84110
| ^^^^^ ^^^^^^
111+
|
112+
help: provide the highest index that is indexed with
113+
|
114+
LL - assert!(v1.len() >= 12);
115+
LL + assert!(v1.len() > 12);
116+
|
85117

86118
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
87119
--> tests/ui/missing_asserts_for_indexing.rs:131:13
88120
|
89-
LL | assert!(v1.len() == 2);
90-
| ---------------------- help: provide the highest index that is indexed with: `assert!(v1.len() == 3)`
91-
...
92121
LL | let _ = v1[0] + v1[1] + v1[2];
93122
| ^^^^^ ^^^^^ ^^^^^
123+
|
124+
help: provide the highest index that is indexed with
125+
|
126+
LL - assert!(v1.len() == 2);
127+
LL + assert!(v1.len() == 3);
128+
|
94129

95130
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
96131
--> tests/ui/missing_asserts_for_indexing.rs:136:13
97132
|
98-
LL | assert!(2 == v3.len());
99-
| ---------------------- help: provide the highest index that is indexed with: `assert!(v3.len() == 3)`
100-
...
101133
LL | let _ = v3[0] + v3[1] + v3[2];
102134
| ^^^^^ ^^^^^ ^^^^^
135+
|
136+
help: provide the highest index that is indexed with
137+
|
138+
LL - assert!(2 == v3.len());
139+
LL + assert!(v3.len() == 3);
140+
|
103141

104142
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
105143
--> tests/ui/missing_asserts_for_indexing.rs:158:13
106144
|
107-
LL | assert_eq!(v1.len(), 2);
108-
| ----------------------- help: provide the highest index that is indexed with: `assert_eq!(v1.len(), 3)`
109-
...
110145
LL | let _ = v1[0] + v1[1] + v1[2];
111146
| ^^^^^ ^^^^^ ^^^^^
147+
|
148+
help: provide the highest index that is indexed with
149+
|
150+
LL - assert_eq!(v1.len(), 2);
151+
LL + assert_eq!(v1.len(), 3);
152+
|
112153

113154
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
114155
--> tests/ui/missing_asserts_for_indexing.rs:163:13
115156
|
116-
LL | assert_eq!(2, v3.len());
117-
| ----------------------- help: provide the highest index that is indexed with: `assert_eq!(v3.len(), 3)`
118-
...
119157
LL | let _ = v3[0] + v3[1] + v3[2];
120158
| ^^^^^ ^^^^^ ^^^^^
159+
|
160+
help: provide the highest index that is indexed with
161+
|
162+
LL - assert_eq!(2, v3.len());
163+
LL + assert_eq!(v3.len(), 3);
164+
|
121165

122166
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
123167
--> tests/ui/missing_asserts_for_indexing.rs:172:17
124168
|
125-
LL | assert_eq!(v.len(), 2);
126-
| ---------------------- help: provide the highest index that is indexed with: `assert_eq!(v.len(), 3)`
127169
LL | let _ = v[0] + v[1] + v[2];
128170
| ^^^^ ^^^^ ^^^^
171+
|
172+
help: provide the highest index that is indexed with
173+
|
174+
LL - assert_eq!(v.len(), 2);
175+
LL + assert_eq!(v.len(), 3);
176+
|
129177

130178
error: indexing into a slice multiple times with an `assert` that does not cover the highest index
131179
--> tests/ui/missing_asserts_for_indexing.rs:178:17
132180
|
133-
LL | debug_assert_eq!(v.len(), 2);
134-
| ---------------------------- help: provide the highest index that is indexed with: `debug_assert_eq!(v.len(), 3)`
135181
LL | let _ = v[0] + v[1] + v[2];
136182
| ^^^^ ^^^^ ^^^^
183+
|
184+
help: provide the highest index that is indexed with
185+
|
186+
LL - debug_assert_eq!(v.len(), 2);
187+
LL + debug_assert_eq!(v.len(), 3);
188+
|
137189

138190
error: aborting due to 15 previous errors
139191

0 commit comments

Comments
 (0)