Skip to content

Commit 231444d

Browse files
committed
Auto merge of rust-lang#6035 - matthiaskrgr:try_into_show_type, r=flip1995
useless_conversion: show type in error message. changelog: useless_conversion: show type in error message.
2 parents f96c47e + 7ba1a8f commit 231444d

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

clippy_lints/src/useless_conversion.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
7272
cx,
7373
USELESS_CONVERSION,
7474
e.span,
75-
"useless conversion to the same type",
75+
&format!("useless conversion to the same type: `{}`", b),
7676
"consider removing `.into()`",
7777
sugg,
7878
Applicability::MachineApplicable, // snippet
@@ -95,7 +95,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
9595
cx,
9696
USELESS_CONVERSION,
9797
e.span,
98-
"useless conversion to the same type",
98+
&format!("useless conversion to the same type: `{}`", b),
9999
"consider removing `.into_iter()`",
100100
sugg,
101101
Applicability::MachineApplicable, // snippet
@@ -116,7 +116,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
116116
cx,
117117
USELESS_CONVERSION,
118118
e.span,
119-
"useless conversion to the same type",
119+
&format!("useless conversion to the same type: `{}`", b),
120120
None,
121121
"consider removing `.try_into()`",
122122
);
@@ -147,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
147147
cx,
148148
USELESS_CONVERSION,
149149
e.span,
150-
"useless conversion to the same type",
150+
&format!("useless conversion to the same type: `{}`", b),
151151
None,
152152
&hint,
153153
);
@@ -166,7 +166,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
166166
cx,
167167
USELESS_CONVERSION,
168168
e.span,
169-
"useless conversion to the same type",
169+
&format!("useless conversion to the same type: `{}`", b),
170170
&sugg_msg,
171171
sugg.to_string(),
172172
Applicability::MachineApplicable, // snippet

tests/ui/useless_conversion.stderr

Lines changed: 11 additions & 11 deletions
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: `T`
22
--> $DIR/useless_conversion.rs:6:13
33
|
44
LL | let _ = T::from(val);
@@ -10,61 +10,61 @@ 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: `T`
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: `i32`
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: `std::string::String`
2626
--> $DIR/useless_conversion.rs:60: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: `std::string::String`
3232
--> $DIR/useless_conversion.rs:61: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: `std::string::String`
3838
--> $DIR/useless_conversion.rs:62: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: `std::string::String`
4444
--> $DIR/useless_conversion.rs:63: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: `std::str::Lines`
5050
--> $DIR/useless_conversion.rs:64: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: `std::vec::IntoIter<i32>`
5656
--> $DIR/useless_conversion.rs:65: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: `std::string::String`
6262
--> $DIR/useless_conversion.rs:66:21
6363
|
6464
LL | let _: String = format!("Hello {}", "world").into();
6565
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `format!("Hello {}", "world")`
6666

67-
error: useless conversion to the same type
67+
error: useless conversion to the same type: `i32`
6868
--> $DIR/useless_conversion.rs:71:13
6969
|
7070
LL | let _ = i32::from(a + b) * 3;

tests/ui/useless_conversion_try.stderr

Lines changed: 9 additions & 9 deletions
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: `T`
22
--> $DIR/useless_conversion_try.rs:6:13
33
|
44
LL | let _ = T::try_from(val).unwrap();
@@ -11,63 +11,63 @@ 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: `T`
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: `std::string::String`
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: `std::string::String`
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: `std::string::String`
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: `std::string::String`
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: `std::string::String`
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: useless conversion to the same type
62+
error: useless conversion to the same type: `std::string::String`
6363
--> $DIR/useless_conversion_try.rs:34:21
6464
|
6565
LL | let _: String = "".to_owned().try_into().unwrap();
6666
| ^^^^^^^^^^^^^^^^^^^^^^^^
6767
|
6868
= help: consider removing `.try_into()`
6969

70-
error: useless conversion to the same type
70+
error: useless conversion to the same type: `std::string::String`
7171
--> $DIR/useless_conversion_try.rs:35:27
7272
|
7373
LL | let _: String = match String::from("_").try_into() {

0 commit comments

Comments
 (0)