mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-13 04:26:48 +00:00
Split up checked_unwrap test further
This commit is contained in:
parent
c7c7ab23aa
commit
a808779441
@ -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() {}
|
||||
|
@ -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
|
||||
|
||||
|
15
tests/ui/checked_unwrap/complex_conditionals_nested.rs
Normal file
15
tests/ui/checked_unwrap/complex_conditionals_nested.rs
Normal 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() {}
|
31
tests/ui/checked_unwrap/complex_conditionals_nested.stderr
Normal file
31
tests/ui/checked_unwrap/complex_conditionals_nested.stderr
Normal 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
|
||||
|
Loading…
Reference in New Issue
Block a user