]> git.lizzy.rs Git - rust.git/blob - tests/ui/match_ref_pats.rs
iterate List by value
[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     #[allow(clippy::match_single_binding)]
30     match w {
31         _ => println!("none"),
32     }
33
34     let a = &Some(0);
35     if let &None = a {
36         println!("none");
37     }
38
39     let b = Some(0);
40     if let &None = &b {
41         println!("none");
42     }
43 }
44
45 mod ice_3719 {
46     macro_rules! foo_variant(
47         ($idx:expr) => (Foo::get($idx).unwrap())
48     );
49
50     enum Foo {
51         A,
52         B,
53     }
54
55     impl Foo {
56         fn get(idx: u8) -> Option<&'static Self> {
57             match idx {
58                 0 => Some(&Foo::A),
59                 1 => Some(&Foo::B),
60                 _ => None,
61             }
62         }
63     }
64
65     fn ice_3719() {
66         // ICE #3719
67         match foo_variant!(0) {
68             &Foo::A => println!("A"),
69             _ => println!("Wild"),
70         }
71     }
72 }
73
74 fn main() {}