Skip to content

Commit 86cd17f

Browse files
Split back out unused_lifetimes -> redundant_lifetimes
1 parent c02d726 commit 86cd17f

12 files changed

+52
-26
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,8 +2118,8 @@ fn check_for_redundant_lifetimes<'tcx>(
21182118
&& outlives_env.free_region_map().sub_free_regions(tcx, victim, candidate)
21192119
{
21202120
shadowed.insert(victim);
2121-
tcx.emit_spanned_lint(
2122-
rustc_lint_defs::builtin::UNUSED_LIFETIMES,
2121+
tcx.emit_node_span_lint(
2122+
rustc_lint_defs::builtin::REDUNDANT_LIFETIMES,
21232123
tcx.local_def_id_to_hir_id(def_id.expect_local()),
21242124
tcx.def_span(def_id),
21252125
RedundantLifetimeArgsLint { candidate, victim },

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ declare_lint_pass! {
7979
PROC_MACRO_BACK_COMPAT,
8080
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
8181
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
82+
REDUNDANT_LIFETIMES,
8283
REFINING_IMPL_TRAIT_INTERNAL,
8384
REFINING_IMPL_TRAIT_REACHABLE,
8485
RENAMED_AND_REMOVED_LINTS,
@@ -1694,6 +1695,27 @@ declare_lint! {
16941695
/// #[deny(unused_lifetimes)]
16951696
///
16961697
/// pub fn foo<'a>() {}
1698+
/// ```
1699+
///
1700+
/// {{produces}}
1701+
///
1702+
/// ### Explanation
1703+
///
1704+
/// Unused lifetime parameters may signal a mistake or unfinished code.
1705+
/// Consider removing the parameter.
1706+
pub UNUSED_LIFETIMES,
1707+
Allow,
1708+
"detects lifetime parameters that are never used"
1709+
}
1710+
1711+
declare_lint! {
1712+
/// The `redundant_lifetimes` lint detects lifetime parameters that are never
1713+
/// used, or are redundant because they are equal to another named lifetime.
1714+
///
1715+
/// ### Example
1716+
///
1717+
/// ```rust,compile_fail
1718+
/// #[deny(redundant_lifetimes)]
16971719
///
16981720
/// // `'a = 'static`, so all usages of `'a` can be replaced with `'static`
16991721
/// pub fn bar<'a: 'static>() {}
@@ -1708,9 +1730,9 @@ declare_lint! {
17081730
///
17091731
/// Unused lifetime parameters may signal a mistake or unfinished code.
17101732
/// Consider removing the parameter.
1711-
pub UNUSED_LIFETIMES,
1733+
pub REDUNDANT_LIFETIMES,
17121734
Allow,
1713-
"detects lifetime parameters that are never used"
1735+
"detects lifetime parameters that are redundant because they are equal to some other named lifetime"
17141736
}
17151737

17161738
declare_lint! {

tests/ui/generic-associated-types/unsatisfied-item-lifetime-bound.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![warn(unused_lifetimes)]
1+
#![warn(unused_lifetimes, redundant_lifetimes)]
22

33
pub trait X {
44
type Y<'a: 'static>; //~ WARN unnecessary lifetime parameter `'a`

tests/ui/generic-associated-types/unsatisfied-item-lifetime-bound.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ LL | type Y<'a: 'static>;
6565
|
6666
= note: you can use the `'static` lifetime directly, in place of `'a`
6767
note: the lint level is defined here
68-
--> $DIR/unsatisfied-item-lifetime-bound.rs:1:9
68+
--> $DIR/unsatisfied-item-lifetime-bound.rs:1:27
6969
|
70-
LL | #![warn(unused_lifetimes)]
71-
| ^^^^^^^^^^^^^^^^
70+
LL | #![warn(unused_lifetimes, redundant_lifetimes)]
71+
| ^^^^^^^^^^^^^^^^^^^
7272

7373
error: aborting due to 4 previous errors; 1 warning emitted
7474

tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//
99
// 'a : 'b
1010

11-
#![warn(unused_lifetimes)]
11+
#![warn(redundant_lifetimes)]
1212

1313
fn test<'a,'b>(x: &'a i32) -> &'b i32 //~ WARN unnecessary lifetime parameter `'a`
1414
where 'a: 'static

tests/ui/regions/regions-free-region-outlives-static-outlives-free-region.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ LL | fn test<'a,'b>(x: &'a i32) -> &'b i32
88
note: the lint level is defined here
99
--> $DIR/regions-free-region-outlives-static-outlives-free-region.rs:11:9
1010
|
11-
LL | #![warn(unused_lifetimes)]
12-
| ^^^^^^^^^^^^^^^^
11+
LL | #![warn(redundant_lifetimes)]
12+
| ^^^^^^^^^^^^^^^^^^^
1313

1414
warning: 1 warning emitted
1515

tests/ui/regions/regions-static-bound-rpass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ run-pass
22

3-
#![warn(unused_lifetimes)]
3+
#![warn(redundant_lifetimes)]
44

55
fn invariant_id<'a,'b>(t: &'b mut &'static ()) -> &'b mut &'a ()
66
//~^ WARN unnecessary lifetime parameter `'a`

tests/ui/regions/regions-static-bound-rpass.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ LL | fn invariant_id<'a,'b>(t: &'b mut &'static ()) -> &'b mut &'a ()
88
note: the lint level is defined here
99
--> $DIR/regions-static-bound-rpass.rs:3:9
1010
|
11-
LL | #![warn(unused_lifetimes)]
12-
| ^^^^^^^^^^^^^^^^
11+
LL | #![warn(redundant_lifetimes)]
12+
| ^^^^^^^^^^^^^^^^^^^
1313

1414
warning: unnecessary lifetime parameter `'a`
1515
--> $DIR/regions-static-bound-rpass.rs:9:14

tests/ui/regions/regions-static-bound.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![warn(unused_lifetimes)]
1+
#![warn(unused_lifetimes, redundant_lifetimes)]
22

33
fn static_id<'a,'b>(t: &'a ()) -> &'static () where 'a: 'static { t }
44
//~^ WARN unnecessary lifetime parameter `'a`

tests/ui/regions/regions-static-bound.stderr

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ LL | fn static_id<'a,'b>(t: &'a ()) -> &'static () where 'a: 'static { t }
99
note: the lint level is defined here
1010
--> $DIR/regions-static-bound.rs:1:9
1111
|
12-
LL | #![warn(unused_lifetimes)]
12+
LL | #![warn(unused_lifetimes, redundant_lifetimes)]
1313
| ^^^^^^^^^^^^^^^^
1414

1515
warning: unnecessary lifetime parameter `'a`
@@ -19,6 +19,11 @@ LL | fn static_id<'a,'b>(t: &'a ()) -> &'static () where 'a: 'static { t }
1919
| ^^
2020
|
2121
= note: you can use the `'static` lifetime directly, in place of `'a`
22+
note: the lint level is defined here
23+
--> $DIR/regions-static-bound.rs:1:27
24+
|
25+
LL | #![warn(unused_lifetimes, redundant_lifetimes)]
26+
| ^^^^^^^^^^^^^^^^^^^
2227

2328
warning: unnecessary lifetime parameter `'a`
2429
--> $DIR/regions-static-bound.rs:7:23

0 commit comments

Comments
 (0)