From a9e262a32dbef558bbe40731ddfe272cb2f11948 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 16 Dec 2023 01:58:26 +0000 Subject: [PATCH] Split back out unused_lifetimes -> redundant_lifetimes --- .../rustc_hir_analysis/src/check/wfcheck.rs | 4 +-- compiler/rustc_lint_defs/src/builtin.rs | 26 +++++++++++++++++-- .../unsatisfied-item-lifetime-bound.rs | 2 +- .../unsatisfied-item-lifetime-bound.stderr | 6 ++--- ...on-outlives-static-outlives-free-region.rs | 2 +- ...utlives-static-outlives-free-region.stderr | 4 +-- .../ui/regions/regions-static-bound-rpass.rs | 2 +- .../regions/regions-static-bound-rpass.stderr | 4 +-- tests/ui/regions/regions-static-bound.rs | 2 +- tests/ui/regions/regions-static-bound.stderr | 7 ++++- .../transitively-redundant-lifetimes.rs | 3 +-- .../transitively-redundant-lifetimes.stderr | 16 ++++++------ 12 files changed, 52 insertions(+), 26 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 01f87ecdebb5e..cc54db18750db 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -2118,8 +2118,8 @@ fn lint_redundant_lifetimes<'tcx>( && outlives_env.free_region_map().sub_free_regions(tcx, victim, candidate) { shadowed.insert(victim); - tcx.emit_spanned_lint( - rustc_lint_defs::builtin::UNUSED_LIFETIMES, + tcx.emit_node_span_lint( + rustc_lint_defs::builtin::REDUNDANT_LIFETIMES, tcx.local_def_id_to_hir_id(def_id.expect_local()), tcx.def_span(def_id), RedundantLifetimeArgsLint { candidate, victim }, diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index c2df3e1015faf..2713690f8120a 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -79,6 +79,7 @@ declare_lint_pass! { PROC_MACRO_BACK_COMPAT, PROC_MACRO_DERIVE_RESOLUTION_FALLBACK, PUB_USE_OF_PRIVATE_EXTERN_CRATE, + REDUNDANT_LIFETIMES, REFINING_IMPL_TRAIT_INTERNAL, REFINING_IMPL_TRAIT_REACHABLE, RENAMED_AND_REMOVED_LINTS, @@ -1694,6 +1695,27 @@ declare_lint! { /// #[deny(unused_lifetimes)] /// /// pub fn foo<'a>() {} + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// Unused lifetime parameters may signal a mistake or unfinished code. + /// Consider removing the parameter. + pub UNUSED_LIFETIMES, + Allow, + "detects lifetime parameters that are never used" +} + +declare_lint! { + /// The `redundant_lifetimes` lint detects lifetime parameters that are + /// redundant because they are equal to another named lifetime. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// #[deny(redundant_lifetimes)] /// /// // `'a = 'static`, so all usages of `'a` can be replaced with `'static` /// pub fn bar<'a: 'static>() {} @@ -1708,9 +1730,9 @@ declare_lint! { /// /// Unused lifetime parameters may signal a mistake or unfinished code. /// Consider removing the parameter. - pub UNUSED_LIFETIMES, + pub REDUNDANT_LIFETIMES, Allow, - "detects lifetime parameters that are never used" + "detects lifetime parameters that are redundant because they are equal to some other named lifetime" } declare_lint! { diff --git a/tests/ui/generic-associated-types/unsatisfied-item-lifetime-bound.rs b/tests/ui/generic-associated-types/unsatisfied-item-lifetime-bound.rs index 381d094d62621..e06341ddf3185 100644 --- a/tests/ui/generic-associated-types/unsatisfied-item-lifetime-bound.rs +++ b/tests/ui/generic-associated-types/unsatisfied-item-lifetime-bound.rs @@ -1,4 +1,4 @@ -#![warn(unused_lifetimes)] +#![warn(unused_lifetimes, redundant_lifetimes)] pub trait X { type Y<'a: 'static>; //~ WARN unnecessary lifetime parameter `'a` diff --git a/tests/ui/generic-associated-types/unsatisfied-item-lifetime-bound.stderr b/tests/ui/generic-associated-types/unsatisfied-item-lifetime-bound.stderr index f1a7511c634b5..4f41ec025fc7f 100644 --- a/tests/ui/generic-associated-types/unsatisfied-item-lifetime-bound.stderr +++ b/tests/ui/generic-associated-types/unsatisfied-item-lifetime-bound.stderr @@ -65,10 +65,10 @@ LL | type Y<'a: 'static>; | = note: you can use the `'static` lifetime directly, in place of `'a` note: the lint level is defined here - --> $DIR/unsatisfied-item-lifetime-bound.rs:1:9 + --> $DIR/unsatisfied-item-lifetime-bound.rs:1:27 | -LL | #![warn(unused_lifetimes)] - | ^^^^^^^^^^^^^^^^ +LL | #![warn(unused_lifetimes, redundant_lifetimes)] + | ^^^^^^^^^^^^^^^^^^^ error: aborting due to 4 previous errors; 1 warning emitted diff --git a/tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.rs b/tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.rs index 5778466f92eff..bef0d70c77659 100644 --- a/tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.rs +++ b/tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.rs @@ -8,7 +8,7 @@ // // 'a : 'b -#![warn(unused_lifetimes)] +#![warn(redundant_lifetimes)] fn test<'a,'b>(x: &'a i32) -> &'b i32 //~ WARN unnecessary lifetime parameter `'a` where 'a: 'static diff --git a/tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.stderr b/tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.stderr index 69f409f436e9e..d97cfd59f2ba4 100644 --- a/tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.stderr +++ b/tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.stderr @@ -8,8 +8,8 @@ LL | fn test<'a,'b>(x: &'a i32) -> &'b i32 note: the lint level is defined here --> $DIR/regions-free-region-outlives-static-outlives-free-region.rs:11:9 | -LL | #![warn(unused_lifetimes)] - | ^^^^^^^^^^^^^^^^ +LL | #![warn(redundant_lifetimes)] + | ^^^^^^^^^^^^^^^^^^^ warning: 1 warning emitted diff --git a/tests/ui/regions/regions-static-bound-rpass.rs b/tests/ui/regions/regions-static-bound-rpass.rs index 028df1ac598d1..f4177f835b15c 100644 --- a/tests/ui/regions/regions-static-bound-rpass.rs +++ b/tests/ui/regions/regions-static-bound-rpass.rs @@ -1,6 +1,6 @@ //@ run-pass -#![warn(unused_lifetimes)] +#![warn(redundant_lifetimes)] fn invariant_id<'a,'b>(t: &'b mut &'static ()) -> &'b mut &'a () //~^ WARN unnecessary lifetime parameter `'a` diff --git a/tests/ui/regions/regions-static-bound-rpass.stderr b/tests/ui/regions/regions-static-bound-rpass.stderr index d197266380a5a..4199ac7bb3d38 100644 --- a/tests/ui/regions/regions-static-bound-rpass.stderr +++ b/tests/ui/regions/regions-static-bound-rpass.stderr @@ -8,8 +8,8 @@ LL | fn invariant_id<'a,'b>(t: &'b mut &'static ()) -> &'b mut &'a () note: the lint level is defined here --> $DIR/regions-static-bound-rpass.rs:3:9 | -LL | #![warn(unused_lifetimes)] - | ^^^^^^^^^^^^^^^^ +LL | #![warn(redundant_lifetimes)] + | ^^^^^^^^^^^^^^^^^^^ warning: unnecessary lifetime parameter `'a` --> $DIR/regions-static-bound-rpass.rs:9:14 diff --git a/tests/ui/regions/regions-static-bound.rs b/tests/ui/regions/regions-static-bound.rs index 3849dfa122f49..32fa2536533cc 100644 --- a/tests/ui/regions/regions-static-bound.rs +++ b/tests/ui/regions/regions-static-bound.rs @@ -1,4 +1,4 @@ -#![warn(unused_lifetimes)] +#![warn(unused_lifetimes, redundant_lifetimes)] fn static_id<'a,'b>(t: &'a ()) -> &'static () where 'a: 'static { t } //~^ WARN unnecessary lifetime parameter `'a` diff --git a/tests/ui/regions/regions-static-bound.stderr b/tests/ui/regions/regions-static-bound.stderr index 4638ca9e35078..48aa8f323291d 100644 --- a/tests/ui/regions/regions-static-bound.stderr +++ b/tests/ui/regions/regions-static-bound.stderr @@ -9,7 +9,7 @@ LL | fn static_id<'a,'b>(t: &'a ()) -> &'static () where 'a: 'static { t } note: the lint level is defined here --> $DIR/regions-static-bound.rs:1:9 | -LL | #![warn(unused_lifetimes)] +LL | #![warn(unused_lifetimes, redundant_lifetimes)] | ^^^^^^^^^^^^^^^^ warning: unnecessary lifetime parameter `'a` @@ -19,6 +19,11 @@ LL | fn static_id<'a,'b>(t: &'a ()) -> &'static () where 'a: 'static { t } | ^^ | = note: you can use the `'static` lifetime directly, in place of `'a` +note: the lint level is defined here + --> $DIR/regions-static-bound.rs:1:27 + | +LL | #![warn(unused_lifetimes, redundant_lifetimes)] + | ^^^^^^^^^^^^^^^^^^^ warning: unnecessary lifetime parameter `'a` --> $DIR/regions-static-bound.rs:7:23 diff --git a/tests/ui/regions/transitively-redundant-lifetimes.rs b/tests/ui/regions/transitively-redundant-lifetimes.rs index 9d375550de3e0..9c29f66e54c5a 100644 --- a/tests/ui/regions/transitively-redundant-lifetimes.rs +++ b/tests/ui/regions/transitively-redundant-lifetimes.rs @@ -1,5 +1,4 @@ -#![allow(unused)] -#![deny(unused_lifetimes)] +#![deny(redundant_lifetimes)] fn a<'a, 'b>(x: &'a &'b &'a ()) {} //~ ERROR unnecessary lifetime parameter `'b` diff --git a/tests/ui/regions/transitively-redundant-lifetimes.stderr b/tests/ui/regions/transitively-redundant-lifetimes.stderr index a35942ca9801b..2d8fc433b241f 100644 --- a/tests/ui/regions/transitively-redundant-lifetimes.stderr +++ b/tests/ui/regions/transitively-redundant-lifetimes.stderr @@ -1,18 +1,18 @@ error: unnecessary lifetime parameter `'b` - --> $DIR/transitively-redundant-lifetimes.rs:4:10 + --> $DIR/transitively-redundant-lifetimes.rs:3:10 | LL | fn a<'a, 'b>(x: &'a &'b &'a ()) {} | ^^ | = note: you can use the `'a` lifetime directly, in place of `'b` note: the lint level is defined here - --> $DIR/transitively-redundant-lifetimes.rs:2:9 + --> $DIR/transitively-redundant-lifetimes.rs:1:9 | -LL | #![deny(unused_lifetimes)] - | ^^^^^^^^^^^^^^^^ +LL | #![deny(redundant_lifetimes)] + | ^^^^^^^^^^^^^^^^^^^ error: unnecessary lifetime parameter `'b` - --> $DIR/transitively-redundant-lifetimes.rs:6:14 + --> $DIR/transitively-redundant-lifetimes.rs:5:14 | LL | fn b<'a: 'b, 'b: 'a>() {} | ^^ @@ -20,7 +20,7 @@ LL | fn b<'a: 'b, 'b: 'a>() {} = note: you can use the `'a` lifetime directly, in place of `'b` error: unnecessary lifetime parameter `'a` - --> $DIR/transitively-redundant-lifetimes.rs:9:6 + --> $DIR/transitively-redundant-lifetimes.rs:8:6 | LL | fn c<'a>(_: Foo<&'a ()>) {} | ^^ @@ -28,7 +28,7 @@ LL | fn c<'a>(_: Foo<&'a ()>) {} = note: you can use the `'static` lifetime directly, in place of `'a` error: unnecessary lifetime parameter `'a` - --> $DIR/transitively-redundant-lifetimes.rs:19:6 + --> $DIR/transitively-redundant-lifetimes.rs:18:6 | LL | impl<'a: 'static> Tr<'a> for () {} | ^^ @@ -36,7 +36,7 @@ LL | impl<'a: 'static> Tr<'a> for () {} = note: you can use the `'static` lifetime directly, in place of `'a` error: unnecessary lifetime parameter `'b` - --> $DIR/transitively-redundant-lifetimes.rs:13:10 + --> $DIR/transitively-redundant-lifetimes.rs:12:10 | LL | fn d<'b: 'a>(&'b self) {} | ^^