Skip to content

Commit 815876d

Browse files
committed
Move MSRV tests into the lint specific test files
1 parent b72e451 commit 815876d

File tree

69 files changed

+1290
-632
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1290
-632
lines changed

book/src/development/adding_lints.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,27 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip {
478478
```
479479

480480
Once the `msrv` is added to the lint, a relevant test case should be added to
481-
`tests/ui/min_rust_version_attr.rs` which verifies that the lint isn't emitted
482-
if the project's MSRV is lower.
481+
the lint's test file, `tests/ui/manual_strip.rs` in this example. It should
482+
have a case for the version below the MSRV and one with the same contents but
483+
for the MSRV version itself.
484+
485+
```rust
486+
#![feature(custom_inner_attributes)]
487+
488+
...
489+
490+
fn msrv_1_44() {
491+
#![clippy::msrv = "1.44"]
492+
493+
/* something that would trigger the lint */
494+
}
495+
496+
fn msrv_1_45() {
497+
#![clippy::msrv = "1.45"]
498+
499+
/* something that would trigger the lint */
500+
}
501+
```
483502

484503
As a last step, the lint should be added to the lint documentation. This is done
485504
in `clippy_lints/src/utils/conf.rs`:

tests/ui/cast_abs_to_unsigned.fixed

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// run-rustfix
2+
3+
#![feature(custom_inner_attributes)]
24
#![warn(clippy::cast_abs_to_unsigned)]
3-
#![allow(clippy::uninlined_format_args)]
5+
#![allow(clippy::uninlined_format_args, unused)]
46

57
fn main() {
68
let x: i32 = -42;
@@ -30,3 +32,17 @@ fn main() {
3032

3133
let _ = (x as i64 - y as i64).unsigned_abs() as u32;
3234
}
35+
36+
fn msrv_1_50() {
37+
#![clippy::msrv = "1.50"]
38+
39+
let x: i32 = 10;
40+
assert_eq!(10u32, x.abs() as u32);
41+
}
42+
43+
fn msrv_1_51() {
44+
#![clippy::msrv = "1.51"]
45+
46+
let x: i32 = 10;
47+
assert_eq!(10u32, x.unsigned_abs());
48+
}

tests/ui/cast_abs_to_unsigned.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// run-rustfix
2+
3+
#![feature(custom_inner_attributes)]
24
#![warn(clippy::cast_abs_to_unsigned)]
3-
#![allow(clippy::uninlined_format_args)]
5+
#![allow(clippy::uninlined_format_args, unused)]
46

57
fn main() {
68
let x: i32 = -42;
@@ -30,3 +32,17 @@ fn main() {
3032

3133
let _ = (x as i64 - y as i64).abs() as u32;
3234
}
35+
36+
fn msrv_1_50() {
37+
#![clippy::msrv = "1.50"]
38+
39+
let x: i32 = 10;
40+
assert_eq!(10u32, x.abs() as u32);
41+
}
42+
43+
fn msrv_1_51() {
44+
#![clippy::msrv = "1.51"]
45+
46+
let x: i32 = 10;
47+
assert_eq!(10u32, x.abs() as u32);
48+
}

tests/ui/cast_abs_to_unsigned.stderr

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,112 @@
11
error: casting the result of `i32::abs()` to u32
2-
--> $DIR/cast_abs_to_unsigned.rs:7:18
2+
--> $DIR/cast_abs_to_unsigned.rs:9:18
33
|
44
LL | let y: u32 = x.abs() as u32;
55
| ^^^^^^^^^^^^^^ help: replace with: `x.unsigned_abs()`
66
|
77
= note: `-D clippy::cast-abs-to-unsigned` implied by `-D warnings`
88

99
error: casting the result of `i32::abs()` to usize
10-
--> $DIR/cast_abs_to_unsigned.rs:11:20
10+
--> $DIR/cast_abs_to_unsigned.rs:13:20
1111
|
1212
LL | let _: usize = a.abs() as usize;
1313
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
1414

1515
error: casting the result of `i32::abs()` to usize
16-
--> $DIR/cast_abs_to_unsigned.rs:12:20
16+
--> $DIR/cast_abs_to_unsigned.rs:14:20
1717
|
1818
LL | let _: usize = a.abs() as _;
1919
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
2020

2121
error: casting the result of `i32::abs()` to usize
22-
--> $DIR/cast_abs_to_unsigned.rs:13:13
22+
--> $DIR/cast_abs_to_unsigned.rs:15:13
2323
|
2424
LL | let _ = a.abs() as usize;
2525
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
2626

2727
error: casting the result of `i64::abs()` to usize
28-
--> $DIR/cast_abs_to_unsigned.rs:16:13
28+
--> $DIR/cast_abs_to_unsigned.rs:18:13
2929
|
3030
LL | let _ = a.abs() as usize;
3131
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
3232

3333
error: casting the result of `i64::abs()` to u8
34-
--> $DIR/cast_abs_to_unsigned.rs:17:13
34+
--> $DIR/cast_abs_to_unsigned.rs:19:13
3535
|
3636
LL | let _ = a.abs() as u8;
3737
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
3838

3939
error: casting the result of `i64::abs()` to u16
40-
--> $DIR/cast_abs_to_unsigned.rs:18:13
40+
--> $DIR/cast_abs_to_unsigned.rs:20:13
4141
|
4242
LL | let _ = a.abs() as u16;
4343
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
4444

4545
error: casting the result of `i64::abs()` to u32
46-
--> $DIR/cast_abs_to_unsigned.rs:19:13
46+
--> $DIR/cast_abs_to_unsigned.rs:21:13
4747
|
4848
LL | let _ = a.abs() as u32;
4949
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
5050

5151
error: casting the result of `i64::abs()` to u64
52-
--> $DIR/cast_abs_to_unsigned.rs:20:13
52+
--> $DIR/cast_abs_to_unsigned.rs:22:13
5353
|
5454
LL | let _ = a.abs() as u64;
5555
| ^^^^^^^^^^^^^^ help: replace with: `a.unsigned_abs()`
5656

5757
error: casting the result of `i64::abs()` to u128
58-
--> $DIR/cast_abs_to_unsigned.rs:21:13
58+
--> $DIR/cast_abs_to_unsigned.rs:23:13
5959
|
6060
LL | let _ = a.abs() as u128;
6161
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
6262

6363
error: casting the result of `isize::abs()` to usize
64-
--> $DIR/cast_abs_to_unsigned.rs:24:13
64+
--> $DIR/cast_abs_to_unsigned.rs:26:13
6565
|
6666
LL | let _ = a.abs() as usize;
6767
| ^^^^^^^^^^^^^^^^ help: replace with: `a.unsigned_abs()`
6868

6969
error: casting the result of `isize::abs()` to u8
70-
--> $DIR/cast_abs_to_unsigned.rs:25:13
70+
--> $DIR/cast_abs_to_unsigned.rs:27:13
7171
|
7272
LL | let _ = a.abs() as u8;
7373
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
7474

7575
error: casting the result of `isize::abs()` to u16
76-
--> $DIR/cast_abs_to_unsigned.rs:26:13
76+
--> $DIR/cast_abs_to_unsigned.rs:28:13
7777
|
7878
LL | let _ = a.abs() as u16;
7979
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
8080

8181
error: casting the result of `isize::abs()` to u32
82-
--> $DIR/cast_abs_to_unsigned.rs:27:13
82+
--> $DIR/cast_abs_to_unsigned.rs:29:13
8383
|
8484
LL | let _ = a.abs() as u32;
8585
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
8686

8787
error: casting the result of `isize::abs()` to u64
88-
--> $DIR/cast_abs_to_unsigned.rs:28:13
88+
--> $DIR/cast_abs_to_unsigned.rs:30:13
8989
|
9090
LL | let _ = a.abs() as u64;
9191
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
9292

9393
error: casting the result of `isize::abs()` to u128
94-
--> $DIR/cast_abs_to_unsigned.rs:29:13
94+
--> $DIR/cast_abs_to_unsigned.rs:31:13
9595
|
9696
LL | let _ = a.abs() as u128;
9797
| ^^^^^^^ help: replace with: `a.unsigned_abs()`
9898

9999
error: casting the result of `i64::abs()` to u32
100-
--> $DIR/cast_abs_to_unsigned.rs:31:13
100+
--> $DIR/cast_abs_to_unsigned.rs:33:13
101101
|
102102
LL | let _ = (x as i64 - y as i64).abs() as u32;
103103
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `(x as i64 - y as i64).unsigned_abs()`
104104

105-
error: aborting due to 17 previous errors
105+
error: casting the result of `i32::abs()` to u32
106+
--> $DIR/cast_abs_to_unsigned.rs:47:23
107+
|
108+
LL | assert_eq!(10u32, x.abs() as u32);
109+
| ^^^^^^^^^^^^^^ help: replace with: `x.unsigned_abs()`
110+
111+
error: aborting due to 18 previous errors
106112

tests/ui/cast_lossless_bool.fixed

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// run-rustfix
22

3+
#![feature(custom_inner_attributes)]
34
#![allow(dead_code)]
45
#![warn(clippy::cast_lossless)]
56

@@ -40,3 +41,15 @@ mod cast_lossless_in_impl {
4041
}
4142
}
4243
}
44+
45+
fn msrv_1_27() {
46+
#![clippy::msrv = "1.27"]
47+
48+
let _ = true as u8;
49+
}
50+
51+
fn msrv_1_28() {
52+
#![clippy::msrv = "1.28"]
53+
54+
let _ = u8::from(true);
55+
}

tests/ui/cast_lossless_bool.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// run-rustfix
22

3+
#![feature(custom_inner_attributes)]
34
#![allow(dead_code)]
45
#![warn(clippy::cast_lossless)]
56

@@ -40,3 +41,15 @@ mod cast_lossless_in_impl {
4041
}
4142
}
4243
}
44+
45+
fn msrv_1_27() {
46+
#![clippy::msrv = "1.27"]
47+
48+
let _ = true as u8;
49+
}
50+
51+
fn msrv_1_28() {
52+
#![clippy::msrv = "1.28"]
53+
54+
let _ = true as u8;
55+
}

tests/ui/cast_lossless_bool.stderr

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,88 @@
11
error: casting `bool` to `u8` is more cleanly stated with `u8::from(_)`
2-
--> $DIR/cast_lossless_bool.rs:8:13
2+
--> $DIR/cast_lossless_bool.rs:9:13
33
|
44
LL | let _ = true as u8;
55
| ^^^^^^^^^^ help: try: `u8::from(true)`
66
|
77
= note: `-D clippy::cast-lossless` implied by `-D warnings`
88

99
error: casting `bool` to `u16` is more cleanly stated with `u16::from(_)`
10-
--> $DIR/cast_lossless_bool.rs:9:13
10+
--> $DIR/cast_lossless_bool.rs:10:13
1111
|
1212
LL | let _ = true as u16;
1313
| ^^^^^^^^^^^ help: try: `u16::from(true)`
1414

1515
error: casting `bool` to `u32` is more cleanly stated with `u32::from(_)`
16-
--> $DIR/cast_lossless_bool.rs:10:13
16+
--> $DIR/cast_lossless_bool.rs:11:13
1717
|
1818
LL | let _ = true as u32;
1919
| ^^^^^^^^^^^ help: try: `u32::from(true)`
2020

2121
error: casting `bool` to `u64` is more cleanly stated with `u64::from(_)`
22-
--> $DIR/cast_lossless_bool.rs:11:13
22+
--> $DIR/cast_lossless_bool.rs:12:13
2323
|
2424
LL | let _ = true as u64;
2525
| ^^^^^^^^^^^ help: try: `u64::from(true)`
2626

2727
error: casting `bool` to `u128` is more cleanly stated with `u128::from(_)`
28-
--> $DIR/cast_lossless_bool.rs:12:13
28+
--> $DIR/cast_lossless_bool.rs:13:13
2929
|
3030
LL | let _ = true as u128;
3131
| ^^^^^^^^^^^^ help: try: `u128::from(true)`
3232

3333
error: casting `bool` to `usize` is more cleanly stated with `usize::from(_)`
34-
--> $DIR/cast_lossless_bool.rs:13:13
34+
--> $DIR/cast_lossless_bool.rs:14:13
3535
|
3636
LL | let _ = true as usize;
3737
| ^^^^^^^^^^^^^ help: try: `usize::from(true)`
3838

3939
error: casting `bool` to `i8` is more cleanly stated with `i8::from(_)`
40-
--> $DIR/cast_lossless_bool.rs:15:13
40+
--> $DIR/cast_lossless_bool.rs:16:13
4141
|
4242
LL | let _ = true as i8;
4343
| ^^^^^^^^^^ help: try: `i8::from(true)`
4444

4545
error: casting `bool` to `i16` is more cleanly stated with `i16::from(_)`
46-
--> $DIR/cast_lossless_bool.rs:16:13
46+
--> $DIR/cast_lossless_bool.rs:17:13
4747
|
4848
LL | let _ = true as i16;
4949
| ^^^^^^^^^^^ help: try: `i16::from(true)`
5050

5151
error: casting `bool` to `i32` is more cleanly stated with `i32::from(_)`
52-
--> $DIR/cast_lossless_bool.rs:17:13
52+
--> $DIR/cast_lossless_bool.rs:18:13
5353
|
5454
LL | let _ = true as i32;
5555
| ^^^^^^^^^^^ help: try: `i32::from(true)`
5656

5757
error: casting `bool` to `i64` is more cleanly stated with `i64::from(_)`
58-
--> $DIR/cast_lossless_bool.rs:18:13
58+
--> $DIR/cast_lossless_bool.rs:19:13
5959
|
6060
LL | let _ = true as i64;
6161
| ^^^^^^^^^^^ help: try: `i64::from(true)`
6262

6363
error: casting `bool` to `i128` is more cleanly stated with `i128::from(_)`
64-
--> $DIR/cast_lossless_bool.rs:19:13
64+
--> $DIR/cast_lossless_bool.rs:20:13
6565
|
6666
LL | let _ = true as i128;
6767
| ^^^^^^^^^^^^ help: try: `i128::from(true)`
6868

6969
error: casting `bool` to `isize` is more cleanly stated with `isize::from(_)`
70-
--> $DIR/cast_lossless_bool.rs:20:13
70+
--> $DIR/cast_lossless_bool.rs:21:13
7171
|
7272
LL | let _ = true as isize;
7373
| ^^^^^^^^^^^^^ help: try: `isize::from(true)`
7474

7575
error: casting `bool` to `u16` is more cleanly stated with `u16::from(_)`
76-
--> $DIR/cast_lossless_bool.rs:23:13
76+
--> $DIR/cast_lossless_bool.rs:24:13
7777
|
7878
LL | let _ = (true | false) as u16;
7979
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `u16::from(true | false)`
8080

81-
error: aborting due to 13 previous errors
81+
error: casting `bool` to `u8` is more cleanly stated with `u8::from(_)`
82+
--> $DIR/cast_lossless_bool.rs:54:13
83+
|
84+
LL | let _ = true as u8;
85+
| ^^^^^^^^^^ help: try: `u8::from(true)`
86+
87+
error: aborting due to 14 previous errors
8288

tests/ui/cfg_attr_rustfmt.fixed

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-rustfix
2-
#![feature(stmt_expr_attributes)]
2+
#![feature(stmt_expr_attributes, custom_inner_attributes)]
33

44
#![allow(unused, clippy::no_effect, clippy::unnecessary_operation)]
55
#![warn(clippy::deprecated_cfg_attr)]
@@ -29,3 +29,17 @@ mod foo {
2929

3030
pub fn f() {}
3131
}
32+
33+
fn msrv_1_29() {
34+
#![clippy::msrv = "1.29"]
35+
36+
#[cfg_attr(rustfmt, rustfmt::skip)]
37+
1+29;
38+
}
39+
40+
fn msrv_1_30() {
41+
#![clippy::msrv = "1.30"]
42+
43+
#[rustfmt::skip]
44+
1+30;
45+
}

0 commit comments

Comments
 (0)