Skip to content

Commit

Permalink
Split back out unused_lifetimes -> redundant_lifetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Apr 9, 2024
1 parent ee78eab commit a9e262a
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 26 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
26 changes: 24 additions & 2 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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>() {}
Expand All @@ -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! {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![warn(unused_lifetimes)]
#![warn(unused_lifetimes, redundant_lifetimes)]

pub trait X {
type Y<'a: 'static>; //~ WARN unnecessary lifetime parameter `'a`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 1 addition & 1 deletion tests/ui/regions/regions-static-bound-rpass.rs
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/regions/regions-static-bound-rpass.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/regions/regions-static-bound.rs
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
7 changes: 6 additions & 1 deletion tests/ui/regions/regions-static-bound.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/ui/regions/transitively-redundant-lifetimes.rs
Original file line number Diff line number Diff line change
@@ -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`

Expand Down
16 changes: 8 additions & 8 deletions tests/ui/regions/transitively-redundant-lifetimes.stderr
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
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>() {}
| ^^
|
= 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 ()>) {}
| ^^
|
= 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 () {}
| ^^
|
= 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) {}
| ^^
Expand Down

0 comments on commit a9e262a

Please sign in to comment.