]> git.lizzy.rs Git - rust.git/blob - tests/ui/wildcard_enum_match_arm.rs
Auto merge of #4947 - rust-lang:doc-main-extern-crate, r=flip1995
[rust.git] / tests / ui / wildcard_enum_match_arm.rs
1 // run-rustfix
2
3 #![deny(clippy::wildcard_enum_match_arm)]
4 #![allow(unreachable_code, unused_variables, dead_code, clippy::single_match)]
5
6 use std::io::ErrorKind;
7
8 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
9 enum Color {
10     Red,
11     Green,
12     Blue,
13     Rgb(u8, u8, u8),
14     Cyan,
15 }
16
17 impl Color {
18     fn is_monochrome(self) -> bool {
19         match self {
20             Color::Red | Color::Green | Color::Blue => true,
21             Color::Rgb(r, g, b) => r | g == 0 || r | b == 0 || g | b == 0,
22             Color::Cyan => false,
23         }
24     }
25 }
26
27 fn main() {
28     let color = Color::Rgb(0, 0, 127);
29     match color {
30         Color::Red => println!("Red"),
31         _ => eprintln!("Not red"),
32     };
33     match color {
34         Color::Red => println!("Red"),
35         _not_red => eprintln!("Not red"),
36     };
37     let _str = match color {
38         Color::Red => "Red".to_owned(),
39         not_red => format!("{:?}", not_red),
40     };
41     match color {
42         Color::Red => {},
43         Color::Green => {},
44         Color::Blue => {},
45         Color::Cyan => {},
46         c if c.is_monochrome() => {},
47         Color::Rgb(_, _, _) => {},
48     };
49     let _str = match color {
50         Color::Red => "Red",
51         c @ Color::Green | c @ Color::Blue | c @ Color::Rgb(_, _, _) | c @ Color::Cyan => "Not red",
52     };
53     match color {
54         Color::Rgb(r, _, _) if r > 0 => "Some red",
55         _ => "No red",
56     };
57     match color {
58         Color::Red | Color::Green | Color::Blue | Color::Cyan => {},
59         Color::Rgb(..) => {},
60     };
61     let x: u8 = unimplemented!();
62     match x {
63         0 => {},
64         140 => {},
65         _ => {},
66     };
67     // We need to use an enum not defined in this test because non_exhaustive is ignored for the
68     // purposes of dead code analysis within a crate.
69     let error_kind = ErrorKind::NotFound;
70     match error_kind {
71         ErrorKind::NotFound => {},
72         _ => {},
73     }
74     match error_kind {
75         ErrorKind::NotFound => {},
76         ErrorKind::PermissionDenied => {},
77         ErrorKind::ConnectionRefused => {},
78         ErrorKind::ConnectionReset => {},
79         ErrorKind::ConnectionAborted => {},
80         ErrorKind::NotConnected => {},
81         ErrorKind::AddrInUse => {},
82         ErrorKind::AddrNotAvailable => {},
83         ErrorKind::BrokenPipe => {},
84         ErrorKind::AlreadyExists => {},
85         ErrorKind::WouldBlock => {},
86         ErrorKind::InvalidInput => {},
87         ErrorKind::InvalidData => {},
88         ErrorKind::TimedOut => {},
89         ErrorKind::WriteZero => {},
90         ErrorKind::Interrupted => {},
91         ErrorKind::Other => {},
92         ErrorKind::UnexpectedEof => {},
93         _ => {},
94     }
95 }