Skip to content

Commit a2ab069

Browse files
committed
identity_conversion: make it use a rustfix test
1 parent bbfb9a4 commit a2ab069

File tree

3 files changed

+71
-11
lines changed

3 files changed

+71
-11
lines changed

tests/ui/identity_conversion.fixed

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// run-rustfix
2+
3+
#![deny(clippy::identity_conversion)]
4+
5+
fn test_generic<T: Copy>(val: T) -> T {
6+
let _ = val;
7+
val
8+
}
9+
10+
fn test_generic2<T: Copy + Into<i32> + Into<U>, U: From<T>>(val: T) {
11+
// ok
12+
let _: i32 = val.into();
13+
let _: U = val.into();
14+
let _ = U::from(val);
15+
}
16+
17+
fn test_questionmark() -> Result<(), ()> {
18+
{
19+
let _: i32 = 0i32;
20+
Ok(Ok(()))
21+
}??;
22+
Ok(())
23+
}
24+
25+
fn test_issue_3913() -> Result<(), std::io::Error> {
26+
use std::fs;
27+
use std::path::Path;
28+
29+
let path = Path::new(".");
30+
for _ in fs::read_dir(path)? {}
31+
32+
Ok(())
33+
}
34+
35+
fn main() {
36+
test_generic(10i32);
37+
test_generic2::<i32, i32>(10i32);
38+
test_questionmark().unwrap();
39+
test_issue_3913().unwrap();
40+
41+
let _: String = "foo".into();
42+
let _: String = From::from("foo");
43+
let _ = String::from("foo");
44+
#[allow(clippy::identity_conversion)]
45+
{
46+
let _: String = "foo".into();
47+
let _ = String::from("foo");
48+
let _ = "".lines().into_iter();
49+
}
50+
51+
let _: String = "foo".to_string();
52+
let _: String = "foo".to_string();
53+
let _ = "foo".to_string();
54+
let _ = format!("A: {:04}", 123);
55+
let _ = "".lines();
56+
let _ = vec![1, 2, 3].into_iter();
57+
let _: String = format!("Hello {}", "world");
58+
}

tests/ui/identity_conversion.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// run-rustfix
2+
13
#![deny(clippy::identity_conversion)]
24

35
fn test_generic<T: Copy>(val: T) -> T {

tests/ui/identity_conversion.stderr

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
11
error: identical conversion
2-
--> $DIR/identity_conversion.rs:4:13
2+
--> $DIR/identity_conversion.rs:6:13
33
|
44
LL | let _ = T::from(val);
55
| ^^^^^^^^^^^^ help: consider removing `T::from()`: `val`
66
|
77
note: lint level defined here
8-
--> $DIR/identity_conversion.rs:1:9
8+
--> $DIR/identity_conversion.rs:3:9
99
|
1010
LL | #![deny(clippy::identity_conversion)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: identical conversion
14-
--> $DIR/identity_conversion.rs:5:5
14+
--> $DIR/identity_conversion.rs:7:5
1515
|
1616
LL | val.into()
1717
| ^^^^^^^^^^ help: consider removing `.into()`: `val`
1818

1919
error: identical conversion
20-
--> $DIR/identity_conversion.rs:17:22
20+
--> $DIR/identity_conversion.rs:19:22
2121
|
2222
LL | let _: i32 = 0i32.into();
2323
| ^^^^^^^^^^^ help: consider removing `.into()`: `0i32`
2424

2525
error: identical conversion
26-
--> $DIR/identity_conversion.rs:49:21
26+
--> $DIR/identity_conversion.rs:51:21
2727
|
2828
LL | let _: String = "foo".to_string().into();
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `"foo".to_string()`
3030

3131
error: identical conversion
32-
--> $DIR/identity_conversion.rs:50:21
32+
--> $DIR/identity_conversion.rs:52:21
3333
|
3434
LL | let _: String = From::from("foo".to_string());
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `From::from()`: `"foo".to_string()`
3636

3737
error: identical conversion
38-
--> $DIR/identity_conversion.rs:51:13
38+
--> $DIR/identity_conversion.rs:53:13
3939
|
4040
LL | let _ = String::from("foo".to_string());
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `"foo".to_string()`
4242

4343
error: identical conversion
44-
--> $DIR/identity_conversion.rs:52:13
44+
--> $DIR/identity_conversion.rs:54:13
4545
|
4646
LL | let _ = String::from(format!("A: {:04}", 123));
4747
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `format!("A: {:04}", 123)`
4848

4949
error: identical conversion
50-
--> $DIR/identity_conversion.rs:53:13
50+
--> $DIR/identity_conversion.rs:55:13
5151
|
5252
LL | let _ = "".lines().into_iter();
5353
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `"".lines()`
5454

5555
error: identical conversion
56-
--> $DIR/identity_conversion.rs:54:13
56+
--> $DIR/identity_conversion.rs:56:13
5757
|
5858
LL | let _ = vec![1, 2, 3].into_iter().into_iter();
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![1, 2, 3].into_iter()`
6060

6161
error: identical conversion
62-
--> $DIR/identity_conversion.rs:55:21
62+
--> $DIR/identity_conversion.rs:57:21
6363
|
6464
LL | let _: String = format!("Hello {}", "world").into();
6565
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `format!("Hello {}", "world")`

0 commit comments

Comments
 (0)