about summary refs log tree commit diff
path: root/src/tools/clippy/tests
diff options
context:
space:
mode:
authorAlex Macleod <alex@macleod.io>2025-04-09 12:14:18 +0000
committerPietro Albini <pietro@pietroalbini.org>2025-05-09 17:41:11 +0200
commit79df6ac1a738d6cd9d8ef6ccaa04fef558c71196 (patch)
treef5257894efe0c4b87abe3e1ddc753571275e8bf6 /src/tools/clippy/tests
parent7d83c8c543d7c6a394c0c5f5235e63d3da01e0c8 (diff)
downloadrust-79df6ac1a738d6cd9d8ef6ccaa04fef558c71196.tar.gz
rust-79df6ac1a738d6cd9d8ef6ccaa04fef558c71196.zip
fix: map_entry: don't emit lint before checks have been performed (#14568)
Fixes rust-lang/rust-clippy#14449, introduced in #14314

changelog: [`map_entry`]: fix a false positive where the lint would
trigger without any insert calls present
Diffstat (limited to 'src/tools/clippy/tests')
-rw-r--r--src/tools/clippy/tests/ui/entry.fixed22
-rw-r--r--src/tools/clippy/tests/ui/entry.rs22
2 files changed, 44 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/entry.fixed b/src/tools/clippy/tests/ui/entry.fixed
index 69452a8d9a6..f2df9f0204e 100644
--- a/src/tools/clippy/tests/ui/entry.fixed
+++ b/src/tools/clippy/tests/ui/entry.fixed
@@ -226,4 +226,26 @@ fn issue11976() {
     }
 }
 
+mod issue14449 {
+    use std::collections::BTreeMap;
+
+    pub struct Meow {
+        map: BTreeMap<String, String>,
+    }
+
+    impl Meow {
+        fn pet(&self, _key: &str, _v: u32) -> u32 {
+            42
+        }
+    }
+
+    pub fn f(meow: &Meow, x: String) {
+        if meow.map.contains_key(&x) {
+            let _ = meow.pet(&x, 1);
+        } else {
+            let _ = meow.pet(&x, 0);
+        }
+    }
+}
+
 fn main() {}
diff --git a/src/tools/clippy/tests/ui/entry.rs b/src/tools/clippy/tests/ui/entry.rs
index 3578324f01c..166eea417ac 100644
--- a/src/tools/clippy/tests/ui/entry.rs
+++ b/src/tools/clippy/tests/ui/entry.rs
@@ -232,4 +232,26 @@ fn issue11976() {
     }
 }
 
+mod issue14449 {
+    use std::collections::BTreeMap;
+
+    pub struct Meow {
+        map: BTreeMap<String, String>,
+    }
+
+    impl Meow {
+        fn pet(&self, _key: &str, _v: u32) -> u32 {
+            42
+        }
+    }
+
+    pub fn f(meow: &Meow, x: String) {
+        if meow.map.contains_key(&x) {
+            let _ = meow.pet(&x, 1);
+        } else {
+            let _ = meow.pet(&x, 0);
+        }
+    }
+}
+
 fn main() {}