Auto merge of #8737 - smoelius:extra-impl-lifetimes, r=giraffate

Extend `extra_unused_lifetimes` to handle impl lifetimes

Fixes #6437 (cc: `@carols10cents)`

changelog: fix #6437
This commit is contained in:
bors 2022-04-26 00:06:53 +00:00
commit 94623ee882
7 changed files with 124 additions and 12 deletions

View file

@ -1,4 +1,4 @@
#[allow(dead_code)]
#![allow(dead_code, clippy::extra_unused_lifetimes)]
/// Test for https://github.com/rust-lang/rust-clippy/issues/2865

View file

@ -1,4 +1,4 @@
/// Test for https://github.com/rust-lang/rust-clippy/issues/2865
/// Test for https://github.com/rust-lang/rust-clippy/issues/3151
#[derive(Clone)]
pub struct HashMap<V, S> {

View file

@ -72,4 +72,46 @@ mod issue4291 {
}
}
mod issue6437 {
pub struct Scalar;
impl<'a> std::ops::AddAssign<&Scalar> for &mut Scalar {
fn add_assign(&mut self, _rhs: &Scalar) {
unimplemented!();
}
}
impl<'b> Scalar {
pub fn something<'c>() -> Self {
Self
}
}
}
// https://github.com/rust-lang/rust-clippy/pull/8737#pullrequestreview-951268213
mod first_case {
use serde::de::Visitor;
pub trait Expected {
fn fmt(&self, formatter: &mut std::fmt::Formatter);
}
impl<'de, T> Expected for T
where
T: Visitor<'de>,
{
fn fmt(&self, formatter: &mut std::fmt::Formatter) {}
}
}
// https://github.com/rust-lang/rust-clippy/pull/8737#pullrequestreview-951268213
mod second_case {
pub trait Source {
fn hey();
}
impl<'a, T: Source + ?Sized + 'a> Source for Box<T> {
fn hey() {}
}
}
fn main() {}

View file

@ -24,5 +24,23 @@ error: this lifetime isn't used in the function definition
LL | fn unused_lt<'a>(x: u8) {}
| ^^
error: aborting due to 4 previous errors
error: this lifetime isn't used in the impl
--> $DIR/extra_unused_lifetimes.rs:78:10
|
LL | impl<'a> std::ops::AddAssign<&Scalar> for &mut Scalar {
| ^^
error: this lifetime isn't used in the impl
--> $DIR/extra_unused_lifetimes.rs:84:10
|
LL | impl<'b> Scalar {
| ^^
error: this lifetime isn't used in the function definition
--> $DIR/extra_unused_lifetimes.rs:85:26
|
LL | pub fn something<'c>() -> Self {
| ^^
error: aborting due to 7 previous errors

View file

@ -1,4 +1,4 @@
#![allow(dead_code)]
#![allow(dead_code, clippy::extra_unused_lifetimes)]
#![warn(clippy::multiple_inherent_impl)]
struct MyStruct;

View file

@ -1,4 +1,4 @@
#![allow(dead_code, clippy::missing_safety_doc)]
#![allow(dead_code, clippy::missing_safety_doc, clippy::extra_unused_lifetimes)]
#![warn(clippy::new_without_default)]
pub struct Foo;