]> git.lizzy.rs Git - rust.git/blob - tests/ui/wildcard_enum_match_arm.rs
wildcard_enum_match_arm gives suggestions
[rust.git] / tests / ui / wildcard_enum_match_arm.rs
1 #![warn(clippy::wildcard_enum_match_arm)]
2
3 #[derive(Debug)]
4 enum Maybe<T> {
5     Some(T),
6     Probably(T),
7     None,
8 }
9
10 fn is_it_wildcard<T>(m: Maybe<T>) -> &'static str {
11     match m {
12         Maybe::Some(_) => "Some",
13         _ => "Could be",
14     }
15 }
16
17 fn is_it_bound<T>(m: Maybe<T>) -> &'static str {
18     match m {
19         Maybe::None => "None",
20         _other => "Could be",
21     }
22 }
23
24 fn is_it_binding(m: Maybe<u32>) -> String {
25     match m {
26         Maybe::Some(v) => "Large".to_string(),
27         n => format!("{:?}", n),
28     }
29 }
30
31 fn is_it_binding_exhaustive(m: Maybe<u32>) -> String {
32     match m {
33         Maybe::Some(v) => "Large".to_string(),
34         n @ Maybe::Probably(_) | n @ Maybe::None => format!("{:?}", n),
35     }
36 }
37
38 fn is_it_with_guard(m: Maybe<u32>) -> &'static str {
39     match m {
40         Maybe::Some(v) if v > 100 => "Large",
41         _ => "Who knows",
42     }
43 }
44
45 fn is_it_exhaustive<T>(m: Maybe<T>) -> &'static str {
46     match m {
47         Maybe::None => "None",
48         Maybe::Some(_) | Maybe::Probably(..) => "Could be",
49     }
50 }
51
52 fn is_one_or_three(i: i32) -> bool {
53     match i {
54         1 | 3 => true,
55         _ => false,
56     }
57 }
58
59 fn main() {
60     println!("{}", is_it_wildcard(Maybe::Some("foo")));
61
62     println!("{}", is_it_bound(Maybe::Some("foo")));
63
64     println!("{}", is_it_binding(Maybe::Some(1)));
65
66     println!("{}", is_it_binding_exhaustive(Maybe::Some(1)));
67
68     println!("{}", is_it_with_guard(Maybe::Some(1)));
69
70     println!("{}", is_it_exhaustive(Maybe::Some("foo")));
71
72     println!("{}", is_one_or_three(2));
73 }