Skip to content

Commit 1801841

Browse files
committed
Add test cases for broader coverage
1 parent 705bfdc commit 1801841

File tree

4 files changed

+47
-23
lines changed

4 files changed

+47
-23
lines changed

clippy_lints/src/useless_conversion.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessConversion {
7171
cx,
7272
USELESS_CONVERSION,
7373
e.span,
74-
"Useless conversion to the same type",
74+
"useless conversion to the same type",
7575
"consider removing `.into()`",
7676
sugg,
7777
Applicability::MachineApplicable, // snippet
@@ -87,7 +87,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessConversion {
8787
cx,
8888
USELESS_CONVERSION,
8989
e.span,
90-
"Useless conversion to the same type",
90+
"useless conversion to the same type",
9191
"consider removing `.into_iter()`",
9292
sugg,
9393
Applicability::MachineApplicable, // snippet
@@ -108,7 +108,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessConversion {
108108
cx,
109109
USELESS_CONVERSION,
110110
e.span,
111-
"Useless conversion to the same type",
111+
"useless conversion to the same type",
112112
None,
113113
"consider removing `.try_into()`",
114114
);
@@ -139,7 +139,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessConversion {
139139
cx,
140140
USELESS_CONVERSION,
141141
e.span,
142-
"Useless conversion to the same type",
142+
"useless conversion to the same type",
143143
None,
144144
&hint,
145145
);
@@ -158,7 +158,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessConversion {
158158
cx,
159159
USELESS_CONVERSION,
160160
e.span,
161-
"Useless conversion to the same type",
161+
"useless conversion to the same type",
162162
&sugg_msg,
163163
sugg,
164164
Applicability::MachineApplicable, // snippet

tests/ui/useless_conversion.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: Useless conversion to the same type
1+
error: useless conversion to the same type
22
--> $DIR/useless_conversion.rs:6:13
33
|
44
LL | let _ = T::from(val);
@@ -10,55 +10,55 @@ note: the lint level is defined here
1010
LL | #![deny(clippy::useless_conversion)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13-
error: Useless conversion to the same type
13+
error: useless conversion to the same type
1414
--> $DIR/useless_conversion.rs:7:5
1515
|
1616
LL | val.into()
1717
| ^^^^^^^^^^ help: consider removing `.into()`: `val`
1818

19-
error: Useless conversion to the same type
19+
error: useless conversion to the same type
2020
--> $DIR/useless_conversion.rs:19:22
2121
|
2222
LL | let _: i32 = 0i32.into();
2323
| ^^^^^^^^^^^ help: consider removing `.into()`: `0i32`
2424

25-
error: Useless conversion to the same type
25+
error: useless conversion to the same type
2626
--> $DIR/useless_conversion.rs:51:21
2727
|
2828
LL | let _: String = "foo".to_string().into();
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `"foo".to_string()`
3030

31-
error: Useless conversion to the same type
31+
error: useless conversion to the same type
3232
--> $DIR/useless_conversion.rs:52:21
3333
|
3434
LL | let _: String = From::from("foo".to_string());
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `From::from()`: `"foo".to_string()`
3636

37-
error: Useless conversion to the same type
37+
error: useless conversion to the same type
3838
--> $DIR/useless_conversion.rs:53:13
3939
|
4040
LL | let _ = String::from("foo".to_string());
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `"foo".to_string()`
4242

43-
error: Useless conversion to the same type
43+
error: useless conversion to the same type
4444
--> $DIR/useless_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

49-
error: Useless conversion to the same type
49+
error: useless conversion to the same type
5050
--> $DIR/useless_conversion.rs:55:13
5151
|
5252
LL | let _ = "".lines().into_iter();
5353
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `"".lines()`
5454

55-
error: Useless conversion to the same type
55+
error: useless conversion to the same type
5656
--> $DIR/useless_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

61-
error: Useless conversion to the same type
61+
error: useless conversion to the same type
6262
--> $DIR/useless_conversion.rs:57:21
6363
|
6464
LL | let _: String = format!("Hello {}", "world").into();

tests/ui/useless_conversion_try.rs

+8
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,12 @@ fn main() {
3131
let _ = String::try_from("foo".to_string()).unwrap();
3232
let _ = String::try_from(format!("A: {:04}", 123)).unwrap();
3333
let _: String = format!("Hello {}", "world").try_into().unwrap();
34+
let _: String = "".to_owned().try_into().unwrap();
35+
let _: String = match String::from("_").try_into() {
36+
Ok(a) => a,
37+
Err(_) => "".into(),
38+
};
39+
// FIXME this is a false negative
40+
#[allow(clippy::cmp_owned)]
41+
if String::from("a") == TryInto::<String>::try_into(String::from("a")).unwrap() {}
3442
}
+24-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: Useless conversion to the same type
1+
error: useless conversion to the same type
22
--> $DIR/useless_conversion_try.rs:6:13
33
|
44
LL | let _ = T::try_from(val).unwrap();
@@ -11,53 +11,69 @@ LL | #![deny(clippy::useless_conversion)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
= help: consider removing `T::try_from()`
1313

14-
error: Useless conversion to the same type
14+
error: useless conversion to the same type
1515
--> $DIR/useless_conversion_try.rs:7:5
1616
|
1717
LL | val.try_into().unwrap()
1818
| ^^^^^^^^^^^^^^
1919
|
2020
= help: consider removing `.try_into()`
2121

22-
error: Useless conversion to the same type
22+
error: useless conversion to the same type
2323
--> $DIR/useless_conversion_try.rs:29:21
2424
|
2525
LL | let _: String = "foo".to_string().try_into().unwrap();
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2727
|
2828
= help: consider removing `.try_into()`
2929

30-
error: Useless conversion to the same type
30+
error: useless conversion to the same type
3131
--> $DIR/useless_conversion_try.rs:30:21
3232
|
3333
LL | let _: String = TryFrom::try_from("foo".to_string()).unwrap();
3434
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3535
|
3636
= help: consider removing `TryFrom::try_from()`
3737

38-
error: Useless conversion to the same type
38+
error: useless conversion to the same type
3939
--> $DIR/useless_conversion_try.rs:31:13
4040
|
4141
LL | let _ = String::try_from("foo".to_string()).unwrap();
4242
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4343
|
4444
= help: consider removing `String::try_from()`
4545

46-
error: Useless conversion to the same type
46+
error: useless conversion to the same type
4747
--> $DIR/useless_conversion_try.rs:32:13
4848
|
4949
LL | let _ = String::try_from(format!("A: {:04}", 123)).unwrap();
5050
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5151
|
5252
= help: consider removing `String::try_from()`
5353

54-
error: Useless conversion to the same type
54+
error: useless conversion to the same type
5555
--> $DIR/useless_conversion_try.rs:33:21
5656
|
5757
LL | let _: String = format!("Hello {}", "world").try_into().unwrap();
5858
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5959
|
6060
= help: consider removing `.try_into()`
6161

62-
error: aborting due to 7 previous errors
62+
error: useless conversion to the same type
63+
--> $DIR/useless_conversion_try.rs:34:21
64+
|
65+
LL | let _: String = "".to_owned().try_into().unwrap();
66+
| ^^^^^^^^^^^^^^^^^^^^^^^^
67+
|
68+
= help: consider removing `.try_into()`
69+
70+
error: useless conversion to the same type
71+
--> $DIR/useless_conversion_try.rs:35:27
72+
|
73+
LL | let _: String = match String::from("_").try_into() {
74+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
75+
|
76+
= help: consider removing `.try_into()`
77+
78+
error: aborting due to 9 previous errors
6379

0 commit comments

Comments
 (0)