Lint redundant lifetimes in impl header
This commit is contained in:
parent
2d813547bf
commit
ee78eab62b
@ -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
|
||||
|
@ -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() {}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user