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