Skip to content

Commit db37c1d

Browse files
Split back out unused_lifetimes -> redundant_lifetimes
1 parent 1042f32 commit db37c1d

12 files changed

+52
-26
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+2-2
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

+24-2
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

+1-1
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

+3-3
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

+1-1
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

+2-2
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

+1-1
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

+2-2
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

+1-1
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

+6-1
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

tests/ui/regions/transitively-redundant-lifetimes.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#![allow(unused)]
2-
#![deny(unused_lifetimes)]
1+
#![deny(redundant_lifetimes)]
32

43
fn a<'a, 'b>(x: &'a &'b &'a ()) {} //~ ERROR unnecessary lifetime parameter `'b`
54

tests/ui/regions/transitively-redundant-lifetimes.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
error: unnecessary lifetime parameter `'b`
2-
--> $DIR/transitively-redundant-lifetimes.rs:4:10
2+
--> $DIR/transitively-redundant-lifetimes.rs:3:10
33
|
44
LL | fn a<'a, 'b>(x: &'a &'b &'a ()) {}
55
| ^^
66
|
77
= note: you can use the `'a` lifetime directly, in place of `'b`
88
note: the lint level is defined here
9-
--> $DIR/transitively-redundant-lifetimes.rs:2:9
9+
--> $DIR/transitively-redundant-lifetimes.rs:1:9
1010
|
11-
LL | #![deny(unused_lifetimes)]
12-
| ^^^^^^^^^^^^^^^^
11+
LL | #![deny(redundant_lifetimes)]
12+
| ^^^^^^^^^^^^^^^^^^^
1313

1414
error: unnecessary lifetime parameter `'b`
15-
--> $DIR/transitively-redundant-lifetimes.rs:6:14
15+
--> $DIR/transitively-redundant-lifetimes.rs:5:14
1616
|
1717
LL | fn b<'a: 'b, 'b: 'a>() {}
1818
| ^^
1919
|
2020
= note: you can use the `'a` lifetime directly, in place of `'b`
2121

2222
error: unnecessary lifetime parameter `'a`
23-
--> $DIR/transitively-redundant-lifetimes.rs:9:6
23+
--> $DIR/transitively-redundant-lifetimes.rs:8:6
2424
|
2525
LL | fn c<'a>(_: Foo<&'a ()>) {}
2626
| ^^
2727
|
2828
= note: you can use the `'static` lifetime directly, in place of `'a`
2929

3030
error: unnecessary lifetime parameter `'a`
31-
--> $DIR/transitively-redundant-lifetimes.rs:19:6
31+
--> $DIR/transitively-redundant-lifetimes.rs:18:6
3232
|
3333
LL | impl<'a: 'static> Tr<'a> for () {}
3434
| ^^
3535
|
3636
= note: you can use the `'static` lifetime directly, in place of `'a`
3737

3838
error: unnecessary lifetime parameter `'b`
39-
--> $DIR/transitively-redundant-lifetimes.rs:13:10
39+
--> $DIR/transitively-redundant-lifetimes.rs:12:10
4040
|
4141
LL | fn d<'b: 'a>(&'b self) {}
4242
| ^^

0 commit comments

Comments
 (0)