]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/wildcard_enum_match_arm.fixed
New upstream version 1.66.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / wildcard_enum_match_arm.fixed
CommitLineData
f20569fa 1// run-rustfix
136023e0 2// aux-build:non-exhaustive-enum.rs
f20569fa 3#![deny(clippy::wildcard_enum_match_arm)]
2b03887a 4#![allow(dead_code, unreachable_code, unused_variables)]
f20569fa 5#![allow(
2b03887a 6 clippy::diverging_sub_expression,
f20569fa 7 clippy::single_match,
2b03887a 8 clippy::uninlined_format_args,
f20569fa 9 clippy::unnested_or_patterns,
2b03887a 10 clippy::wildcard_in_or_patterns
f20569fa
XL
11)]
12
136023e0
XL
13extern crate non_exhaustive_enum;
14
15use non_exhaustive_enum::ErrorKind;
f20569fa
XL
16
17#[derive(Clone, Copy, Debug, Eq, PartialEq)]
18enum Color {
19 Red,
20 Green,
21 Blue,
22 Rgb(u8, u8, u8),
23 Cyan,
24}
25
26impl Color {
27 fn is_monochrome(self) -> bool {
28 match self {
29 Color::Red | Color::Green | Color::Blue => true,
30 Color::Rgb(r, g, b) => r | g == 0 || r | b == 0 || g | b == 0,
31 Color::Cyan => false,
32 }
33 }
34}
35
36fn main() {
37 let color = Color::Rgb(0, 0, 127);
38 match color {
39 Color::Red => println!("Red"),
40 Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan => eprintln!("Not red"),
41 };
42 match color {
43 Color::Red => println!("Red"),
44 _not_red @ Color::Green | _not_red @ Color::Blue | _not_red @ Color::Rgb(..) | _not_red @ Color::Cyan => eprintln!("Not red"),
45 };
46 let _str = match color {
47 Color::Red => "Red".to_owned(),
48 not_red @ Color::Green | not_red @ Color::Blue | not_red @ Color::Rgb(..) | not_red @ Color::Cyan => format!("{:?}", not_red),
49 };
50 match color {
51 Color::Red => {},
52 Color::Green => {},
53 Color::Blue => {},
54 Color::Cyan => {},
55 c if c.is_monochrome() => {},
56 Color::Rgb(_, _, _) => {},
57 };
58 let _str = match color {
59 Color::Red => "Red",
60 c @ Color::Green | c @ Color::Blue | c @ Color::Rgb(_, _, _) | c @ Color::Cyan => "Not red",
61 };
62 match color {
63 Color::Rgb(r, _, _) if r > 0 => "Some red",
64 Color::Red | Color::Green | Color::Blue | Color::Rgb(..) | Color::Cyan => "No red",
65 };
66 match color {
67 Color::Red | Color::Green | Color::Blue | Color::Cyan => {},
68 Color::Rgb(..) => {},
69 };
70 let x: u8 = unimplemented!();
71 match x {
72 0 => {},
73 140 => {},
74 _ => {},
75 };
76 // We need to use an enum not defined in this test because non_exhaustive is ignored for the
77 // purposes of dead code analysis within a crate.
78 let error_kind = ErrorKind::NotFound;
79 match error_kind {
80 ErrorKind::NotFound => {},
136023e0 81 ErrorKind::PermissionDenied | _ => {},
f20569fa
XL
82 }
83 match error_kind {
84 ErrorKind::NotFound => {},
85 ErrorKind::PermissionDenied => {},
f20569fa
XL
86 _ => {},
87 }
136023e0
XL
88
89 {
90 #![allow(clippy::manual_non_exhaustive)]
91 pub enum Enum {
92 A,
93 B,
94 #[doc(hidden)]
95 __Private,
96 }
97 match Enum::A {
98 Enum::A => (),
99 Enum::B | _ => (),
100 }
101 }
f20569fa 102}