diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f34d24cd470..d40eb9513f4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -881,7 +881,6 @@ All notable changes to this project will be documented in this file. [`cmp_owned`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_owned [`cognitive_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#cognitive_complexity [`collapsible_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if -[`const_static_lifetime`]: https://rust-lang.github.io/rust-clippy/master/index.html#const_static_lifetime [`copy_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#copy_iterator [`crosspointer_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#crosspointer_transmute [`dbg_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#dbg_macro @@ -1068,6 +1067,7 @@ All notable changes to this project will be documented in this file. [`redundant_field_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names [`redundant_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern [`redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching +[`redundant_static_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes [`ref_in_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_in_deref [`regex_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#regex_macro [`replace_consts`]: https://rust-lang.github.io/rust-clippy/master/index.html#replace_consts diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 2bec5cb2d015..cfd6070356d1 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -157,7 +157,6 @@ pub mod cargo_common_metadata; pub mod checked_conversions; pub mod cognitive_complexity; pub mod collapsible_if; -pub mod const_static_lifetime; pub mod copies; pub mod copy_iterator; pub mod dbg_macro; @@ -249,6 +248,7 @@ pub mod ranges; pub mod redundant_clone; pub mod redundant_field_names; pub mod redundant_pattern_matching; +pub mod redundant_static_lifetimes; pub mod reference; pub mod regex; pub mod replace_consts; @@ -553,7 +553,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { reg.register_late_lint_pass(box invalid_ref::InvalidRef); reg.register_late_lint_pass(box identity_conversion::IdentityConversion::default()); reg.register_late_lint_pass(box types::ImplicitHasher); - reg.register_early_lint_pass(box const_static_lifetime::StaticConst); + reg.register_early_lint_pass(box redundant_static_lifetimes::RedundantStaticLifetimes); reg.register_late_lint_pass(box fallible_impl_from::FallibleImplFrom); reg.register_late_lint_pass(box replace_consts::ReplaceConsts); reg.register_late_lint_pass(box types::UnitArg); @@ -686,7 +686,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { bytecount::NAIVE_BYTECOUNT, cognitive_complexity::COGNITIVE_COMPLEXITY, collapsible_if::COLLAPSIBLE_IF, - const_static_lifetime::CONST_STATIC_LIFETIME, copies::IFS_SAME_COND, copies::IF_SAME_THEN_ELSE, derive::DERIVE_HASH_XOR_EQ, @@ -834,6 +833,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { ranges::RANGE_ZIP_WITH_LEN, redundant_field_names::REDUNDANT_FIELD_NAMES, redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING, + redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES, reference::DEREF_ADDROF, reference::REF_IN_DEREF, regex::INVALID_REGEX, @@ -901,7 +901,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { block_in_if_condition::BLOCK_IN_IF_CONDITION_EXPR, block_in_if_condition::BLOCK_IN_IF_CONDITION_STMT, collapsible_if::COLLAPSIBLE_IF, - const_static_lifetime::CONST_STATIC_LIFETIME, enum_variants::ENUM_VARIANT_NAMES, enum_variants::MODULE_INCEPTION, eq_op::OP_REF, @@ -957,6 +956,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) { question_mark::QUESTION_MARK, redundant_field_names::REDUNDANT_FIELD_NAMES, redundant_pattern_matching::REDUNDANT_PATTERN_MATCHING, + redundant_static_lifetimes::REDUNDANT_STATIC_LIFETIMES, regex::REGEX_MACRO, regex::TRIVIAL_REGEX, returns::LET_AND_RETURN, @@ -1153,6 +1153,7 @@ pub fn register_renamed(ls: &mut rustc::lint::LintStore) { ls.register_renamed("clippy::stutter", "clippy::module_name_repetitions"); ls.register_renamed("clippy::new_without_default_derive", "clippy::new_without_default"); ls.register_renamed("clippy::cyclomatic_complexity", "clippy::cognitive_complexity"); + ls.register_renamed("clippy::const_static_lifetime", "clippy::redundant_static_lifetimes"); } // only exists to let the dogfood integration test works. diff --git a/clippy_lints/src/const_static_lifetime.rs b/clippy_lints/src/redundant_static_lifetimes.rs similarity index 54% rename from clippy_lints/src/const_static_lifetime.rs rename to clippy_lints/src/redundant_static_lifetimes.rs index fefd180953f2..bdd48fe86461 100644 --- a/clippy_lints/src/const_static_lifetime.rs +++ b/clippy_lints/src/redundant_static_lifetimes.rs @@ -5,7 +5,7 @@ use rustc_errors::Applicability; use syntax::ast::*; declare_clippy_lint! { - /// **What it does:** Checks for constants with an explicit `'static` lifetime. + /// **What it does:** Checks for constants and statics with an explicit `'static` lifetime. /// /// **Why is this bad?** Adding `'static` to every reference can create very /// complicated types. @@ -16,29 +16,32 @@ declare_clippy_lint! { /// ```ignore /// const FOO: &'static [(&'static str, &'static str, fn(&Bar) -> bool)] = /// &[...] + /// static FOO: &'static [(&'static str, &'static str, fn(&Bar) -> bool)] = + /// &[...] /// ``` /// This code can be rewritten as /// ```ignore /// const FOO: &[(&str, &str, fn(&Bar) -> bool)] = &[...] + /// static FOO: &[(&str, &str, fn(&Bar) -> bool)] = &[...] /// ``` - pub CONST_STATIC_LIFETIME, + pub REDUNDANT_STATIC_LIFETIMES, style, - "Using explicit `'static` lifetime for constants when elision rules would allow omitting them." + "Using explicit `'static` lifetime for constants or statics when elision rules would allow omitting them." } -declare_lint_pass!(StaticConst => [CONST_STATIC_LIFETIME]); +declare_lint_pass!(RedundantStaticLifetimes => [REDUNDANT_STATIC_LIFETIMES]); -impl StaticConst { +impl RedundantStaticLifetimes { // Recursively visit types - fn visit_type(&mut self, ty: &Ty, cx: &EarlyContext<'_>) { + fn visit_type(&mut self, ty: &Ty, cx: &EarlyContext<'_>, reason: &str) { match ty.node { // Be careful of nested structures (arrays and tuples) TyKind::Array(ref ty, _) => { - self.visit_type(&*ty, cx); + self.visit_type(&*ty, cx, reason); }, TyKind::Tup(ref tup) => { for tup_ty in tup { - self.visit_type(&*tup_ty, cx); + self.visit_type(&*tup_ty, cx, reason); } }, // This is what we are looking for ! @@ -50,44 +53,40 @@ impl StaticConst { if lifetime.ident.name == syntax::symbol::kw::StaticLifetime { let snip = snippet(cx, borrow_type.ty.span, ""); let sugg = format!("&{}", snip); - span_lint_and_then( - cx, - CONST_STATIC_LIFETIME, - lifetime.ident.span, - "Constants have by default a `'static` lifetime", - |db| { - db.span_suggestion( - ty.span, - "consider removing `'static`", - sugg, - Applicability::MachineApplicable, //snippet - ); - }, - ); + span_lint_and_then(cx, REDUNDANT_STATIC_LIFETIMES, lifetime.ident.span, reason, |db| { + db.span_suggestion( + ty.span, + "consider removing `'static`", + sugg, + Applicability::MachineApplicable, //snippet + ); + }); } }, _ => {}, } } - self.visit_type(&*borrow_type.ty, cx); + self.visit_type(&*borrow_type.ty, cx, reason); }, TyKind::Slice(ref ty) => { - self.visit_type(ty, cx); + self.visit_type(ty, cx, reason); }, _ => {}, } } } -impl EarlyLintPass for StaticConst { +impl EarlyLintPass for RedundantStaticLifetimes { fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { if !in_macro_or_desugar(item.span) { - // Match only constants... if let ItemKind::Const(ref var_type, _) = item.node { - self.visit_type(var_type, cx); + self.visit_type(var_type, cx, "Constants have by default a `'static` lifetime"); + // Don't check associated consts because `'static` cannot be elided on those (issue #2438) + } + + if let ItemKind::Static(ref var_type, _, _) = item.node { + self.visit_type(var_type, cx, "Statics have by default a `'static` lifetime"); } } } - - // Don't check associated consts because `'static` cannot be elided on those (issue #2438) } diff --git a/tests/ui/const_static_lifetime.stderr b/tests/ui/const_static_lifetime.stderr deleted file mode 100644 index c329e860558e..000000000000 --- a/tests/ui/const_static_lifetime.stderr +++ /dev/null @@ -1,82 +0,0 @@ -error: Constants have by default a `'static` lifetime - --> $DIR/const_static_lifetime.rs:4:17 - | -LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removing 'static. - | -^^^^^^^---- help: consider removing `'static`: `&str` - | - = note: `-D clippy::const-static-lifetime` implied by `-D warnings` - -error: Constants have by default a `'static` lifetime - --> $DIR/const_static_lifetime.rs:8:21 - | -LL | const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static - | -^^^^^^^---- help: consider removing `'static`: `&str` - -error: Constants have by default a `'static` lifetime - --> $DIR/const_static_lifetime.rs:10:32 - | -LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static - | -^^^^^^^---- help: consider removing `'static`: `&str` - -error: Constants have by default a `'static` lifetime - --> $DIR/const_static_lifetime.rs:10:47 - | -LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static - | -^^^^^^^---- help: consider removing `'static`: `&str` - -error: Constants have by default a `'static` lifetime - --> $DIR/const_static_lifetime.rs:12:18 - | -LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static - | -^^^^^^^------------------ help: consider removing `'static`: `&[&[&'static str]]` - -error: Constants have by default a `'static` lifetime - --> $DIR/const_static_lifetime.rs:12:30 - | -LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static - | -^^^^^^^---- help: consider removing `'static`: `&str` - -error: Constants have by default a `'static` lifetime - --> $DIR/const_static_lifetime.rs:14:17 - | -LL | const VAR_SIX: &'static u8 = &5; - | -^^^^^^^--- help: consider removing `'static`: `&u8` - -error: Constants have by default a `'static` lifetime - --> $DIR/const_static_lifetime.rs:16:29 - | -LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; - | -^^^^^^^--------------- help: consider removing `'static`: `&[&'static str]` - -error: Constants have by default a `'static` lifetime - --> $DIR/const_static_lifetime.rs:16:39 - | -LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; - | -^^^^^^^---- help: consider removing `'static`: `&str` - -error: Constants have by default a `'static` lifetime - --> $DIR/const_static_lifetime.rs:18:20 - | -LL | const VAR_HEIGHT: &'static Foo = &Foo {}; - | -^^^^^^^---- help: consider removing `'static`: `&Foo` - -error: Constants have by default a `'static` lifetime - --> $DIR/const_static_lifetime.rs:20:19 - | -LL | const VAR_SLICE: &'static [u8] = b"Test constant #1"; // ERROR Consider removing 'static. - | -^^^^^^^----- help: consider removing `'static`: `&[u8]` - -error: Constants have by default a `'static` lifetime - --> $DIR/const_static_lifetime.rs:22:19 - | -LL | const VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static. - | -^^^^^^^--------- help: consider removing `'static`: `&(u8, u8)` - -error: Constants have by default a `'static` lifetime - --> $DIR/const_static_lifetime.rs:24:19 - | -LL | const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static. - | -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]` - -error: aborting due to 13 previous errors - diff --git a/tests/ui/const_static_lifetime.rs b/tests/ui/redundant_static_lifetimes.rs similarity index 59% rename from tests/ui/const_static_lifetime.rs rename to tests/ui/redundant_static_lifetimes.rs index 745821a1503c..fc9f0e066d43 100644 --- a/tests/ui/const_static_lifetime.rs +++ b/tests/ui/redundant_static_lifetimes.rs @@ -23,6 +23,28 @@ const VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static. +static STATIC_VAR_ONE: &'static str = "Test static #1"; // ERROR Consider removing 'static. + +static STATIC_VAR_TWO: &str = "Test static #2"; // This line should not raise a warning. + +static STATIC_VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static + +static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static + +static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static + +static STATIC_VAR_SIX: &'static u8 = &5; + +static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; + +static STATIC_VAR_HEIGHT: &'static Foo = &Foo {}; + +static STATIC_VAR_SLICE: &'static [u8] = b"Test static #3"; // ERROR Consider removing 'static. + +static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static. + +static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static. + fn main() { let false_positive: &'static str = "test"; println!("{}", VAR_ONE); diff --git a/tests/ui/redundant_static_lifetimes.stderr b/tests/ui/redundant_static_lifetimes.stderr new file mode 100644 index 000000000000..da6175d1debc --- /dev/null +++ b/tests/ui/redundant_static_lifetimes.stderr @@ -0,0 +1,160 @@ +error: Constants have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:4:17 + | +LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR Consider removing 'static. + | -^^^^^^^---- help: consider removing `'static`: `&str` + | + = note: `-D clippy::redundant-static-lifetimes` implied by `-D warnings` + +error: Constants have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:8:21 + | +LL | const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static + | -^^^^^^^---- help: consider removing `'static`: `&str` + +error: Constants have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:10:32 + | +LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static + | -^^^^^^^---- help: consider removing `'static`: `&str` + +error: Constants have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:10:47 + | +LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static + | -^^^^^^^---- help: consider removing `'static`: `&str` + +error: Constants have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:12:18 + | +LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static + | -^^^^^^^------------------ help: consider removing `'static`: `&[&[&'static str]]` + +error: Constants have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:12:30 + | +LL | const VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static + | -^^^^^^^---- help: consider removing `'static`: `&str` + +error: Constants have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:14:17 + | +LL | const VAR_SIX: &'static u8 = &5; + | -^^^^^^^--- help: consider removing `'static`: `&u8` + +error: Constants have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:16:29 + | +LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; + | -^^^^^^^--------------- help: consider removing `'static`: `&[&'static str]` + +error: Constants have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:16:39 + | +LL | const VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; + | -^^^^^^^---- help: consider removing `'static`: `&str` + +error: Constants have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:18:20 + | +LL | const VAR_HEIGHT: &'static Foo = &Foo {}; + | -^^^^^^^---- help: consider removing `'static`: `&Foo` + +error: Constants have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:20:19 + | +LL | const VAR_SLICE: &'static [u8] = b"Test constant #1"; // ERROR Consider removing 'static. + | -^^^^^^^----- help: consider removing `'static`: `&[u8]` + +error: Constants have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:22:19 + | +LL | const VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static. + | -^^^^^^^--------- help: consider removing `'static`: `&(u8, u8)` + +error: Constants have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:24:19 + | +LL | const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static. + | -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]` + +error: Statics have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:26:25 + | +LL | static STATIC_VAR_ONE: &'static str = "Test static #1"; // ERROR Consider removing 'static. + | -^^^^^^^---- help: consider removing `'static`: `&str` + +error: Statics have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:30:29 + | +LL | static STATIC_VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR Consider removing 'static + | -^^^^^^^---- help: consider removing `'static`: `&str` + +error: Statics have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:32:40 + | +LL | static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static + | -^^^^^^^---- help: consider removing `'static`: `&str` + +error: Statics have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:32:55 + | +LL | static STATIC_VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR Consider removing 'static + | -^^^^^^^---- help: consider removing `'static`: `&str` + +error: Statics have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:34:26 + | +LL | static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static + | -^^^^^^^------------------ help: consider removing `'static`: `&[&[&'static str]]` + +error: Statics have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:34:38 + | +LL | static STATIC_VAR_FIVE: &'static [&[&'static str]] = &[&["test"], &["other one"]]; // ERROR Consider removing 'static + | -^^^^^^^---- help: consider removing `'static`: `&str` + +error: Statics have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:36:25 + | +LL | static STATIC_VAR_SIX: &'static u8 = &5; + | -^^^^^^^--- help: consider removing `'static`: `&u8` + +error: Statics have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:38:37 + | +LL | static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; + | -^^^^^^^--------------- help: consider removing `'static`: `&[&'static str]` + +error: Statics have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:38:47 + | +LL | static STATIC_VAR_SEVEN: &[&(&str, &'static [&'static str])] = &[&("one", &["other one"])]; + | -^^^^^^^---- help: consider removing `'static`: `&str` + +error: Statics have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:40:28 + | +LL | static STATIC_VAR_HEIGHT: &'static Foo = &Foo {}; + | -^^^^^^^---- help: consider removing `'static`: `&Foo` + +error: Statics have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:42:27 + | +LL | static STATIC_VAR_SLICE: &'static [u8] = b"Test static #3"; // ERROR Consider removing 'static. + | -^^^^^^^----- help: consider removing `'static`: `&[u8]` + +error: Statics have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:44:27 + | +LL | static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR Consider removing 'static. + | -^^^^^^^--------- help: consider removing `'static`: `&(u8, u8)` + +error: Statics have by default a `'static` lifetime + --> $DIR/redundant_static_lifetimes.rs:46:27 + | +LL | static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR Consider removing 'static. + | -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]` + +error: aborting due to 26 previous errors + diff --git a/tests/ui/rename.rs b/tests/ui/rename.rs index b1846a1096cb..f3758174125a 100644 --- a/tests/ui/rename.rs +++ b/tests/ui/rename.rs @@ -1,4 +1,11 @@ -#![allow(stutter)] +//! Test for Clippy lint renames. + +// allow the new lint name here, to test if the new name works +#![allow(clippy::module_name_repetitions)] +#![allow(clippy::new_without_default)] +#![allow(clippy::cognitive_complexity)] +#![allow(clippy::redundant_static_lifetimes)] +// warn for the old lint name here, to test if the renaming worked #![warn(clippy::cyclomatic_complexity)] #[warn(clippy::stutter)] @@ -7,6 +14,9 @@ fn main() {} #[warn(clippy::new_without_default_derive)] struct Foo; +#[warn(clippy::const_static_lifetime)] +static Bar: &'static str = "baz"; + impl Foo { fn new() -> Self { Foo diff --git a/tests/ui/rename.stderr b/tests/ui/rename.stderr index ac850b60d972..0765e6e954a1 100644 --- a/tests/ui/rename.stderr +++ b/tests/ui/rename.stderr @@ -1,13 +1,5 @@ -error: unknown lint: `stutter` - --> $DIR/rename.rs:1:10 - | -LL | #![allow(stutter)] - | ^^^^^^^ - | - = note: `-D unknown-lints` implied by `-D warnings` - error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:2:9 + --> $DIR/rename.rs:9:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` @@ -15,28 +7,28 @@ LL | #![warn(clippy::cyclomatic_complexity)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:4:8 + --> $DIR/rename.rs:11:8 | LL | #[warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:7:8 + --> $DIR/rename.rs:14:8 | LL | #[warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` -error: unknown lint: `stutter` - --> $DIR/rename.rs:1:10 +error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` + --> $DIR/rename.rs:17:8 | -LL | #![allow(stutter)] - | ^^^^^^^ +LL | #[warn(clippy::const_static_lifetime)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:2:9 + --> $DIR/rename.rs:9:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` -error: aborting due to 6 previous errors +error: aborting due to 5 previous errors