Skip to content

Commit e214ea8

Browse files
committed
Auto merge of rust-lang#5568 - ThibsG:RenameIdentityConversionLint, r=flip1995
Rename lint `identity_conversion` to `useless_conversion` Lint name `identity_conversion` was misleading, so this PR renames it to `useless_conversion`. As decision has not really came up in the issue comments, this PR will probably need discussion. fixes rust-lang#3106 changelog: Rename lint `identity_conversion` to `useless_conversion`
2 parents 6ae0643 + e55b920 commit e214ea8

File tree

7 files changed

+60
-53
lines changed

7 files changed

+60
-53
lines changed

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ Released 2018-09-13
805805

806806
## 0.0.166
807807
* Rustup to *rustc 1.22.0-nightly (b7960878b 2017-10-18)*
808-
* New lints: [`explicit_write`], [`identity_conversion`], [`implicit_hasher`], [`invalid_ref`], [`option_map_or_none`],
808+
* New lints: [`explicit_write`], `identity_conversion`, [`implicit_hasher`], [`invalid_ref`], [`option_map_or_none`],
809809
[`range_minus_one`], [`range_plus_one`], [`transmute_int_to_bool`], [`transmute_int_to_char`],
810810
[`transmute_int_to_float`]
811811

@@ -1368,7 +1368,6 @@ Released 2018-09-13
13681368
[`future_not_send`]: https://rust-lang.github.io/rust-clippy/master/index.html#future_not_send
13691369
[`get_last_with_len`]: https://rust-lang.github.io/rust-clippy/master/index.html#get_last_with_len
13701370
[`get_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#get_unwrap
1371-
[`identity_conversion`]: https://rust-lang.github.io/rust-clippy/master/index.html#identity_conversion
13721371
[`identity_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#identity_op
13731372
[`if_let_mutex`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_let_mutex
13741373
[`if_let_redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_let_redundant_pattern_matching
@@ -1624,6 +1623,7 @@ Released 2018-09-13
16241623
[`used_underscore_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding
16251624
[`useless_asref`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_asref
16261625
[`useless_attribute`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_attribute
1626+
[`useless_conversion`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
16271627
[`useless_format`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_format
16281628
[`useless_let_if_seq`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_let_if_seq
16291629
[`useless_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_transmute

clippy_lints/src/lib.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ mod formatting;
221221
mod functions;
222222
mod future_not_send;
223223
mod get_last_with_len;
224-
mod identity_conversion;
225224
mod identity_op;
226225
mod if_let_mutex;
227226
mod if_let_some_result;
@@ -324,6 +323,7 @@ mod unused_io_amount;
324323
mod unused_self;
325324
mod unwrap;
326325
mod use_self;
326+
mod useless_conversion;
327327
mod vec;
328328
mod verbose_file_reads;
329329
mod wildcard_dependencies;
@@ -577,7 +577,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
577577
&functions::TOO_MANY_LINES,
578578
&future_not_send::FUTURE_NOT_SEND,
579579
&get_last_with_len::GET_LAST_WITH_LEN,
580-
&identity_conversion::IDENTITY_CONVERSION,
581580
&identity_op::IDENTITY_OP,
582581
&if_let_mutex::IF_LET_MUTEX,
583582
&if_let_some_result::IF_LET_SOME_RESULT,
@@ -843,6 +842,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
843842
&unwrap::PANICKING_UNWRAP,
844843
&unwrap::UNNECESSARY_UNWRAP,
845844
&use_self::USE_SELF,
845+
&useless_conversion::USELESS_CONVERSION,
846846
&utils::internal_lints::CLIPPY_LINTS_INTERNAL,
847847
&utils::internal_lints::COLLAPSIBLE_SPAN_LINT_CALLS,
848848
&utils::internal_lints::COMPILER_LINT_FUNCTIONS,
@@ -980,7 +980,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
980980
store.register_late_pass(|| box bytecount::ByteCount);
981981
store.register_late_pass(|| box infinite_iter::InfiniteIter);
982982
store.register_late_pass(|| box inline_fn_without_body::InlineFnWithoutBody);
983-
store.register_late_pass(|| box identity_conversion::IdentityConversion::default());
983+
store.register_late_pass(|| box useless_conversion::UselessConversion::default());
984984
store.register_late_pass(|| box types::ImplicitHasher);
985985
store.register_late_pass(|| box fallible_impl_from::FallibleImplFrom);
986986
store.register_late_pass(|| box types::UnitArg);
@@ -1241,7 +1241,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
12411241
LintId::of(&functions::NOT_UNSAFE_PTR_ARG_DEREF),
12421242
LintId::of(&functions::TOO_MANY_ARGUMENTS),
12431243
LintId::of(&get_last_with_len::GET_LAST_WITH_LEN),
1244-
LintId::of(&identity_conversion::IDENTITY_CONVERSION),
12451244
LintId::of(&identity_op::IDENTITY_OP),
12461245
LintId::of(&if_let_mutex::IF_LET_MUTEX),
12471246
LintId::of(&if_let_some_result::IF_LET_SOME_RESULT),
@@ -1427,6 +1426,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14271426
LintId::of(&unused_io_amount::UNUSED_IO_AMOUNT),
14281427
LintId::of(&unwrap::PANICKING_UNWRAP),
14291428
LintId::of(&unwrap::UNNECESSARY_UNWRAP),
1429+
LintId::of(&useless_conversion::USELESS_CONVERSION),
14301430
LintId::of(&vec::USELESS_VEC),
14311431
LintId::of(&write::PRINTLN_EMPTY_STRING),
14321432
LintId::of(&write::PRINT_LITERAL),
@@ -1546,7 +1546,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
15461546
LintId::of(&format::USELESS_FORMAT),
15471547
LintId::of(&functions::TOO_MANY_ARGUMENTS),
15481548
LintId::of(&get_last_with_len::GET_LAST_WITH_LEN),
1549-
LintId::of(&identity_conversion::IDENTITY_CONVERSION),
15501549
LintId::of(&identity_op::IDENTITY_OP),
15511550
LintId::of(&int_plus_one::INT_PLUS_ONE),
15521551
LintId::of(&lifetimes::EXTRA_UNUSED_LIFETIMES),
@@ -1605,6 +1604,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
16051604
LintId::of(&types::UNNECESSARY_CAST),
16061605
LintId::of(&types::VEC_BOX),
16071606
LintId::of(&unwrap::UNNECESSARY_UNWRAP),
1607+
LintId::of(&useless_conversion::USELESS_CONVERSION),
16081608
LintId::of(&zero_div_zero::ZERO_DIVIDED_BY_ZERO),
16091609
]);
16101610

@@ -1796,6 +1796,7 @@ pub fn register_renamed(ls: &mut rustc_lint::LintStore) {
17961796
ls.register_renamed("clippy::result_expect_used", "clippy::expect_used");
17971797
ls.register_renamed("clippy::for_loop_over_option", "clippy::for_loops_over_fallibles");
17981798
ls.register_renamed("clippy::for_loop_over_result", "clippy::for_loops_over_fallibles");
1799+
ls.register_renamed("clippy::identity_conversion", "clippy::useless_conversion");
17991800
}
18001801

18011802
// only exists to let the dogfood integration test works.

clippy_lints/src/identity_conversion.rs renamed to clippy_lints/src/useless_conversion.rs

+18-12
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,36 @@ use rustc_lint::{LateContext, LateLintPass};
77
use rustc_session::{declare_tool_lint, impl_lint_pass};
88

99
declare_clippy_lint! {
10-
/// **What it does:** Checks for always-identical `Into`/`From`/`IntoIter` conversions.
10+
/// **What it does:** Checks for `Into`/`From`/`IntoIter` calls that useless converts
11+
/// to the same type as caller.
1112
///
1213
/// **Why is this bad?** Redundant code.
1314
///
1415
/// **Known problems:** None.
1516
///
1617
/// **Example:**
18+
///
1719
/// ```rust
20+
/// // Bad
1821
/// // format!() returns a `String`
1922
/// let s: String = format!("hello").into();
23+
///
24+
/// // Good
25+
/// let s: String = format!("hello");
2026
/// ```
21-
pub IDENTITY_CONVERSION,
27+
pub USELESS_CONVERSION,
2228
complexity,
23-
"using always-identical `Into`/`From`/`IntoIter` conversions"
29+
"calls to `Into`/`From`/`IntoIter` that performs useless conversions to the same type"
2430
}
2531

2632
#[derive(Default)]
27-
pub struct IdentityConversion {
33+
pub struct UselessConversion {
2834
try_desugar_arm: Vec<HirId>,
2935
}
3036

31-
impl_lint_pass!(IdentityConversion => [IDENTITY_CONVERSION]);
37+
impl_lint_pass!(UselessConversion => [USELESS_CONVERSION]);
3238

33-
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
39+
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UselessConversion {
3440
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) {
3541
if e.span.from_expansion() {
3642
return;
@@ -60,9 +66,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
6066

6167
span_lint_and_sugg(
6268
cx,
63-
IDENTITY_CONVERSION,
69+
USELESS_CONVERSION,
6470
e.span,
65-
"identical conversion",
71+
"useless conversion",
6672
"consider removing `.into()`",
6773
sugg,
6874
Applicability::MachineApplicable, // snippet
@@ -76,9 +82,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
7682
let sugg = snippet(cx, args[0].span, "<expr>").into_owned();
7783
span_lint_and_sugg(
7884
cx,
79-
IDENTITY_CONVERSION,
85+
USELESS_CONVERSION,
8086
e.span,
81-
"identical conversion",
87+
"useless conversion",
8288
"consider removing `.into_iter()`",
8389
sugg,
8490
Applicability::MachineApplicable, // snippet
@@ -99,9 +105,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IdentityConversion {
99105
format!("consider removing `{}()`", snippet(cx, path.span, "From::from"));
100106
span_lint_and_sugg(
101107
cx,
102-
IDENTITY_CONVERSION,
108+
USELESS_CONVERSION,
103109
e.span,
104-
"identical conversion",
110+
"useless conversion",
105111
&sugg_msg,
106112
sugg,
107113
Applicability::MachineApplicable, // snippet

src/lintlist/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -724,13 +724,6 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
724724
deprecation: None,
725725
module: "methods",
726726
},
727-
Lint {
728-
name: "identity_conversion",
729-
group: "complexity",
730-
desc: "using always-identical `Into`/`From`/`IntoIter` conversions",
731-
deprecation: None,
732-
module: "identity_conversion",
733-
},
734727
Lint {
735728
name: "identity_op",
736729
group: "complexity",
@@ -2418,6 +2411,13 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
24182411
deprecation: None,
24192412
module: "attrs",
24202413
},
2414+
Lint {
2415+
name: "useless_conversion",
2416+
group: "complexity",
2417+
desc: "calls to `Into`/`From`/`IntoIter` that performs useless conversions to the same type",
2418+
deprecation: None,
2419+
module: "useless_conversion",
2420+
},
24212421
Lint {
24222422
name: "useless_format",
24232423
group: "complexity",

tests/ui/identity_conversion.fixed renamed to tests/ui/useless_conversion.fixed

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-rustfix
22

3-
#![deny(clippy::identity_conversion)]
3+
#![deny(clippy::useless_conversion)]
44

55
fn test_generic<T: Copy>(val: T) -> T {
66
let _ = val;
@@ -41,7 +41,7 @@ fn main() {
4141
let _: String = "foo".into();
4242
let _: String = From::from("foo");
4343
let _ = String::from("foo");
44-
#[allow(clippy::identity_conversion)]
44+
#[allow(clippy::useless_conversion)]
4545
{
4646
let _: String = "foo".into();
4747
let _ = String::from("foo");

tests/ui/identity_conversion.rs renamed to tests/ui/useless_conversion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-rustfix
22

3-
#![deny(clippy::identity_conversion)]
3+
#![deny(clippy::useless_conversion)]
44

55
fn test_generic<T: Copy>(val: T) -> T {
66
let _ = T::from(val);
@@ -41,7 +41,7 @@ fn main() {
4141
let _: String = "foo".into();
4242
let _: String = From::from("foo");
4343
let _ = String::from("foo");
44-
#[allow(clippy::identity_conversion)]
44+
#[allow(clippy::useless_conversion)]
4545
{
4646
let _: String = "foo".into();
4747
let _ = String::from("foo");

tests/ui/identity_conversion.stderr renamed to tests/ui/useless_conversion.stderr

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

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

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

25-
error: identical conversion
26-
--> $DIR/identity_conversion.rs:51:21
25+
error: useless conversion
26+
--> $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: identical conversion
32-
--> $DIR/identity_conversion.rs:52:21
31+
error: useless conversion
32+
--> $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: identical conversion
38-
--> $DIR/identity_conversion.rs:53:13
37+
error: useless conversion
38+
--> $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: identical conversion
44-
--> $DIR/identity_conversion.rs:54:13
43+
error: useless conversion
44+
--> $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: identical conversion
50-
--> $DIR/identity_conversion.rs:55:13
49+
error: useless conversion
50+
--> $DIR/useless_conversion.rs:55:13
5151
|
5252
LL | let _ = "".lines().into_iter();
5353
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `"".lines()`
5454

55-
error: identical conversion
56-
--> $DIR/identity_conversion.rs:56:13
55+
error: useless conversion
56+
--> $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: identical conversion
62-
--> $DIR/identity_conversion.rs:57:21
61+
error: useless conversion
62+
--> $DIR/useless_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)