]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/match_expr_like_matches_macro.fixed
Rollup merge of #78728 - a1phyr:const_cell_into_inner, r=dtolnay
[rust.git] / src / tools / clippy / tests / ui / match_expr_like_matches_macro.fixed
1 // run-rustfix
2
3 #![warn(clippy::match_like_matches_macro)]
4 #![allow(unreachable_patterns, dead_code)]
5
6 fn main() {
7     let x = Some(5);
8
9     // Lint
10     let _y = matches!(x, Some(0));
11
12     // Lint
13     let _w = matches!(x, Some(_));
14
15     // Turn into is_none
16     let _z = x.is_none();
17
18     // Lint
19     let _zz = !matches!(x, Some(r) if r == 0);
20
21     // Lint
22     let _zzz = matches!(x, Some(5));
23
24     // No lint
25     let _a = match x {
26         Some(_) => false,
27         _ => false,
28     };
29
30     // No lint
31     let _ab = match x {
32         Some(0) => false,
33         _ => true,
34         None => false,
35     };
36
37     enum E {
38         A(u32),
39         B(i32),
40         C,
41         D,
42     };
43     let x = E::A(2);
44     {
45         // lint
46         let _ans = matches!(x, E::A(_) | E::B(_));
47     }
48     {
49         // lint
50         let _ans = !matches!(x, E::B(_) | E::C);
51     }
52     {
53         // no lint
54         let _ans = match x {
55             E::A(_) => false,
56             E::B(_) => false,
57             E::C => true,
58             _ => true,
59         };
60     }
61     {
62         // no lint
63         let _ans = match x {
64             E::A(_) => true,
65             E::B(_) => false,
66             E::C => false,
67             _ => true,
68         };
69     }
70     {
71         // no lint
72         let _ans = match x {
73             E::A(a) if a < 10 => false,
74             E::B(a) if a < 10 => false,
75             _ => true,
76         };
77     }
78     {
79         // no lint
80         let _ans = match x {
81             E::A(_) => false,
82             E::B(a) if a < 10 => false,
83             _ => true,
84         };
85     }
86     {
87         // no lint
88         let _ans = match x {
89             E::A(a) => a == 10,
90             E::B(_) => false,
91             _ => true,
92         };
93     }
94     {
95         // no lint
96         let _ans = match x {
97             E::A(_) => false,
98             E::B(_) => true,
99             _ => false,
100         };
101     }
102 }