summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed')
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed
index 4778eaefd..66598f892 100644
--- a/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_lazy_eval.fixed
@@ -6,6 +6,8 @@
#![allow(clippy::needless_borrow)]
#![allow(clippy::unnecessary_literal_unwrap)]
#![allow(clippy::unit_arg)]
+#![allow(arithmetic_overflow)]
+#![allow(unconditional_panic)]
use std::ops::Deref;
@@ -190,3 +192,79 @@ fn issue9485() {
// should not lint, is in proc macro
with_span!(span Some(42).unwrap_or_else(|| 2););
}
+
+fn issue9422(x: usize) -> Option<usize> {
+ (x >= 5).then(|| x - 5)
+ // (x >= 5).then_some(x - 5) // clippy suggestion panics
+}
+
+fn panicky_arithmetic_ops(x: usize, y: isize) {
+ #![allow(clippy::identity_op, clippy::eq_op)]
+
+ // See comments in `eager_or_lazy.rs` for the rules that this is meant to follow
+
+ let _x = false.then_some(i32::MAX + 1);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then_some(i32::MAX * 2);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then_some(i32::MAX - 1);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then_some(i32::MIN - 1);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then_some((1 + 2 * 3 - 2 / 3 + 9) << 2);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then_some(255u8 << 7);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then_some(255u8 << 8);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then_some(255u8 >> 8);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then(|| 255u8 >> x);
+ let _x = false.then_some(i32::MAX + -1);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then_some(-i32::MAX);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then_some(-i32::MIN);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then(|| -y);
+ let _x = false.then_some(255 >> -7);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then_some(255 << -1);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then_some(1 / 0);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then_some(x << -1);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then_some(x << 2);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then(|| x + x);
+ let _x = false.then(|| x * x);
+ let _x = false.then(|| x - x);
+ let _x = false.then(|| x / x);
+ let _x = false.then(|| x % x);
+ let _x = false.then(|| x + 1);
+ let _x = false.then(|| 1 + x);
+
+ let _x = false.then_some(x / 0);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then_some(x % 0);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then(|| y / -1);
+ let _x = false.then_some(1 / -1);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then_some(i32::MIN / -1);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then(|| i32::MIN / x as i32);
+ let _x = false.then_some(i32::MIN / 0);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then_some(4 / 2);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+ let _x = false.then(|| 1 / x);
+
+ // const eval doesn't read variables, but floating point math never panics, so we can still emit a
+ // warning
+ let f1 = 1.0;
+ let f2 = 2.0;
+ let _x = false.then_some(f1 + f2);
+ //~^ ERROR: unnecessary closure used with `bool::then`
+}