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