]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/match_single_binding.fixed
Auto merge of #8374 - Alexendoo:bless-revisions, r=camsteffen
[rust.git] / tests / ui / match_single_binding.fixed
index bc2346a8dbf0b9b83ff8eea22e518987bfafe9c8..b4ec525ada09a763059d8837fc06d572051f1a4b 100644 (file)
@@ -1,7 +1,7 @@
 // run-rustfix
 
 #![warn(clippy::match_single_binding)]
-#![allow(unused_variables, clippy::many_single_char_names, clippy::toplevel_ref_arg)]
+#![allow(unused_variables, clippy::toplevel_ref_arg)]
 
 struct Point {
     x: i32,
@@ -12,6 +12,14 @@ fn coords() -> Point {
     Point { x: 1, y: 2 }
 }
 
+macro_rules! foo {
+    ($param:expr) => {
+        match $param {
+            _ => println!("whatever"),
+        }
+    };
+}
+
 fn main() {
     let a = 1;
     let b = 2;
@@ -25,6 +33,8 @@ fn main() {
     let (x, y, z) = (a, b, c);
     println!("{} {} {}", x, y, z);
     // Ok
+    foo!(a);
+    // Ok
     match a {
         2 => println!("2"),
         _ => println!("Not 2"),
@@ -67,4 +77,39 @@ fn main() {
     // Lint
     let Point { x, y } = coords();
     let product = x * y;
+    // Lint
+    let v = vec![Some(1), Some(2), Some(3), Some(4)];
+    #[allow(clippy::let_and_return)]
+    let _ = v
+        .iter()
+        .map(|i| {
+            let unwrapped = i.unwrap();
+            unwrapped
+        })
+        .collect::<Vec<u8>>();
+    // Ok
+    let x = 1;
+    match x {
+        #[cfg(disabled_feature)]
+        0 => println!("Disabled branch"),
+        _ => println!("Enabled branch"),
+    }
+
+    // Ok
+    let x = 1;
+    let y = 1;
+    match match y {
+        0 => 1,
+        _ => 2,
+    } {
+        #[cfg(disabled_feature)]
+        0 => println!("Array index start"),
+        _ => println!("Not an array index start"),
+    }
+    // False negative
+    let x = 1;
+    match x {
+        // =>
+        _ => println!("Not an array index start"),
+    }
 }