2023-06-02 09:41:57 +00:00
|
|
|
#![allow(clippy::match_same_arms, dead_code)]
|
2020-01-30 03:06:42 +00:00
|
|
|
#![warn(clippy::match_wild_err_arm)]
|
|
|
|
|
2023-06-02 09:41:57 +00:00
|
|
|
fn issue_10635() {
|
|
|
|
enum Error {
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't trigger in const contexts. Const unwrap is not yet stable
|
|
|
|
const X: () = match Ok::<_, Error>(()) {
|
|
|
|
Ok(x) => x,
|
|
|
|
Err(_) => panic!(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-01-30 03:06:42 +00:00
|
|
|
fn match_wild_err_arm() {
|
|
|
|
let x: Result<i32, &str> = Ok(3);
|
|
|
|
|
|
|
|
match x {
|
|
|
|
Ok(3) => println!("ok"),
|
|
|
|
Ok(_) => println!("ok"),
|
|
|
|
Err(_) => panic!("err"),
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: `Err(_)` matches all errors
|
|
|
|
//~| NOTE: match each error separately or use the error output, or use `.expect(ms
|
2020-01-30 03:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
match x {
|
|
|
|
Ok(3) => println!("ok"),
|
|
|
|
Ok(_) => println!("ok"),
|
|
|
|
Err(_) => panic!(),
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: `Err(_)` matches all errors
|
|
|
|
//~| NOTE: match each error separately or use the error output, or use `.expect(ms
|
2020-01-30 03:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
match x {
|
|
|
|
Ok(3) => println!("ok"),
|
|
|
|
Ok(_) => println!("ok"),
|
|
|
|
Err(_) => {
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: `Err(_)` matches all errors
|
|
|
|
//~| NOTE: match each error separately or use the error output, or use `.expect(ms
|
2020-01-30 03:06:42 +00:00
|
|
|
panic!();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
match x {
|
|
|
|
Ok(3) => println!("ok"),
|
|
|
|
Ok(_) => println!("ok"),
|
|
|
|
Err(_e) => panic!(),
|
2023-08-24 19:32:12 +00:00
|
|
|
//~^ ERROR: `Err(_e)` matches all errors
|
|
|
|
//~| NOTE: match each error separately or use the error output, or use `.expect(ms
|
2020-01-30 03:06:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allowed when used in `panic!`.
|
|
|
|
match x {
|
|
|
|
Ok(3) => println!("ok"),
|
|
|
|
Ok(_) => println!("ok"),
|
|
|
|
Err(_e) => panic!("{}", _e),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allowed when not with `panic!` block.
|
|
|
|
match x {
|
|
|
|
Ok(3) => println!("ok"),
|
|
|
|
Ok(_) => println!("ok"),
|
|
|
|
Err(_) => println!("err"),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allowed when used with `unreachable!`.
|
|
|
|
match x {
|
|
|
|
Ok(3) => println!("ok"),
|
|
|
|
Ok(_) => println!("ok"),
|
|
|
|
Err(_) => unreachable!(),
|
|
|
|
}
|
|
|
|
|
|
|
|
// Allowed when used with `unreachable!`.
|
|
|
|
match x {
|
|
|
|
Ok(3) => println!("ok"),
|
|
|
|
Ok(_) => println!("ok"),
|
|
|
|
Err(_) => {
|
|
|
|
unreachable!();
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|