]> git.lizzy.rs Git - rust.git/blob - tests/ui/match_ref_pats.rs
Auto merge of #4314 - chansuke:add-negation-to-is_empty, r=flip1995
[rust.git] / tests / ui / match_ref_pats.rs
1 #![warn(clippy::match_ref_pats)]
2
3 fn ref_pats() {
4     {
5         let v = &Some(0);
6         match v {
7             &Some(v) => println!("{:?}", v),
8             &None => println!("none"),
9         }
10         match v {
11             // This doesn't trigger; we have a different pattern.
12             &Some(v) => println!("some"),
13             other => println!("other"),
14         }
15     }
16     let tup = &(1, 2);
17     match tup {
18         &(v, 1) => println!("{}", v),
19         _ => println!("none"),
20     }
21     // Special case: using `&` both in expr and pats.
22     let w = Some(0);
23     match &w {
24         &Some(v) => println!("{:?}", v),
25         &None => println!("none"),
26     }
27     // False positive: only wildcard pattern.
28     let w = Some(0);
29     match w {
30         _ => println!("none"),
31     }
32
33     let a = &Some(0);
34     if let &None = a {
35         println!("none");
36     }
37
38     let b = Some(0);
39     if let &None = &b {
40         println!("none");
41     }
42 }
43
44 mod ice_3719 {
45     macro_rules! foo_variant(
46         ($idx:expr) => (Foo::get($idx).unwrap())
47     );
48
49     enum Foo {
50         A,
51         B,
52     }
53
54     impl Foo {
55         fn get(idx: u8) -> Option<&'static Self> {
56             match idx {
57                 0 => Some(&Foo::A),
58                 1 => Some(&Foo::B),
59                 _ => None,
60             }
61         }
62     }
63
64     fn ice_3719() {
65         // ICE #3719
66         match foo_variant!(0) {
67             &Foo::A => println!("A"),
68             _ => println!("Wild"),
69         }
70     }
71 }
72
73 fn main() {}