2018-07-28 10:34:52 -05:00
|
|
|
#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
|
2023-05-31 12:47:10 -05:00
|
|
|
#![allow(
|
|
|
|
clippy::if_same_then_else,
|
|
|
|
clippy::branches_sharing_code,
|
|
|
|
clippy::unnecessary_literal_unwrap
|
|
|
|
)]
|
2018-06-07 22:55:11 -05:00
|
|
|
|
2018-05-27 17:02:38 -05:00
|
|
|
fn test_complex_conditions() {
|
|
|
|
let x: Result<(), ()> = Ok(());
|
|
|
|
let y: Result<(), ()> = Ok(());
|
|
|
|
if x.is_ok() && y.is_err() {
|
2023-07-28 13:40:44 -05:00
|
|
|
// unnecessary
|
|
|
|
x.unwrap();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `unwrap` on `x` after checking its variant with `is_ok`
|
2023-07-28 13:40:44 -05:00
|
|
|
// will panic
|
|
|
|
x.unwrap_err();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this call to `unwrap_err()` will always panic
|
2023-07-28 13:40:44 -05:00
|
|
|
// will panic
|
|
|
|
y.unwrap();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this call to `unwrap()` will always panic
|
2023-07-28 13:40:44 -05:00
|
|
|
// unnecessary
|
|
|
|
y.unwrap_err();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `unwrap_err` on `y` after checking its variant with `is_err`
|
2018-05-27 17:02:38 -05:00
|
|
|
} else {
|
2018-06-08 11:12:01 -05:00
|
|
|
// not statically determinable whether any of the following will always succeed or always fail:
|
|
|
|
x.unwrap();
|
2018-05-27 17:02:38 -05:00
|
|
|
x.unwrap_err();
|
|
|
|
y.unwrap();
|
2018-06-08 11:12:01 -05:00
|
|
|
y.unwrap_err();
|
2018-05-27 17:02:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if x.is_ok() || y.is_ok() {
|
2018-06-08 11:12:01 -05:00
|
|
|
// not statically determinable whether any of the following will always succeed or always fail:
|
2018-05-27 17:02:38 -05:00
|
|
|
x.unwrap();
|
|
|
|
y.unwrap();
|
|
|
|
} else {
|
2023-07-28 13:40:44 -05:00
|
|
|
// will panic
|
|
|
|
x.unwrap();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this call to `unwrap()` will always panic
|
2023-07-28 13:40:44 -05:00
|
|
|
// unnecessary
|
|
|
|
x.unwrap_err();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_ok`
|
2023-07-28 13:40:44 -05:00
|
|
|
// will panic
|
|
|
|
y.unwrap();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this call to `unwrap()` will always panic
|
2023-07-28 13:40:44 -05:00
|
|
|
// unnecessary
|
|
|
|
y.unwrap_err();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `unwrap_err` on `y` after checking its variant with `is_ok`
|
2018-05-27 17:02:38 -05:00
|
|
|
}
|
|
|
|
let z: Result<(), ()> = Ok(());
|
|
|
|
if x.is_ok() && !(y.is_ok() || z.is_err()) {
|
2023-07-28 13:40:44 -05:00
|
|
|
// unnecessary
|
|
|
|
x.unwrap();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `unwrap` on `x` after checking its variant with `is_ok`
|
2023-07-28 13:40:44 -05:00
|
|
|
// will panic
|
|
|
|
x.unwrap_err();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this call to `unwrap_err()` will always panic
|
2023-07-28 13:40:44 -05:00
|
|
|
// will panic
|
|
|
|
y.unwrap();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this call to `unwrap()` will always panic
|
2023-07-28 13:40:44 -05:00
|
|
|
// unnecessary
|
|
|
|
y.unwrap_err();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `unwrap_err` on `y` after checking its variant with `is_ok`
|
2023-07-28 13:40:44 -05:00
|
|
|
// unnecessary
|
|
|
|
z.unwrap();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `unwrap` on `z` after checking its variant with `is_err`
|
2023-07-28 13:40:44 -05:00
|
|
|
// will panic
|
|
|
|
z.unwrap_err();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this call to `unwrap_err()` will always panic
|
2018-05-27 17:02:38 -05:00
|
|
|
}
|
|
|
|
if x.is_ok() || !(y.is_ok() && z.is_err()) {
|
2018-06-08 11:12:01 -05:00
|
|
|
// not statically determinable whether any of the following will always succeed or always fail:
|
|
|
|
x.unwrap();
|
2018-05-27 17:02:38 -05:00
|
|
|
y.unwrap();
|
2018-06-08 11:12:01 -05:00
|
|
|
z.unwrap();
|
|
|
|
} else {
|
2023-07-28 13:40:44 -05:00
|
|
|
// will panic
|
|
|
|
x.unwrap();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this call to `unwrap()` will always panic
|
2023-07-28 13:40:44 -05:00
|
|
|
// unnecessary
|
|
|
|
x.unwrap_err();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `unwrap_err` on `x` after checking its variant with `is_ok`
|
2023-07-28 13:40:44 -05:00
|
|
|
// unnecessary
|
|
|
|
y.unwrap();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `unwrap` on `y` after checking its variant with `is_ok`
|
2023-07-28 13:40:44 -05:00
|
|
|
// will panic
|
|
|
|
y.unwrap_err();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this call to `unwrap_err()` will always panic
|
2023-07-28 13:40:44 -05:00
|
|
|
// will panic
|
|
|
|
z.unwrap();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: this call to `unwrap()` will always panic
|
2023-07-28 13:40:44 -05:00
|
|
|
// unnecessary
|
|
|
|
z.unwrap_err();
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `unwrap_err` on `z` after checking its variant with `is_err`
|
2018-05-27 17:02:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-15 14:27:44 -05:00
|
|
|
fn main() {}
|