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