File tree 3 files changed +18
-6
lines changed
compiler/rustc_hir_analysis/src/check
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>(
2028
2028
| DefKind :: TraitAlias
2029
2029
| DefKind :: Fn
2030
2030
| DefKind :: Const
2031
- | DefKind :: Impl { of_trait : false } => {
2031
+ | DefKind :: Impl { of_trait : _ } => {
2032
2032
// Proceed
2033
2033
}
2034
2034
DefKind :: AssocFn | DefKind :: AssocTy | DefKind :: AssocConst => {
2035
2035
let parent_def_id = tcx. local_parent ( owner_id) ;
2036
2036
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.
2039
2041
return ;
2040
2042
}
2041
2043
}
2042
- DefKind :: Impl { of_trait : true }
2043
- | DefKind :: Mod
2044
+ DefKind :: Mod
2044
2045
| DefKind :: Variant
2045
2046
| DefKind :: TyAlias
2046
2047
| DefKind :: ForeignTy
Original file line number Diff line number Diff line change @@ -15,4 +15,7 @@ impl<'a> Bar<'a> {
15
15
16
16
fn ok ( x : & ' static & ( ) ) { }
17
17
18
+ trait Tr < ' a > { }
19
+ impl < ' a : ' static > Tr < ' a > for ( ) { } //~ ERROR unnecessary lifetime parameter `'a`
20
+
18
21
fn main ( ) { }
Original file line number Diff line number Diff line change @@ -27,6 +27,14 @@ LL | fn c<'a>(_: Foo<&'a ()>) {}
27
27
|
28
28
= note: you can use the `'static` lifetime directly, in place of `'a`
29
29
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
+
30
38
error: unnecessary lifetime parameter `'b`
31
39
--> $DIR/transitively-redundant-lifetimes.rs:13:10
32
40
|
@@ -35,5 +43,5 @@ LL | fn d<'b: 'a>(&'b self) {}
35
43
|
36
44
= note: you can use the `'a` lifetime directly, in place of `'b`
37
45
38
- error: aborting due to 4 previous errors
46
+ error: aborting due to 5 previous errors
39
47
You can’t perform that action at this time.
0 commit comments