]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/single_match.rs
iterate List by value
[rust.git] / tests / ui / single_match.rs
index c0c82adafb5512e2391a14ab9bdaf6ad779c93e7..1c55af5dfb673536605d3443bc135b4d49209e65 100644 (file)
@@ -1,53 +1,64 @@
-#![feature(tool_lints)]
-
 #![warn(clippy::single_match)]
 
-fn dummy() {
-}
+fn dummy() {}
 
-fn single_match(){
+fn single_match() {
     let x = Some(1u8);
 
     match x {
-        Some(y) => { println!("{:?}", y); }
-        _ => ()
+        Some(y) => {
+            println!("{:?}", y);
+        },
+        _ => (),
     };
 
-    let z = (1u8,1u8);
+    let x = Some(1u8);
+    match x {
+        // Note the missing block braces.
+        // We suggest `if let Some(y) = x { .. }` because the macro
+        // is expanded before we can do anything.
+        Some(y) => println!("{:?}", y),
+        _ => (),
+    }
+
+    let z = (1u8, 1u8);
     match z {
-        (2...3, 7...9) => dummy(),
-        _ => {}
+        (2..=3, 7..=9) => dummy(),
+        _ => {},
     };
 
     // Not linted (pattern guards used)
     match x {
         Some(y) if y == 0 => println!("{:?}", y),
-        _ => ()
+        _ => (),
     }
 
     // Not linted (no block with statements in the single arm)
     match z {
-        (2...3, 7...9) => println!("{:?}", z),
+        (2..=3, 7..=9) => println!("{:?}", z),
         _ => println!("nope"),
     }
 }
 
-enum Foo { Bar, Baz(u8) }
-use Foo::*;
+enum Foo {
+    Bar,
+    Baz(u8),
+}
 use std::borrow::Cow;
+use Foo::*;
 
 fn single_match_know_enum() {
     let x = Some(1u8);
-    let y : Result<_, i8> = Ok(1i8);
+    let y: Result<_, i8> = Ok(1i8);
 
     match x {
         Some(y) => dummy(),
-        None => ()
+        None => (),
     };
 
     match y {
         Ok(y) => dummy(),
-        Err(..) => ()
+        Err(..) => (),
     };
 
     let c = Cow::Borrowed("");
@@ -70,4 +81,15 @@ fn single_match_know_enum() {
     }
 }
 
-fn main() { }
+macro_rules! single_match {
+    ($num:literal) => {
+        match $num {
+            15 => println!("15"),
+            _ => (),
+        }
+    };
+}
+
+fn main() {
+    single_match!(5);
+}