diff options
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/wfcheck.rs | 11 | ||||
| -rw-r--r-- | tests/ui/regions/transitively-redundant-lifetimes.rs | 3 | ||||
| -rw-r--r-- | tests/ui/regions/transitively-redundant-lifetimes.stderr | 10 |
3 files changed, 18 insertions, 6 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index cc7c41cb387..01f87ecdebb 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -2028,19 +2028,20 @@ fn lint_redundant_lifetimes<'tcx>( | DefKind::TraitAlias | DefKind::Fn | DefKind::Const - | DefKind::Impl { of_trait: false } => { + | DefKind::Impl { of_trait: _ } => { // Proceed } DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst => { let parent_def_id = tcx.local_parent(owner_id); if matches!(tcx.def_kind(parent_def_id), DefKind::Impl { of_trait: true }) { - // Don't check for redundant lifetimes for trait implementations, - // since the signature is required to be compatible with the trait. + // Don't check for redundant lifetimes for associated items of trait + // implementations, since the signature is required to be compatible + // with the trait, even if the implementation implies some lifetimes + // are redundant. return; } } - DefKind::Impl { of_trait: true } - | DefKind::Mod + DefKind::Mod | DefKind::Variant | DefKind::TyAlias | DefKind::ForeignTy diff --git a/tests/ui/regions/transitively-redundant-lifetimes.rs b/tests/ui/regions/transitively-redundant-lifetimes.rs index af1195fe94f..9d375550de3 100644 --- a/tests/ui/regions/transitively-redundant-lifetimes.rs +++ b/tests/ui/regions/transitively-redundant-lifetimes.rs @@ -15,4 +15,7 @@ impl<'a> Bar<'a> { fn ok(x: &'static &()) {} +trait Tr<'a> {} +impl<'a: 'static> Tr<'a> for () {} //~ ERROR unnecessary lifetime parameter `'a` + fn main() {} diff --git a/tests/ui/regions/transitively-redundant-lifetimes.stderr b/tests/ui/regions/transitively-redundant-lifetimes.stderr index 22a27115f7a..a35942ca980 100644 --- a/tests/ui/regions/transitively-redundant-lifetimes.stderr +++ b/tests/ui/regions/transitively-redundant-lifetimes.stderr @@ -27,6 +27,14 @@ 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 + | +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 | @@ -35,5 +43,5 @@ LL | fn d<'b: 'a>(&'b self) {} | = note: you can use the `'a` lifetime directly, in place of `'b` -error: aborting due to 4 previous errors +error: aborting due to 5 previous errors |
