about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-12-16 01:58:26 +0000
committerMichael Goulet <michael@errs.io>2024-04-09 12:17:34 -0400
commita9e262a32dbef558bbe40731ddfe272cb2f11948 (patch)
tree7b00dc45782530088aa2204d02ae31050fd6130a
parentee78eab62be926b69236c9a344fbcec2b3355bbd (diff)
downloadrust-a9e262a32dbef558bbe40731ddfe272cb2f11948.tar.gz
rust-a9e262a32dbef558bbe40731ddfe272cb2f11948.zip
Split back out unused_lifetimes -> redundant_lifetimes
-rw-r--r--compiler/rustc_hir_analysis/src/check/wfcheck.rs4
-rw-r--r--compiler/rustc_lint_defs/src/builtin.rs26
-rw-r--r--tests/ui/generic-associated-types/unsatisfied-item-lifetime-bound.rs2
-rw-r--r--tests/ui/generic-associated-types/unsatisfied-item-lifetime-bound.stderr6
-rw-r--r--tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.rs2
-rw-r--r--tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.stderr4
-rw-r--r--tests/ui/regions/regions-static-bound-rpass.rs2
-rw-r--r--tests/ui/regions/regions-static-bound-rpass.stderr4
-rw-r--r--tests/ui/regions/regions-static-bound.rs2
-rw-r--r--tests/ui/regions/regions-static-bound.stderr7
-rw-r--r--tests/ui/regions/transitively-redundant-lifetimes.rs3
-rw-r--r--tests/ui/regions/transitively-redundant-lifetimes.stderr16
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 01f87ecdebb..cc54db18750 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 c2df3e1015f..2713690f812 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 381d094d626..e06341ddf31 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 f1a7511c634..4f41ec025fc 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 5778466f92e..bef0d70c776 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 69f409f436e..d97cfd59f2b 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 028df1ac598..f4177f835b1 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 d197266380a..4199ac7bb3d 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 3849dfa122f..32fa2536533 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 4638ca9e350..48aa8f32329 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 9d375550de3..9c29f66e54c 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 a35942ca980..2d8fc433b24 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) {}
    |          ^^