2023-04-23 06:03:09 -05:00
|
|
|
//@aux-build:non-exhaustive-enum.rs
|
2019-02-18 16:55:16 -06:00
|
|
|
#![deny(clippy::wildcard_enum_match_arm)]
|
2022-10-06 02:44:38 -05:00
|
|
|
#![allow(dead_code, unreachable_code, unused_variables)]
|
2019-12-26 22:42:28 -06:00
|
|
|
#![allow(
|
2022-10-06 02:44:38 -05:00
|
|
|
clippy::diverging_sub_expression,
|
2019-12-26 22:42:28 -06:00
|
|
|
clippy::single_match,
|
2022-10-06 02:44:38 -05:00
|
|
|
clippy::uninlined_format_args,
|
2020-12-06 08:01:03 -06:00
|
|
|
clippy::unnested_or_patterns,
|
2022-10-06 02:44:38 -05:00
|
|
|
clippy::wildcard_in_or_patterns
|
2019-12-26 22:42:28 -06:00
|
|
|
)]
|
2019-12-21 20:13:39 -06:00
|
|
|
|
2021-07-01 11:17:38 -05:00
|
|
|
extern crate non_exhaustive_enum;
|
|
|
|
|
|
|
|
use non_exhaustive_enum::ErrorKind;
|
2019-02-18 16:55:16 -06:00
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
|
|
enum Color {
|
|
|
|
Red,
|
|
|
|
Green,
|
|
|
|
Blue,
|
|
|
|
Rgb(u8, u8, u8),
|
|
|
|
Cyan,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Color {
|
|
|
|
fn is_monochrome(self) -> bool {
|
|
|
|
match self {
|
|
|
|
Color::Red | Color::Green | Color::Blue => true,
|
|
|
|
Color::Rgb(r, g, b) => r | g == 0 || r | b == 0 || g | b == 0,
|
|
|
|
Color::Cyan => false,
|
|
|
|
}
|
2019-01-29 12:23:11 -06:00
|
|
|
}
|
2019-01-25 10:42:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2019-02-18 16:55:16 -06:00
|
|
|
let color = Color::Rgb(0, 0, 127);
|
|
|
|
match color {
|
|
|
|
Color::Red => println!("Red"),
|
|
|
|
_ => eprintln!("Not red"),
|
|
|
|
};
|
|
|
|
match color {
|
|
|
|
Color::Red => println!("Red"),
|
|
|
|
_not_red => eprintln!("Not red"),
|
|
|
|
};
|
|
|
|
let _str = match color {
|
|
|
|
Color::Red => "Red".to_owned(),
|
|
|
|
not_red => format!("{:?}", not_red),
|
|
|
|
};
|
|
|
|
match color {
|
|
|
|
Color::Red => {},
|
|
|
|
Color::Green => {},
|
|
|
|
Color::Blue => {},
|
|
|
|
Color::Cyan => {},
|
|
|
|
c if c.is_monochrome() => {},
|
|
|
|
Color::Rgb(_, _, _) => {},
|
|
|
|
};
|
|
|
|
let _str = match color {
|
|
|
|
Color::Red => "Red",
|
|
|
|
c @ Color::Green | c @ Color::Blue | c @ Color::Rgb(_, _, _) | c @ Color::Cyan => "Not red",
|
|
|
|
};
|
|
|
|
match color {
|
|
|
|
Color::Rgb(r, _, _) if r > 0 => "Some red",
|
|
|
|
_ => "No red",
|
|
|
|
};
|
|
|
|
match color {
|
|
|
|
Color::Red | Color::Green | Color::Blue | Color::Cyan => {},
|
|
|
|
Color::Rgb(..) => {},
|
|
|
|
};
|
|
|
|
let x: u8 = unimplemented!();
|
|
|
|
match x {
|
|
|
|
0 => {},
|
|
|
|
140 => {},
|
|
|
|
_ => {},
|
|
|
|
};
|
2019-12-21 20:13:39 -06:00
|
|
|
// We need to use an enum not defined in this test because non_exhaustive is ignored for the
|
|
|
|
// purposes of dead code analysis within a crate.
|
|
|
|
let error_kind = ErrorKind::NotFound;
|
|
|
|
match error_kind {
|
|
|
|
ErrorKind::NotFound => {},
|
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
match error_kind {
|
|
|
|
ErrorKind::NotFound => {},
|
|
|
|
ErrorKind::PermissionDenied => {},
|
|
|
|
_ => {},
|
|
|
|
}
|
2021-07-01 11:17:38 -05:00
|
|
|
|
|
|
|
{
|
|
|
|
#![allow(clippy::manual_non_exhaustive)]
|
|
|
|
pub enum Enum {
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
#[doc(hidden)]
|
|
|
|
__Private,
|
|
|
|
}
|
|
|
|
match Enum::A {
|
|
|
|
Enum::A => (),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
2019-01-29 12:23:11 -06:00
|
|
|
}
|