File tree Expand file tree Collapse file tree 3 files changed +18
-6
lines changed
compiler/rustc_hir_analysis/src/check Expand file tree Collapse file tree 3 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -2028,19 +2028,20 @@ fn lint_redundant_lifetimes<'tcx>(
20282028 | DefKind :: TraitAlias
20292029 | DefKind :: Fn
20302030 | DefKind :: Const
2031- | DefKind :: Impl { of_trait : false } => {
2031+ | DefKind :: Impl { of_trait : _ } => {
20322032 // Proceed
20332033 }
20342034 DefKind :: AssocFn | DefKind :: AssocTy | DefKind :: AssocConst => {
20352035 let parent_def_id = tcx. local_parent ( owner_id) ;
20362036 if matches ! ( tcx. def_kind( parent_def_id) , DefKind :: Impl { of_trait: true } ) {
2037- // Don't check for redundant lifetimes for trait implementations,
2038- // since the signature is required to be compatible with the trait.
2037+ // Don't check for redundant lifetimes for associated items of trait
2038+ // implementations, since the signature is required to be compatible
2039+ // with the trait, even if the implementation implies some lifetimes
2040+ // are redundant.
20392041 return ;
20402042 }
20412043 }
2042- DefKind :: Impl { of_trait : true }
2043- | DefKind :: Mod
2044+ DefKind :: Mod
20442045 | DefKind :: Variant
20452046 | DefKind :: TyAlias
20462047 | DefKind :: ForeignTy
Original file line number Diff line number Diff line change @@ -15,4 +15,7 @@ impl<'a> Bar<'a> {
1515
1616fn ok ( x : & ' static & ( ) ) { }
1717
18+ trait Tr < ' a > { }
19+ impl < ' a : ' static > Tr < ' a > for ( ) { } //~ ERROR unnecessary lifetime parameter `'a`
20+
1821fn main ( ) { }
Original file line number Diff line number Diff line change @@ -27,6 +27,14 @@ LL | fn c<'a>(_: Foo<&'a ()>) {}
2727 |
2828 = note: you can use the `'static` lifetime directly, in place of `'a`
2929
30+ error: unnecessary lifetime parameter `'a`
31+ --> $DIR/transitively-redundant-lifetimes.rs:19:6
32+ |
33+ LL | impl<'a: 'static> Tr<'a> for () {}
34+ | ^^
35+ |
36+ = note: you can use the `'static` lifetime directly, in place of `'a`
37+
3038error: unnecessary lifetime parameter `'b`
3139 --> $DIR/transitively-redundant-lifetimes.rs:13:10
3240 |
@@ -35,5 +43,5 @@ LL | fn d<'b: 'a>(&'b self) {}
3543 |
3644 = note: you can use the `'a` lifetime directly, in place of `'b`
3745
38- error: aborting due to 4 previous errors
46+ error: aborting due to 5 previous errors
3947
You can’t perform that action at this time.
0 commit comments