]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/dereference.rs
Check for Deref trait impl + add fixed version
[rust.git] / tests / ui / dereference.rs
index 5de201fb22f0b6e56f7d4cef0723906b50efae2e..25e1c29e7fa5ff4c45755bcdb34b5b709c53adb5 100644 (file)
@@ -1,3 +1,5 @@
+// run-rustfix
+
 #![allow(unused_variables, clippy::many_single_char_names, clippy::clone_double_ref)]
 #![warn(clippy::explicit_deref_method)]
 
@@ -59,4 +61,19 @@ macro_rules! expr_deref {
 
     let opt_a = Some(a);
     let b = opt_a.unwrap().deref();
+
+    // The struct does not implement Deref trait
+    #[derive(Copy, Clone)]
+    struct NoLint(u32);
+    impl NoLint {
+        pub fn deref(self) -> u32 {
+            self.0
+        }
+        pub fn deref_mut(self) -> u32 {
+            self.0
+        }
+    }
+    let no_lint = NoLint(42);
+    let b = no_lint.deref();
+    let b = no_lint.deref_mut();
 }