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