Skip to content

Commit 37b15ca

Browse files
committed
Remove constants in clippy tests that hide follow-up lints
1 parent 94329f6 commit 37b15ca

File tree

4 files changed

+23
-64
lines changed

4 files changed

+23
-64
lines changed

src/tools/clippy/tests/ui-toml/suppress_lint_in_const/test.rs

-5
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
const ARR: [i32; 2] = [1, 2];
1515
const REF: &i32 = &ARR[idx()]; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true.
16-
const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
17-
//~^ ERROR: failed
1816

1917
const fn idx() -> usize {
2018
1
@@ -35,9 +33,6 @@ fn main() {
3533
x[const { idx() }]; // Ok, should not produce stderr.
3634
x[const { idx4() }]; // Ok, let rustc's `unconditional_panic` lint handle `usize` indexing on arrays.
3735
const { &ARR[idx()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true.
38-
const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true.
39-
//
40-
//~^^ ERROR: failed
4136

4237
let y = &x;
4338
y[0]; // Ok, referencing shouldn't affect this lint. See the issue 6021
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
error[E0080]: evaluation of `main::{constant#3}` failed
2-
--> $DIR/test.rs:38:14
3-
|
4-
LL | const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true.
5-
| ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4
6-
7-
note: erroneous constant encountered
8-
--> $DIR/test.rs:38:5
9-
|
10-
LL | const { &ARR[idx4()] }; // Ok, should not produce stderr, since `suppress-restriction-lint-in-const` is set true.
11-
| ^^^^^^^^^^^^^^^^^^^^^^
12-
131
error: indexing may panic
14-
--> $DIR/test.rs:29:5
2+
--> $DIR/test.rs:27:5
153
|
164
LL | x[index];
175
| ^^^^^^^^
@@ -21,51 +9,44 @@ LL | x[index];
219
= help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]`
2210

2311
error: indexing may panic
24-
--> $DIR/test.rs:47:5
12+
--> $DIR/test.rs:42:5
2513
|
2614
LL | v[0];
2715
| ^^^^
2816
|
2917
= help: consider using `.get(n)` or `.get_mut(n)` instead
3018

3119
error: indexing may panic
32-
--> $DIR/test.rs:48:5
20+
--> $DIR/test.rs:43:5
3321
|
3422
LL | v[10];
3523
| ^^^^^
3624
|
3725
= help: consider using `.get(n)` or `.get_mut(n)` instead
3826

3927
error: indexing may panic
40-
--> $DIR/test.rs:49:5
28+
--> $DIR/test.rs:44:5
4129
|
4230
LL | v[1 << 3];
4331
| ^^^^^^^^^
4432
|
4533
= help: consider using `.get(n)` or `.get_mut(n)` instead
4634

4735
error: indexing may panic
48-
--> $DIR/test.rs:55:5
36+
--> $DIR/test.rs:50:5
4937
|
5038
LL | v[N];
5139
| ^^^^
5240
|
5341
= help: consider using `.get(n)` or `.get_mut(n)` instead
5442

5543
error: indexing may panic
56-
--> $DIR/test.rs:56:5
44+
--> $DIR/test.rs:51:5
5745
|
5846
LL | v[M];
5947
| ^^^^
6048
|
6149
= help: consider using `.get(n)` or `.get_mut(n)` instead
6250

63-
error[E0080]: evaluation of constant value failed
64-
--> $DIR/test.rs:16:24
65-
|
66-
LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
67-
| ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4
68-
69-
error: aborting due to 8 previous errors
51+
error: aborting due to 6 previous errors
7052

71-
For more information about this error, try `rustc --explain E0080`.

src/tools/clippy/tests/ui/indexing_slicing_index.rs

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
const ARR: [i32; 2] = [1, 2];
1414
const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-restriction-lint-in-const` default is false.
1515
//~^ ERROR: indexing may panic
16-
const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
17-
//~^ ERROR: indexing may panic
1816

1917
const fn idx() -> usize {
2018
1

src/tools/clippy/tests/ui/indexing_slicing_index.stderr

+16-31
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,28 @@ LL | const REF: &i32 = &ARR[idx()]; // This should be linted, since `suppress-re
99
= note: `-D clippy::indexing-slicing` implied by `-D warnings`
1010
= help: to override `-D warnings` add `#[allow(clippy::indexing_slicing)]`
1111

12-
error: indexing may panic
13-
--> $DIR/indexing_slicing_index.rs:16:24
14-
|
15-
LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
16-
| ^^^^^^^^^^^
17-
|
18-
= help: consider using `.get(n)` or `.get_mut(n)` instead
19-
= note: the suggestion might not be applicable in constant blocks
20-
2112
error[E0080]: evaluation of `main::{constant#3}` failed
22-
--> $DIR/indexing_slicing_index.rs:48:14
13+
--> $DIR/indexing_slicing_index.rs:46:14
2314
|
2415
LL | const { &ARR[idx4()] };
2516
| ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4
2617

2718
note: erroneous constant encountered
28-
--> $DIR/indexing_slicing_index.rs:48:5
19+
--> $DIR/indexing_slicing_index.rs:46:5
2920
|
3021
LL | const { &ARR[idx4()] };
3122
| ^^^^^^^^^^^^^^^^^^^^^^
3223

3324
error: indexing may panic
34-
--> $DIR/indexing_slicing_index.rs:29:5
25+
--> $DIR/indexing_slicing_index.rs:27:5
3526
|
3627
LL | x[index];
3728
| ^^^^^^^^
3829
|
3930
= help: consider using `.get(n)` or `.get_mut(n)` instead
4031

4132
error: index is out of bounds
42-
--> $DIR/indexing_slicing_index.rs:32:5
33+
--> $DIR/indexing_slicing_index.rs:30:5
4334
|
4435
LL | x[4];
4536
| ^^^^
@@ -48,13 +39,13 @@ LL | x[4];
4839
= help: to override `-D warnings` add `#[allow(clippy::out_of_bounds_indexing)]`
4940

5041
error: index is out of bounds
51-
--> $DIR/indexing_slicing_index.rs:34:5
42+
--> $DIR/indexing_slicing_index.rs:32:5
5243
|
5344
LL | x[1 << 3];
5445
| ^^^^^^^^^
5546

5647
error: indexing may panic
57-
--> $DIR/indexing_slicing_index.rs:45:14
48+
--> $DIR/indexing_slicing_index.rs:43:14
5849
|
5950
LL | const { &ARR[idx()] };
6051
| ^^^^^^^^^^
@@ -63,7 +54,7 @@ LL | const { &ARR[idx()] };
6354
= note: the suggestion might not be applicable in constant blocks
6455

6556
error: indexing may panic
66-
--> $DIR/indexing_slicing_index.rs:48:14
57+
--> $DIR/indexing_slicing_index.rs:46:14
6758
|
6859
LL | const { &ARR[idx4()] };
6960
| ^^^^^^^^^^^
@@ -72,69 +63,63 @@ LL | const { &ARR[idx4()] };
7263
= note: the suggestion might not be applicable in constant blocks
7364

7465
error: index is out of bounds
75-
--> $DIR/indexing_slicing_index.rs:55:5
66+
--> $DIR/indexing_slicing_index.rs:53:5
7667
|
7768
LL | y[4];
7869
| ^^^^
7970

8071
error: indexing may panic
81-
--> $DIR/indexing_slicing_index.rs:58:5
72+
--> $DIR/indexing_slicing_index.rs:56:5
8273
|
8374
LL | v[0];
8475
| ^^^^
8576
|
8677
= help: consider using `.get(n)` or `.get_mut(n)` instead
8778

8879
error: indexing may panic
89-
--> $DIR/indexing_slicing_index.rs:60:5
80+
--> $DIR/indexing_slicing_index.rs:58:5
9081
|
9182
LL | v[10];
9283
| ^^^^^
9384
|
9485
= help: consider using `.get(n)` or `.get_mut(n)` instead
9586

9687
error: indexing may panic
97-
--> $DIR/indexing_slicing_index.rs:62:5
88+
--> $DIR/indexing_slicing_index.rs:60:5
9889
|
9990
LL | v[1 << 3];
10091
| ^^^^^^^^^
10192
|
10293
= help: consider using `.get(n)` or `.get_mut(n)` instead
10394

10495
error: index is out of bounds
105-
--> $DIR/indexing_slicing_index.rs:70:5
96+
--> $DIR/indexing_slicing_index.rs:68:5
10697
|
10798
LL | x[N];
10899
| ^^^^
109100

110101
error: indexing may panic
111-
--> $DIR/indexing_slicing_index.rs:73:5
102+
--> $DIR/indexing_slicing_index.rs:71:5
112103
|
113104
LL | v[N];
114105
| ^^^^
115106
|
116107
= help: consider using `.get(n)` or `.get_mut(n)` instead
117108

118109
error: indexing may panic
119-
--> $DIR/indexing_slicing_index.rs:75:5
110+
--> $DIR/indexing_slicing_index.rs:73:5
120111
|
121112
LL | v[M];
122113
| ^^^^
123114
|
124115
= help: consider using `.get(n)` or `.get_mut(n)` instead
125116

126117
error: index is out of bounds
127-
--> $DIR/indexing_slicing_index.rs:79:13
118+
--> $DIR/indexing_slicing_index.rs:77:13
128119
|
129120
LL | let _ = x[4];
130121
| ^^^^
131122

132-
error[E0080]: evaluation of constant value failed
133-
--> $DIR/indexing_slicing_index.rs:16:24
134-
|
135-
LL | const REF_ERR: &i32 = &ARR[idx4()]; // Ok, let rustc handle const contexts.
136-
| ^^^^^^^^^^^ index out of bounds: the length is 2 but the index is 4
137-
138-
error: aborting due to 17 previous errors
123+
error: aborting due to 15 previous errors
139124

140125
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)