Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useless_conversion: show type in error message. #6035

Merged
merged 1 commit into from
Sep 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions clippy_lints/src/useless_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
cx,
USELESS_CONVERSION,
e.span,
"useless conversion to the same type",
&format!("useless conversion to the same type: `{}`", b),
"consider removing `.into()`",
sugg,
Applicability::MachineApplicable, // snippet
Expand All @@ -95,7 +95,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
cx,
USELESS_CONVERSION,
e.span,
"useless conversion to the same type",
&format!("useless conversion to the same type: `{}`", b),
"consider removing `.into_iter()`",
sugg,
Applicability::MachineApplicable, // snippet
Expand All @@ -116,7 +116,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
cx,
USELESS_CONVERSION,
e.span,
"useless conversion to the same type",
&format!("useless conversion to the same type: `{}`", b),
None,
"consider removing `.try_into()`",
);
Expand Down Expand Up @@ -147,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
cx,
USELESS_CONVERSION,
e.span,
"useless conversion to the same type",
&format!("useless conversion to the same type: `{}`", b),
None,
&hint,
);
Expand All @@ -166,7 +166,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
cx,
USELESS_CONVERSION,
e.span,
"useless conversion to the same type",
&format!("useless conversion to the same type: `{}`", b),
&sugg_msg,
sugg.to_string(),
Applicability::MachineApplicable, // snippet
Expand Down
22 changes: 11 additions & 11 deletions tests/ui/useless_conversion.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: useless conversion to the same type
error: useless conversion to the same type: `T`
--> $DIR/useless_conversion.rs:6:13
|
LL | let _ = T::from(val);
Expand All @@ -10,61 +10,61 @@ note: the lint level is defined here
LL | #![deny(clippy::useless_conversion)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: useless conversion to the same type
error: useless conversion to the same type: `T`
--> $DIR/useless_conversion.rs:7:5
|
LL | val.into()
| ^^^^^^^^^^ help: consider removing `.into()`: `val`

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

error: useless conversion to the same type
error: useless conversion to the same type: `std::string::String`
--> $DIR/useless_conversion.rs:60:21
|
LL | let _: String = "foo".to_string().into();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `"foo".to_string()`

error: useless conversion to the same type
error: useless conversion to the same type: `std::string::String`
--> $DIR/useless_conversion.rs:61:21
|
LL | let _: String = From::from("foo".to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `From::from()`: `"foo".to_string()`

error: useless conversion to the same type
error: useless conversion to the same type: `std::string::String`
--> $DIR/useless_conversion.rs:62:13
|
LL | let _ = String::from("foo".to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `"foo".to_string()`

error: useless conversion to the same type
error: useless conversion to the same type: `std::string::String`
--> $DIR/useless_conversion.rs:63:13
|
LL | let _ = String::from(format!("A: {:04}", 123));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `format!("A: {:04}", 123)`

error: useless conversion to the same type
error: useless conversion to the same type: `std::str::Lines`
--> $DIR/useless_conversion.rs:64:13
|
LL | let _ = "".lines().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `"".lines()`

error: useless conversion to the same type
error: useless conversion to the same type: `std::vec::IntoIter<i32>`
--> $DIR/useless_conversion.rs:65:13
|
LL | let _ = vec![1, 2, 3].into_iter().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![1, 2, 3].into_iter()`

error: useless conversion to the same type
error: useless conversion to the same type: `std::string::String`
--> $DIR/useless_conversion.rs:66:21
|
LL | let _: String = format!("Hello {}", "world").into();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `format!("Hello {}", "world")`

error: useless conversion to the same type
error: useless conversion to the same type: `i32`
--> $DIR/useless_conversion.rs:71:13
|
LL | let _ = i32::from(a + b) * 3;
Expand Down
18 changes: 9 additions & 9 deletions tests/ui/useless_conversion_try.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: useless conversion to the same type
error: useless conversion to the same type: `T`
--> $DIR/useless_conversion_try.rs:6:13
|
LL | let _ = T::try_from(val).unwrap();
Expand All @@ -11,63 +11,63 @@ LL | #![deny(clippy::useless_conversion)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: consider removing `T::try_from()`

error: useless conversion to the same type
error: useless conversion to the same type: `T`
--> $DIR/useless_conversion_try.rs:7:5
|
LL | val.try_into().unwrap()
| ^^^^^^^^^^^^^^
|
= help: consider removing `.try_into()`

error: useless conversion to the same type
error: useless conversion to the same type: `std::string::String`
--> $DIR/useless_conversion_try.rs:29:21
|
LL | let _: String = "foo".to_string().try_into().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider removing `.try_into()`

error: useless conversion to the same type
error: useless conversion to the same type: `std::string::String`
--> $DIR/useless_conversion_try.rs:30:21
|
LL | let _: String = TryFrom::try_from("foo".to_string()).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider removing `TryFrom::try_from()`

error: useless conversion to the same type
error: useless conversion to the same type: `std::string::String`
--> $DIR/useless_conversion_try.rs:31:13
|
LL | let _ = String::try_from("foo".to_string()).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider removing `String::try_from()`

error: useless conversion to the same type
error: useless conversion to the same type: `std::string::String`
--> $DIR/useless_conversion_try.rs:32:13
|
LL | let _ = String::try_from(format!("A: {:04}", 123)).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider removing `String::try_from()`

error: useless conversion to the same type
error: useless conversion to the same type: `std::string::String`
--> $DIR/useless_conversion_try.rs:33:21
|
LL | let _: String = format!("Hello {}", "world").try_into().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider removing `.try_into()`

error: useless conversion to the same type
error: useless conversion to the same type: `std::string::String`
--> $DIR/useless_conversion_try.rs:34:21
|
LL | let _: String = "".to_owned().try_into().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider removing `.try_into()`

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