Split up checked_unwrap test further

This commit is contained in:
flip1995 2020-03-18 15:24:48 +01:00
parent c7c7ab23aa
commit a808779441
No known key found for this signature in database
GPG Key ID: 2CEFCDB27ED0BE79
4 changed files with 47 additions and 29 deletions

View File

@ -51,15 +51,4 @@ fn test_complex_conditions() {
}
}
fn test_nested() {
fn nested() {
let x = Some(());
if x.is_some() {
x.unwrap(); // unnecessary
} else {
x.unwrap(); // will panic
}
}
}
fn main() {}

View File

@ -188,22 +188,5 @@ LL | if x.is_ok() || !(y.is_ok() && z.is_err()) {
LL | z.unwrap_err(); // unnecessary
| ^^^^^^^^^^^^^^
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
--> $DIR/complex_conditionals.rs:58:13
|
LL | if x.is_some() {
| ----------- the check is happening here
LL | x.unwrap(); // unnecessary
| ^^^^^^^^^^
error: This call to `unwrap()` will always panic.
--> $DIR/complex_conditionals.rs:60:13
|
LL | if x.is_some() {
| ----------- because of this check
...
LL | x.unwrap(); // will panic
| ^^^^^^^^^^
error: aborting due to 22 previous errors
error: aborting due to 20 previous errors

View File

@ -0,0 +1,15 @@
#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
#![allow(clippy::if_same_then_else)]
fn test_nested() {
fn nested() {
let x = Some(());
if x.is_some() {
x.unwrap(); // unnecessary
} else {
x.unwrap(); // will panic
}
}
}
fn main() {}

View File

@ -0,0 +1,31 @@
error: You checked before that `unwrap()` cannot fail. Instead of checking and unwrapping, it's better to use `if let` or `match`.
--> $DIR/complex_conditionals_nested.rs:8:13
|
LL | if x.is_some() {
| ----------- the check is happening here
LL | x.unwrap(); // unnecessary
| ^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/complex_conditionals_nested.rs:1:35
|
LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: This call to `unwrap()` will always panic.
--> $DIR/complex_conditionals_nested.rs:10:13
|
LL | if x.is_some() {
| ----------- because of this check
...
LL | x.unwrap(); // will panic
| ^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/complex_conditionals_nested.rs:1:9
|
LL | #![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors