]> git.lizzy.rs Git - rust.git/blobdiff - src/tools/clippy/tests/ui/return_self_not_must_use.rs
Merge commit '0eff589afc83e21a03a168497bbab6b4dfbb4ef6' into clippyup
[rust.git] / src / tools / clippy / tests / ui / return_self_not_must_use.rs
index bdf3f3d799582085b2b39a341445074f18e603b2..7dd5742dae9f213d5038af6d0422b6b201342db6 100644 (file)
@@ -5,12 +5,12 @@
 
 pub trait Whatever {
     fn what(&self) -> Self;
-    // There should be no warning here!
+    // There should be no warning here! (returns a reference)
     fn what2(&self) -> &Self;
 }
 
 impl Bar {
-    // There should be no warning here!
+    // There should be no warning here! (note taking a self argument)
     pub fn not_new() -> Self {
         Self
     }
@@ -20,23 +20,38 @@ pub fn foo(&self) -> Self {
     pub fn bar(self) -> Self {
         self
     }
-    // There should be no warning here!
+    // There should be no warning here! (private method)
     fn foo2(&self) -> Self {
         Self
     }
-    // There should be no warning here!
+    // There should be no warning here! (returns a reference)
     pub fn foo3(&self) -> &Self {
         self
     }
+    // There should be no warning here! (already a `must_use` attribute)
+    #[must_use]
+    pub fn foo4(&self) -> Self {
+        Self
+    }
 }
 
 impl Whatever for Bar {
-    // There should be no warning here!
+    // There should be no warning here! (comes from the trait)
     fn what(&self) -> Self {
         self.foo2()
     }
-    // There should be no warning here!
+    // There should be no warning here! (comes from the trait)
     fn what2(&self) -> &Self {
         self
     }
 }
+
+#[must_use]
+pub struct Foo;
+
+impl Foo {
+    // There should be no warning here! (`Foo` already implements `#[must_use]`)
+    fn foo(&self) -> Self {
+        Self
+    }
+}