]> git.lizzy.rs Git - rust.git/blobdiff - src/tools/clippy/tests/ui/match_ref_pats.rs
Rollup merge of #100076 - tspiteri:const_slice_split_at, r=oli-obk
[rust.git] / src / tools / clippy / tests / ui / match_ref_pats.rs
index 6cbb4d32b0d71287c8e35a8e648d9436cbb0aef5..68dfac4e2e978ba44c018e17701be7e7c2569664 100644 (file)
@@ -1,5 +1,6 @@
+// run-rustfix
 #![warn(clippy::match_ref_pats)]
-#![allow(clippy::equatable_if_let)]
+#![allow(dead_code, unused_variables, clippy::equatable_if_let, clippy::enum_variant_names)]
 
 fn ref_pats() {
     {
@@ -72,4 +73,46 @@ fn ice_3719() {
     }
 }
 
+mod issue_7740 {
+    macro_rules! foobar_variant(
+        ($idx:expr) => (FooBar::get($idx).unwrap())
+    );
+
+    enum FooBar {
+        Foo,
+        Bar,
+        FooBar,
+        BarFoo,
+    }
+
+    impl FooBar {
+        fn get(idx: u8) -> Option<&'static Self> {
+            match idx {
+                0 => Some(&FooBar::Foo),
+                1 => Some(&FooBar::Bar),
+                2 => Some(&FooBar::FooBar),
+                3 => Some(&FooBar::BarFoo),
+                _ => None,
+            }
+        }
+    }
+
+    fn issue_7740() {
+        // Issue #7740
+        match foobar_variant!(0) {
+            &FooBar::Foo => println!("Foo"),
+            &FooBar::Bar => println!("Bar"),
+            &FooBar::FooBar => println!("FooBar"),
+            _ => println!("Wild"),
+        }
+
+        // This shouldn't trigger
+        if let &FooBar::BarFoo = foobar_variant!(3) {
+            println!("BarFoo");
+        } else {
+            println!("Wild");
+        }
+    }
+}
+
 fn main() {}