]> git.lizzy.rs Git - rust.git/blobdiff - tests/ui/single_match.rs
Rollup merge of #92849 - flip1995:clippyup, r=Manishearth
[rust.git] / tests / ui / single_match.rs
index 5a1bde3de3243b7b9eabc8c71aac88163fcc1f6a..b1819e08d53bf5dc9054e41cde25c580077082c5 100644 (file)
@@ -1,12 +1,3 @@
-// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
 #![warn(clippy::single_match)]
 
 fn dummy() {}
@@ -32,7 +23,7 @@ fn single_match() {
 
     let z = (1u8, 1u8);
     match z {
-        (2...3, 7...9) => dummy(),
+        (2..=3, 7..=9) => dummy(),
         _ => {},
     };
 
@@ -44,7 +35,7 @@ fn single_match() {
 
     // 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"),
     }
 }
@@ -90,4 +81,79 @@ fn single_match_know_enum() {
     }
 }
 
-fn main() {}
+// issue #173
+fn if_suggestion() {
+    let x = "test";
+    match x {
+        "test" => println!(),
+        _ => (),
+    }
+
+    #[derive(PartialEq, Eq)]
+    enum Foo {
+        A,
+        B,
+        C(u32),
+    }
+
+    let x = Foo::A;
+    match x {
+        Foo::A => println!(),
+        _ => (),
+    }
+
+    const FOO_C: Foo = Foo::C(0);
+    match x {
+        FOO_C => println!(),
+        _ => (),
+    }
+
+    match &&x {
+        Foo::A => println!(),
+        _ => (),
+    }
+
+    let x = &x;
+    match &x {
+        Foo::A => println!(),
+        _ => (),
+    }
+
+    enum Bar {
+        A,
+        B,
+    }
+    impl PartialEq for Bar {
+        fn eq(&self, rhs: &Self) -> bool {
+            matches!((self, rhs), (Self::A, Self::A) | (Self::B, Self::B))
+        }
+    }
+    impl Eq for Bar {}
+
+    let x = Bar::A;
+    match x {
+        Bar::A => println!(),
+        _ => (),
+    }
+
+    // issue #7038
+    struct X;
+    let x = Some(X);
+    match x {
+        None => println!(),
+        _ => (),
+    };
+}
+
+macro_rules! single_match {
+    ($num:literal) => {
+        match $num {
+            15 => println!("15"),
+            _ => (),
+        }
+    };
+}
+
+fn main() {
+    single_match!(5);
+}