about summary refs log tree commit diff
diff options
context:
space:
mode:
authoryanglsh <yanglsh@shanghaitech.edu.cn>2025-03-12 21:55:31 +0800
committeryanglsh <yanglsh@shanghaitech.edu.cn>2025-03-12 21:55:31 +0800
commit1066ee09ed106a19cd902dfb1d4d44fdf472cb56 (patch)
tree3f608eacde5aea4f1accb4e507c8229df531cbe9
parent714c64c7a140bc5c7accbf16770d11ddf7d9e742 (diff)
downloadrust-1066ee09ed106a19cd902dfb1d4d44fdf472cb56.tar.gz
rust-1066ee09ed106a19cd902dfb1d4d44fdf472cb56.zip
fix: `redundant_clone` FP on enum cast
-rw-r--r--clippy_utils/src/mir/mod.rs2
-rw-r--r--tests/ui/redundant_clone.fixed15
-rw-r--r--tests/ui/redundant_clone.rs15
3 files changed, 31 insertions, 1 deletions
diff --git a/clippy_utils/src/mir/mod.rs b/clippy_utils/src/mir/mod.rs
index ffcfcd240ea..9ba644fdd20 100644
--- a/clippy_utils/src/mir/mod.rs
+++ b/clippy_utils/src/mir/mod.rs
@@ -76,7 +76,7 @@ impl<'tcx> Visitor<'tcx> for V<'_> {
                 }
                 if matches!(
                     ctx,
-                    PlaceContext::NonMutatingUse(NonMutatingUseContext::Move)
+                    PlaceContext::NonMutatingUse(NonMutatingUseContext::Move | NonMutatingUseContext::Inspect)
                         | PlaceContext::MutatingUse(MutatingUseContext::Borrow)
                 ) {
                     self.results[i].local_consume_or_mutate_locs.push(loc);
diff --git a/tests/ui/redundant_clone.fixed b/tests/ui/redundant_clone.fixed
index 23c00b34a00..7d5195b6217 100644
--- a/tests/ui/redundant_clone.fixed
+++ b/tests/ui/redundant_clone.fixed
@@ -259,3 +259,18 @@ fn false_negative_5707() {
     let _z = x.clone(); // pr 7346 can't lint on `x`
     drop(y);
 }
+
+mod issue10074 {
+    #[derive(Debug, Clone)]
+    enum MyEnum {
+        A = 1,
+    }
+
+    fn false_positive_on_as() {
+        let e = MyEnum::A;
+        let v = e.clone() as u16;
+
+        println!("{e:?}");
+        println!("{v}");
+    }
+}
diff --git a/tests/ui/redundant_clone.rs b/tests/ui/redundant_clone.rs
index f9fe8ba0236..0ea1024a568 100644
--- a/tests/ui/redundant_clone.rs
+++ b/tests/ui/redundant_clone.rs
@@ -259,3 +259,18 @@ fn false_negative_5707() {
     let _z = x.clone(); // pr 7346 can't lint on `x`
     drop(y);
 }
+
+mod issue10074 {
+    #[derive(Debug, Clone)]
+    enum MyEnum {
+        A = 1,
+    }
+
+    fn false_positive_on_as() {
+        let e = MyEnum::A;
+        let v = e.clone() as u16;
+
+        println!("{e:?}");
+        println!("{v}");
+    }
+}