From 5114050839ba288cbd1af44ac0261c50c8239493 Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Fri, 9 Aug 2019 07:50:25 +0200 Subject: [PATCH 1/5] Update lint deprecation for tool lints Our lint deprecation previously didn't work for tool lints, because `register_removed` was registering lints to be removed _without_ the `clippy` prefix. --- clippy_dev/src/lib.rs | 6 +++--- clippy_lints/src/lib.rs | 22 +++++++++++----------- tests/ui/deprecated.rs | 11 ++++++----- tests/ui/deprecated.stderr | 36 ++++++++++++++++++------------------ 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index 392388ffd..db407565b 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -126,7 +126,7 @@ pub fn gen_deprecated(lints: &[Lint]) -> Vec { l.clone().deprecation.and_then(|depr_text| { Some(vec![ " store.register_removed(".to_string(), - format!(" \"{}\",", l.name), + format!(" \"clippy::{}\",", l.name), format!(" \"{}\",", depr_text), " );".to_string(), ]) @@ -442,11 +442,11 @@ fn test_gen_deprecated() { ]; let expected: Vec = vec![ " store.register_removed(", - " \"should_assert_eq\",", + " \"clippy::should_assert_eq\",", " \"has been superseded by should_assert_eq2\",", " );", " store.register_removed(", - " \"another_deprecated\",", + " \"clippy::another_deprecated\",", " \"will be removed\",", " );", ] diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 1ab943c59..784a10882 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -386,47 +386,47 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { let mut store = reg.sess.lint_store.borrow_mut(); // begin deprecated lints, do not remove this comment, it’s used in `update_lints` store.register_removed( - "should_assert_eq", + "clippy::should_assert_eq", "`assert!()` will be more flexible with RFC 2011", ); store.register_removed( - "extend_from_slice", + "clippy::extend_from_slice", "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice", ); store.register_removed( - "range_step_by_zero", + "clippy::range_step_by_zero", "`iterator.step_by(0)` panics nowadays", ); store.register_removed( - "unstable_as_slice", + "clippy::unstable_as_slice", "`Vec::as_slice` has been stabilized in 1.7", ); store.register_removed( - "unstable_as_mut_slice", + "clippy::unstable_as_mut_slice", "`Vec::as_mut_slice` has been stabilized in 1.7", ); store.register_removed( - "str_to_string", + "clippy::str_to_string", "using `str::to_string` is common even today and specialization will likely happen soon", ); store.register_removed( - "string_to_string", + "clippy::string_to_string", "using `string::to_string` is common even today and specialization will likely happen soon", ); store.register_removed( - "misaligned_transmute", + "clippy::misaligned_transmute", "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr", ); store.register_removed( - "assign_ops", + "clippy::assign_ops", "using compound assignment operators (e.g., `+=`) is harmless", ); store.register_removed( - "if_let_redundant_pattern_matching", + "clippy::if_let_redundant_pattern_matching", "this lint has been changed to redundant_pattern_matching", ); store.register_removed( - "unsafe_vector_initialization", + "clippy::unsafe_vector_initialization", "the replacement suggested by this lint had substantially different behavior", ); // end deprecated lints, do not remove this comment, it’s used in `update_lints` diff --git a/tests/ui/deprecated.rs b/tests/ui/deprecated.rs index 2e5c5b7ea..7ad330cb3 100644 --- a/tests/ui/deprecated.rs +++ b/tests/ui/deprecated.rs @@ -1,7 +1,8 @@ -#[warn(str_to_string)] -#[warn(string_to_string)] -#[warn(unstable_as_slice)] -#[warn(unstable_as_mut_slice)] -#[warn(misaligned_transmute)] +#[warn(clippy::str_to_string)] +#[warn(clippy::string_to_string)] +#[warn(clippy::unstable_as_slice)] +#[warn(clippy::unstable_as_mut_slice)] +#[warn(clippy::misaligned_transmute)] +#[warn(clippy::unused_collect)] fn main() {} diff --git a/tests/ui/deprecated.stderr b/tests/ui/deprecated.stderr index ea809472c..df9793a09 100644 --- a/tests/ui/deprecated.stderr +++ b/tests/ui/deprecated.stderr @@ -1,40 +1,40 @@ -error: lint `str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon` +error: lint `clippy::str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon` --> $DIR/deprecated.rs:1:8 | -LL | #[warn(str_to_string)] - | ^^^^^^^^^^^^^ +LL | #[warn(clippy::str_to_string)] + | ^^^^^^^^^^^^^^^^^^^^^ | = note: `-D renamed-and-removed-lints` implied by `-D warnings` -error: lint `string_to_string` has been removed: `using `string::to_string` is common even today and specialization will likely happen soon` +error: lint `clippy::string_to_string` has been removed: `using `string::to_string` is common even today and specialization will likely happen soon` --> $DIR/deprecated.rs:2:8 | -LL | #[warn(string_to_string)] - | ^^^^^^^^^^^^^^^^ +LL | #[warn(clippy::string_to_string)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` +error: lint `clippy::unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` --> $DIR/deprecated.rs:3:8 | -LL | #[warn(unstable_as_slice)] - | ^^^^^^^^^^^^^^^^^ +LL | #[warn(clippy::unstable_as_slice)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `unstable_as_mut_slice` has been removed: ``Vec::as_mut_slice` has been stabilized in 1.7` +error: lint `clippy::unstable_as_mut_slice` has been removed: ``Vec::as_mut_slice` has been stabilized in 1.7` --> $DIR/deprecated.rs:4:8 | -LL | #[warn(unstable_as_mut_slice)] - | ^^^^^^^^^^^^^^^^^^^^^ +LL | #[warn(clippy::unstable_as_mut_slice)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `misaligned_transmute` has been removed: `this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr` +error: lint `clippy::misaligned_transmute` has been removed: `this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr` --> $DIR/deprecated.rs:5:8 | -LL | #[warn(misaligned_transmute)] - | ^^^^^^^^^^^^^^^^^^^^ +LL | #[warn(clippy::misaligned_transmute)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: lint `str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon` +error: lint `clippy::str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon` --> $DIR/deprecated.rs:1:8 | -LL | #[warn(str_to_string)] - | ^^^^^^^^^^^^^ +LL | #[warn(clippy::str_to_string)] + | ^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 6 previous errors From 0b7e2376c82b901ff151d5755d17ffed59896380 Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Mon, 12 Aug 2019 07:28:07 +0200 Subject: [PATCH 2/5] Keep old deprecated lints deprecated as non-tool, too --- clippy_lints/src/lib.rs | 50 +++++++++++++++++++++++++++++++++++++++++ tests/ui/deprecated.rs | 12 +++++----- 2 files changed, 56 insertions(+), 6 deletions(-) diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 784a10882..0ac0a5304 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -384,6 +384,8 @@ pub fn read_conf(reg: &rustc_plugin::Registry<'_>) -> Conf { #[rustfmt::skip] pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { let mut store = reg.sess.lint_store.borrow_mut(); + register_removed_non_tool_lints(&mut store); + // begin deprecated lints, do not remove this comment, it’s used in `update_lints` store.register_removed( "clippy::should_assert_eq", @@ -1164,6 +1166,54 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { ]); } +#[rustfmt::skip] +fn register_removed_non_tool_lints(store: &mut rustc::lint::LintStore) { + store.register_removed( + "should_assert_eq", + "`assert!()` will be more flexible with RFC 2011", + ); + store.register_removed( + "extend_from_slice", + "`.extend_from_slice(_)` is a faster way to extend a Vec by a slice", + ); + store.register_removed( + "range_step_by_zero", + "`iterator.step_by(0)` panics nowadays", + ); + store.register_removed( + "unstable_as_slice", + "`Vec::as_slice` has been stabilized in 1.7", + ); + store.register_removed( + "unstable_as_mut_slice", + "`Vec::as_mut_slice` has been stabilized in 1.7", + ); + store.register_removed( + "str_to_string", + "using `str::to_string` is common even today and specialization will likely happen soon", + ); + store.register_removed( + "string_to_string", + "using `string::to_string` is common even today and specialization will likely happen soon", + ); + store.register_removed( + "misaligned_transmute", + "this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr", + ); + store.register_removed( + "assign_ops", + "using compound assignment operators (e.g., `+=`) is harmless", + ); + store.register_removed( + "if_let_redundant_pattern_matching", + "this lint has been changed to redundant_pattern_matching", + ); + store.register_removed( + "unsafe_vector_initialization", + "the replacement suggested by this lint had substantially different behavior", + ); +} + /// Register renamed lints. /// /// Used in `./src/driver.rs`. diff --git a/tests/ui/deprecated.rs b/tests/ui/deprecated.rs index 7ad330cb3..cd6a3a5bf 100644 --- a/tests/ui/deprecated.rs +++ b/tests/ui/deprecated.rs @@ -1,8 +1,8 @@ -#[warn(clippy::str_to_string)] -#[warn(clippy::string_to_string)] -#[warn(clippy::unstable_as_slice)] -#[warn(clippy::unstable_as_mut_slice)] -#[warn(clippy::misaligned_transmute)] -#[warn(clippy::unused_collect)] +#[warn(str_to_string)] +#[warn(string_to_string)] +#[warn(unstable_as_slice)] +#[warn(unstable_as_mut_slice)] +#[warn(misaligned_transmute)] +#[warn(unused_collect)] fn main() {} From b50c13c578b5d2cd1fdd14ddd8e594f1f1574316 Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Mon, 12 Aug 2019 07:27:01 +0200 Subject: [PATCH 3/5] Fix invalid_ref deprecation --- CHANGELOG.md | 1 + clippy_lints/src/deprecated_lints.rs | 2 +- clippy_lints/src/lib.rs | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db838a3e2..e4a1a602c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -982,6 +982,7 @@ Released 2018-09-13 [`integer_division`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_division [`into_iter_on_array`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_array [`into_iter_on_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref +[`invalid_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_ref [`invalid_regex`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_regex [`invalid_upcast_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_upcast_comparisons [`items_after_statements`]: https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements diff --git a/clippy_lints/src/deprecated_lints.rs b/clippy_lints/src/deprecated_lints.rs index 0140cf861..4a6011042 100644 --- a/clippy_lints/src/deprecated_lints.rs +++ b/clippy_lints/src/deprecated_lints.rs @@ -118,7 +118,7 @@ declare_deprecated_lint! { /// /// **Deprecation reason:** This lint has been superseded by the warn-by-default /// `invalid_value` rustc lint. -declare_clippy_lint! { +declare_deprecated_lint! { pub INVALID_REF, "superseded by rustc lint `invalid_value`" } diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 0ac0a5304..7cf4cb8b4 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -431,6 +431,10 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { "clippy::unsafe_vector_initialization", "the replacement suggested by this lint had substantially different behavior", ); + store.register_removed( + "clippy::invalid_ref", + "superseded by rustc lint `invalid_value`", + ); // end deprecated lints, do not remove this comment, it’s used in `update_lints` reg.register_late_lint_pass(box serde_api::SerdeAPI); From 0d0db5ed5f57603c029c7866926daac58d29b35f Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Mon, 12 Aug 2019 19:26:16 +0200 Subject: [PATCH 4/5] Move old lint deprecation tests to deprecated_old.rs --- tests/ui/deprecated.stderr | 40 ---------------- tests/ui/{deprecated.rs => deprecated_old.rs} | 0 tests/ui/deprecated_old.stderr | 46 +++++++++++++++++++ 3 files changed, 46 insertions(+), 40 deletions(-) delete mode 100644 tests/ui/deprecated.stderr rename tests/ui/{deprecated.rs => deprecated_old.rs} (100%) create mode 100644 tests/ui/deprecated_old.stderr diff --git a/tests/ui/deprecated.stderr b/tests/ui/deprecated.stderr deleted file mode 100644 index df9793a09..000000000 --- a/tests/ui/deprecated.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error: lint `clippy::str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon` - --> $DIR/deprecated.rs:1:8 - | -LL | #[warn(clippy::str_to_string)] - | ^^^^^^^^^^^^^^^^^^^^^ - | - = note: `-D renamed-and-removed-lints` implied by `-D warnings` - -error: lint `clippy::string_to_string` has been removed: `using `string::to_string` is common even today and specialization will likely happen soon` - --> $DIR/deprecated.rs:2:8 - | -LL | #[warn(clippy::string_to_string)] - | ^^^^^^^^^^^^^^^^^^^^^^^^ - -error: lint `clippy::unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` - --> $DIR/deprecated.rs:3:8 - | -LL | #[warn(clippy::unstable_as_slice)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: lint `clippy::unstable_as_mut_slice` has been removed: ``Vec::as_mut_slice` has been stabilized in 1.7` - --> $DIR/deprecated.rs:4:8 - | -LL | #[warn(clippy::unstable_as_mut_slice)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: lint `clippy::misaligned_transmute` has been removed: `this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr` - --> $DIR/deprecated.rs:5:8 - | -LL | #[warn(clippy::misaligned_transmute)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: lint `clippy::str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon` - --> $DIR/deprecated.rs:1:8 - | -LL | #[warn(clippy::str_to_string)] - | ^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 6 previous errors - diff --git a/tests/ui/deprecated.rs b/tests/ui/deprecated_old.rs similarity index 100% rename from tests/ui/deprecated.rs rename to tests/ui/deprecated_old.rs diff --git a/tests/ui/deprecated_old.stderr b/tests/ui/deprecated_old.stderr new file mode 100644 index 000000000..8c879fa97 --- /dev/null +++ b/tests/ui/deprecated_old.stderr @@ -0,0 +1,46 @@ +error: lint `str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon` + --> $DIR/deprecated_old.rs:1:8 + | +LL | #[warn(str_to_string)] + | ^^^^^^^^^^^^^ + | + = note: `-D renamed-and-removed-lints` implied by `-D warnings` + +error: lint `string_to_string` has been removed: `using `string::to_string` is common even today and specialization will likely happen soon` + --> $DIR/deprecated_old.rs:2:8 + | +LL | #[warn(string_to_string)] + | ^^^^^^^^^^^^^^^^ + +error: lint `unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` + --> $DIR/deprecated_old.rs:3:8 + | +LL | #[warn(unstable_as_slice)] + | ^^^^^^^^^^^^^^^^^ + +error: lint `unstable_as_mut_slice` has been removed: ``Vec::as_mut_slice` has been stabilized in 1.7` + --> $DIR/deprecated_old.rs:4:8 + | +LL | #[warn(unstable_as_mut_slice)] + | ^^^^^^^^^^^^^^^^^^^^^ + +error: lint `misaligned_transmute` has been removed: `this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr` + --> $DIR/deprecated_old.rs:5:8 + | +LL | #[warn(misaligned_transmute)] + | ^^^^^^^^^^^^^^^^^^^^ + +error: lint name `unused_collect` is deprecated and may not have an effect in the future. Also `cfg_attr(cargo-clippy)` won't be necessary anymore + --> $DIR/deprecated_old.rs:6:8 + | +LL | #[warn(unused_collect)] + | ^^^^^^^^^^^^^^ help: change it to: `clippy::unused_collect` + +error: lint `str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon` + --> $DIR/deprecated_old.rs:1:8 + | +LL | #[warn(str_to_string)] + | ^^^^^^^^^^^^^ + +error: aborting due to 7 previous errors + From e406ab511766d78fd3b7dcbaf3a35ce28f26d5fe Mon Sep 17 00:00:00 2001 From: Philipp Hansch Date: Mon, 12 Aug 2019 19:30:06 +0200 Subject: [PATCH 5/5] Add deprecation tests for deprecated tool lints --- tests/ui/deprecated.rs | 9 ++++++++ tests/ui/deprecated.stderr | 46 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 tests/ui/deprecated.rs create mode 100644 tests/ui/deprecated.stderr diff --git a/tests/ui/deprecated.rs b/tests/ui/deprecated.rs new file mode 100644 index 000000000..a928d044b --- /dev/null +++ b/tests/ui/deprecated.rs @@ -0,0 +1,9 @@ +#[warn(clippy::str_to_string)] +#[warn(clippy::string_to_string)] +#[warn(clippy::unstable_as_slice)] +#[warn(clippy::unstable_as_mut_slice)] +#[warn(clippy::misaligned_transmute)] +#[warn(clippy::unused_collect)] +#[warn(clippy::invalid_ref)] + +fn main() {} diff --git a/tests/ui/deprecated.stderr b/tests/ui/deprecated.stderr new file mode 100644 index 000000000..fa2cee030 --- /dev/null +++ b/tests/ui/deprecated.stderr @@ -0,0 +1,46 @@ +error: lint `clippy::str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon` + --> $DIR/deprecated.rs:1:8 + | +LL | #[warn(clippy::str_to_string)] + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: `-D renamed-and-removed-lints` implied by `-D warnings` + +error: lint `clippy::string_to_string` has been removed: `using `string::to_string` is common even today and specialization will likely happen soon` + --> $DIR/deprecated.rs:2:8 + | +LL | #[warn(clippy::string_to_string)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: lint `clippy::unstable_as_slice` has been removed: ``Vec::as_slice` has been stabilized in 1.7` + --> $DIR/deprecated.rs:3:8 + | +LL | #[warn(clippy::unstable_as_slice)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: lint `clippy::unstable_as_mut_slice` has been removed: ``Vec::as_mut_slice` has been stabilized in 1.7` + --> $DIR/deprecated.rs:4:8 + | +LL | #[warn(clippy::unstable_as_mut_slice)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: lint `clippy::misaligned_transmute` has been removed: `this lint has been split into cast_ptr_alignment and transmute_ptr_to_ptr` + --> $DIR/deprecated.rs:5:8 + | +LL | #[warn(clippy::misaligned_transmute)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: lint `clippy::invalid_ref` has been removed: `superseded by rustc lint `invalid_value`` + --> $DIR/deprecated.rs:7:8 + | +LL | #[warn(clippy::invalid_ref)] + | ^^^^^^^^^^^^^^^^^^^ + +error: lint `clippy::str_to_string` has been removed: `using `str::to_string` is common even today and specialization will likely happen soon` + --> $DIR/deprecated.rs:1:8 + | +LL | #[warn(clippy::str_to_string)] + | ^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 7 previous errors +