From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../ui/checked_unwrap/complex_conditionals.rs | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.rs (limited to 'src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.rs') diff --git a/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.rs b/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.rs new file mode 100644 index 000000000..ec082c73b --- /dev/null +++ b/src/tools/clippy/tests/ui/checked_unwrap/complex_conditionals.rs @@ -0,0 +1,54 @@ +#![deny(clippy::panicking_unwrap, clippy::unnecessary_unwrap)] +#![allow(clippy::if_same_then_else, clippy::branches_sharing_code)] + +fn test_complex_conditions() { + let x: Result<(), ()> = Ok(()); + let y: Result<(), ()> = Ok(()); + if x.is_ok() && y.is_err() { + x.unwrap(); // unnecessary + x.unwrap_err(); // will panic + y.unwrap(); // will panic + y.unwrap_err(); // unnecessary + } else { + // not statically determinable whether any of the following will always succeed or always fail: + x.unwrap(); + x.unwrap_err(); + y.unwrap(); + y.unwrap_err(); + } + + if x.is_ok() || y.is_ok() { + // not statically determinable whether any of the following will always succeed or always fail: + x.unwrap(); + y.unwrap(); + } else { + x.unwrap(); // will panic + x.unwrap_err(); // unnecessary + y.unwrap(); // will panic + y.unwrap_err(); // unnecessary + } + let z: Result<(), ()> = Ok(()); + if x.is_ok() && !(y.is_ok() || z.is_err()) { + x.unwrap(); // unnecessary + x.unwrap_err(); // will panic + y.unwrap(); // will panic + y.unwrap_err(); // unnecessary + z.unwrap(); // unnecessary + z.unwrap_err(); // will panic + } + if x.is_ok() || !(y.is_ok() && z.is_err()) { + // not statically determinable whether any of the following will always succeed or always fail: + x.unwrap(); + y.unwrap(); + z.unwrap(); + } else { + x.unwrap(); // will panic + x.unwrap_err(); // unnecessary + y.unwrap(); // unnecessary + y.unwrap_err(); // will panic + z.unwrap(); // will panic + z.unwrap_err(); // unnecessary + } +} + +fn main() {} -- cgit v1.2.3