mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-13 12:36:47 +00:00
Split back out unused_lifetimes -> redundant_lifetimes
This commit is contained in:
parent
ee78eab62b
commit
a9e262a32d
@ -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 },
|
||||
|
@ -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! {
|
||||
|
@ -1,4 +1,4 @@
|
||||
#![warn(unused_lifetimes)]
|
||||
#![warn(unused_lifetimes, redundant_lifetimes)]
|
||||
|
||||
pub trait X {
|
||||
type Y<'a: 'static>; //~ WARN unnecessary lifetime parameter `'a`
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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`
|
||||
|
@ -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
|
||||
|
@ -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`
|
||||
|
@ -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
|
||||
|
@ -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`
|
||||
|
||||
|
@ -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) {}
|
||||
| ^^
|
||||
|
Loading…
Reference in New Issue
Block a user