]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/extra_unused_lifetimes.rs
`assertions_on_result_states` fix suggestion when `assert!` not in a statement
[rust.git] / tests / ui / extra_unused_lifetimes.rs
index 66f6e67a75c2916831cb53657b3b628e659e6d82..d6631e01290009feee27ded294e324031b763be7 100644 (file)
@@ -1,12 +1,17 @@
+// aux-build:proc_macro_derive.rs
+
 #![allow(
     unused,
     dead_code,
     clippy::needless_lifetimes,
     clippy::needless_pass_by_value,
-    clippy::trivially_copy_pass_by_ref
+    clippy::needless_arbitrary_self_type
 )]
 #![warn(clippy::extra_unused_lifetimes)]
 
+#[macro_use]
+extern crate proc_macro_derive;
+
 fn empty() {}
 
 fn used_lt<'a>(x: &'a u8) {}
@@ -63,21 +68,62 @@ fn explicit_self_with_lifetime<'a>(self: &'a Self) {}
 
 // Methods implementing traits must have matching lifetimes
 mod issue4291 {
-    #[derive(Debug)]
-    pub struct Foo<'a>(&'a std::marker::PhantomData<u8>);
+    trait BadTrait {
+        fn unused_lt<'a>(x: u8) {}
+    }
 
-    #[derive(Debug)]
-    pub struct Bar<'a: 'b, 'b>(Foo<'a>, &'b std::marker::PhantomData<u8>);
+    impl BadTrait for () {
+        fn unused_lt<'a>(_x: u8) {}
+    }
+}
 
-    trait LT {
-        fn test<'a: 'b, 'b>(foo: &Foo<'a>, bar: &Bar<'a, 'b>);
+mod issue6437 {
+    pub struct Scalar;
+
+    impl<'a> std::ops::AddAssign<&Scalar> for &mut Scalar {
+        fn add_assign(&mut self, _rhs: &Scalar) {
+            unimplemented!();
+        }
     }
 
-    pub struct Baz;
+    impl<'b> Scalar {
+        pub fn something<'c>() -> Self {
+            Self
+        }
+    }
+}
 
-    impl LT for Baz {
-        fn test<'a: 'b, 'b>(_foo: &Foo, _bar: &Bar) {}
+// 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() {}
+    }
+}
+
+// Should not lint
+#[derive(ExtraLifetimeDerive)]
+struct Human<'a> {
+    pub bones: i32,
+    pub name: &'a str,
 }
 
 fn main() {}