From 6f6a80ee476d7c76cb859e6f7f8baf3e2cf58372 Mon Sep 17 00:00:00 2001 From: Gurinder Singh Date: Wed, 27 Dec 2023 09:06:29 +0530 Subject: [PATCH 1/2] Emit `AssertLint` for overflow asserts found in MIR This fixes the issue where no lints were firing for overflowing SHL and SHR ops. That happened because `ConstPropagator::check_binary_op()`, which is responsible for firing these lints, was skipping them because it couldn't find any `Shl()` or `Shr()` ops in the main MIR. That in turn occurred because our const promotion pass `PromoteTemps` removes these ops from the MIR when it runs. With this change, the firing of these particular lints is predicated on the presence of an assert terminator instead, which fortunately is not removed by `PromoteTemps` --- .../src/const_prop_lint.rs | 28 ++- .../lint-exceeding-bitshifts.noopt.stderr | 194 +++++++++++++++++- .../lint/lint-exceeding-bitshifts.opt.stderr | 10 +- ...-bitshifts.opt_with_overflow_checks.stderr | 194 +++++++++++++++++- .../overflowing-lsh-1.stderr | 10 +- .../overflowing-lsh-2.stderr | 10 +- .../overflowing-lsh-3.stderr | 10 +- .../overflowing-lsh-4.stderr | 10 +- .../overflowing-rsh-1.stderr | 10 +- .../overflowing-rsh-2.stderr | 10 +- .../overflowing-rsh-3.stderr | 10 +- .../overflowing-rsh-4.stderr | 10 +- .../overflowing-rsh-5.stderr | 10 +- .../overflowing-rsh-6.stderr | 10 +- 14 files changed, 507 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_mir_transform/src/const_prop_lint.rs b/compiler/rustc_mir_transform/src/const_prop_lint.rs index 99eecb567f277..18214b8f6bbcf 100644 --- a/compiler/rustc_mir_transform/src/const_prop_lint.rs +++ b/compiler/rustc_mir_transform/src/const_prop_lint.rs @@ -485,18 +485,30 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { .and_then(|op| self.ecx.read_immediate(&op).ok()) .map_or(DbgVal::Underscore, |op| DbgVal::Val(op.to_const_int())) }; - let msg = match msg { - AssertKind::DivisionByZero(op) => AssertKind::DivisionByZero(eval_to_int(op)), - AssertKind::RemainderByZero(op) => AssertKind::RemainderByZero(eval_to_int(op)), + let (msg, emit_overflow_lint) = match msg { + AssertKind::DivisionByZero(op) => { + (AssertKind::DivisionByZero(eval_to_int(op)), false) + } + AssertKind::RemainderByZero(op) => { + (AssertKind::RemainderByZero(eval_to_int(op)), false) + } AssertKind::Overflow(bin_op @ (BinOp::Div | BinOp::Rem), op1, op2) => { // Division overflow is *UB* in the MIR, and different than the // other overflow checks. - AssertKind::Overflow(*bin_op, eval_to_int(op1), eval_to_int(op2)) + (AssertKind::Overflow(*bin_op, eval_to_int(op1), eval_to_int(op2)), false) + } + AssertKind::Overflow(bin_op @ (BinOp::Shl | BinOp::Shr), op1, op2) => { + // A hack that fixes #117949 + // Ideally check_binary_op() should check these shift ops, + // but it can't because they are getting removed from the MIR + // during const promotion. So we check the associated asserts + // here instead as they are not removed by promotion. + (AssertKind::Overflow(*bin_op, eval_to_int(op1), eval_to_int(op2)), true) } AssertKind::BoundsCheck { ref len, ref index } => { let len = eval_to_int(len); let index = eval_to_int(index); - AssertKind::BoundsCheck { len, index } + (AssertKind::BoundsCheck { len, index }, false) } // Remaining overflow errors are already covered by checks on the binary operators. AssertKind::Overflow(..) | AssertKind::OverflowNeg(_) => return None, @@ -506,7 +518,11 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { let source_info = self.body().source_info(location); self.report_assert_as_lint( source_info, - AssertLint::UnconditionalPanic(source_info.span, msg), + if emit_overflow_lint { + AssertLint::ArithmeticOverflow(source_info.span, msg) + } else { + AssertLint::UnconditionalPanic(source_info.span, msg) + }, ); } diff --git a/tests/ui/lint/lint-exceeding-bitshifts.noopt.stderr b/tests/ui/lint/lint-exceeding-bitshifts.noopt.stderr index 3a84c6c1fb1f9..8049a55a54672 100644 --- a/tests/ui/lint/lint-exceeding-bitshifts.noopt.stderr +++ b/tests/ui/lint/lint-exceeding-bitshifts.noopt.stderr @@ -10,17 +10,41 @@ note: the lint level is defined here LL | #![warn(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:18:20 + | +LL | const N: i32 = T::N << 42; + | ^^^^^^^^^^ attempt to shift left by `42_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:22:13 | LL | let _ = x << 42; | ^^^^^^^ attempt to shift left by `42_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:22:13 + | +LL | let _ = x << 42; + | ^^^^^^^ attempt to shift left by `42_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:27:15 + | +LL | let n = 1u8 << 8; + | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:27:15 | LL | let n = 1u8 << 8; | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:29:15 @@ -28,17 +52,41 @@ warning: this arithmetic operation will overflow LL | let n = 1u16 << 16; | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:29:15 + | +LL | let n = 1u16 << 16; + | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:31:15 | LL | let n = 1u32 << 32; | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:31:15 + | +LL | let n = 1u32 << 32; + | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:33:15 + | +LL | let n = 1u64 << 64; + | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:33:15 | LL | let n = 1u64 << 64; | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:35:15 @@ -46,17 +94,41 @@ warning: this arithmetic operation will overflow LL | let n = 1i8 << 8; | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:35:15 + | +LL | let n = 1i8 << 8; + | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:37:15 | LL | let n = 1i16 << 16; | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:37:15 + | +LL | let n = 1i16 << 16; + | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:39:15 + | +LL | let n = 1i32 << 32; + | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:39:15 | LL | let n = 1i32 << 32; | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:41:15 @@ -64,17 +136,41 @@ warning: this arithmetic operation will overflow LL | let n = 1i64 << 64; | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:41:15 + | +LL | let n = 1i64 << 64; + | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:44:15 | LL | let n = 1u8 >> 8; | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:44:15 + | +LL | let n = 1u8 >> 8; + | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:46:15 + | +LL | let n = 1u16 >> 16; + | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:46:15 | LL | let n = 1u16 >> 16; | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:48:15 @@ -82,17 +178,41 @@ warning: this arithmetic operation will overflow LL | let n = 1u32 >> 32; | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:48:15 + | +LL | let n = 1u32 >> 32; + | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:50:15 | LL | let n = 1u64 >> 64; | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:50:15 + | +LL | let n = 1u64 >> 64; + | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:52:15 + | +LL | let n = 1i8 >> 8; + | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:52:15 | LL | let n = 1i8 >> 8; | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:54:15 @@ -100,17 +220,41 @@ warning: this arithmetic operation will overflow LL | let n = 1i16 >> 16; | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:54:15 + | +LL | let n = 1i16 >> 16; + | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:56:15 | LL | let n = 1i32 >> 32; | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:56:15 + | +LL | let n = 1i32 >> 32; + | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:58:15 + | +LL | let n = 1i64 >> 64; + | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:58:15 | LL | let n = 1i64 >> 64; | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:62:15 @@ -118,17 +262,41 @@ warning: this arithmetic operation will overflow LL | let n = n << 8; | ^^^^^^ attempt to shift left by `8_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:62:15 + | +LL | let n = n << 8; + | ^^^^^^ attempt to shift left by `8_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:64:15 | LL | let n = 1u8 << -8; | ^^^^^^^^^ attempt to shift left by `-8_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:64:15 + | +LL | let n = 1u8 << -8; + | ^^^^^^^^^ attempt to shift left by `-8_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:69:15 + | +LL | let n = 1u8 << (4+4); + | ^^^^^^^^^^^^ attempt to shift left by `8_i32`, which would overflow + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:69:15 | LL | let n = 1u8 << (4+4); | ^^^^^^^^^^^^ attempt to shift left by `8_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:71:15 @@ -136,17 +304,41 @@ warning: this arithmetic operation will overflow LL | let n = 1i64 >> [64][0]; | ^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:71:15 + | +LL | let n = 1i64 >> [64][0]; + | ^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:77:15 | LL | let n = 1_isize << BITS; | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:77:15 + | +LL | let n = 1_isize << BITS; + | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:78:15 + | +LL | let n = 1_usize << BITS; + | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:78:15 | LL | let n = 1_usize << BITS; | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -warning: 24 warnings emitted +warning: 48 warnings emitted diff --git a/tests/ui/lint/lint-exceeding-bitshifts.opt.stderr b/tests/ui/lint/lint-exceeding-bitshifts.opt.stderr index 3a84c6c1fb1f9..71ccbceff3375 100644 --- a/tests/ui/lint/lint-exceeding-bitshifts.opt.stderr +++ b/tests/ui/lint/lint-exceeding-bitshifts.opt.stderr @@ -10,6 +10,14 @@ note: the lint level is defined here LL | #![warn(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:18:20 + | +LL | const N: i32 = T::N << 42; + | ^^^^^^^^^^ attempt to shift left by `42_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:22:13 | @@ -148,5 +156,5 @@ warning: this arithmetic operation will overflow LL | let n = 1_usize << BITS; | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow -warning: 24 warnings emitted +warning: 25 warnings emitted diff --git a/tests/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr b/tests/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr index 3a84c6c1fb1f9..8049a55a54672 100644 --- a/tests/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr +++ b/tests/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr @@ -10,17 +10,41 @@ note: the lint level is defined here LL | #![warn(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:18:20 + | +LL | const N: i32 = T::N << 42; + | ^^^^^^^^^^ attempt to shift left by `42_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:22:13 | LL | let _ = x << 42; | ^^^^^^^ attempt to shift left by `42_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:22:13 + | +LL | let _ = x << 42; + | ^^^^^^^ attempt to shift left by `42_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:27:15 + | +LL | let n = 1u8 << 8; + | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:27:15 | LL | let n = 1u8 << 8; | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:29:15 @@ -28,17 +52,41 @@ warning: this arithmetic operation will overflow LL | let n = 1u16 << 16; | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:29:15 + | +LL | let n = 1u16 << 16; + | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:31:15 | LL | let n = 1u32 << 32; | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:31:15 + | +LL | let n = 1u32 << 32; + | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:33:15 + | +LL | let n = 1u64 << 64; + | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:33:15 | LL | let n = 1u64 << 64; | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:35:15 @@ -46,17 +94,41 @@ warning: this arithmetic operation will overflow LL | let n = 1i8 << 8; | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:35:15 + | +LL | let n = 1i8 << 8; + | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:37:15 | LL | let n = 1i16 << 16; | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:37:15 + | +LL | let n = 1i16 << 16; + | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:39:15 + | +LL | let n = 1i32 << 32; + | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:39:15 | LL | let n = 1i32 << 32; | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:41:15 @@ -64,17 +136,41 @@ warning: this arithmetic operation will overflow LL | let n = 1i64 << 64; | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:41:15 + | +LL | let n = 1i64 << 64; + | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:44:15 | LL | let n = 1u8 >> 8; | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:44:15 + | +LL | let n = 1u8 >> 8; + | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:46:15 + | +LL | let n = 1u16 >> 16; + | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:46:15 | LL | let n = 1u16 >> 16; | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:48:15 @@ -82,17 +178,41 @@ warning: this arithmetic operation will overflow LL | let n = 1u32 >> 32; | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:48:15 + | +LL | let n = 1u32 >> 32; + | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:50:15 | LL | let n = 1u64 >> 64; | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:50:15 + | +LL | let n = 1u64 >> 64; + | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:52:15 + | +LL | let n = 1i8 >> 8; + | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:52:15 | LL | let n = 1i8 >> 8; | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:54:15 @@ -100,17 +220,41 @@ warning: this arithmetic operation will overflow LL | let n = 1i16 >> 16; | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:54:15 + | +LL | let n = 1i16 >> 16; + | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:56:15 | LL | let n = 1i32 >> 32; | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:56:15 + | +LL | let n = 1i32 >> 32; + | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:58:15 + | +LL | let n = 1i64 >> 64; + | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:58:15 | LL | let n = 1i64 >> 64; | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:62:15 @@ -118,17 +262,41 @@ warning: this arithmetic operation will overflow LL | let n = n << 8; | ^^^^^^ attempt to shift left by `8_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:62:15 + | +LL | let n = n << 8; + | ^^^^^^ attempt to shift left by `8_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:64:15 | LL | let n = 1u8 << -8; | ^^^^^^^^^ attempt to shift left by `-8_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:64:15 + | +LL | let n = 1u8 << -8; + | ^^^^^^^^^ attempt to shift left by `-8_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:69:15 + | +LL | let n = 1u8 << (4+4); + | ^^^^^^^^^^^^ attempt to shift left by `8_i32`, which would overflow + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:69:15 | LL | let n = 1u8 << (4+4); | ^^^^^^^^^^^^ attempt to shift left by `8_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:71:15 @@ -136,17 +304,41 @@ warning: this arithmetic operation will overflow LL | let n = 1i64 >> [64][0]; | ^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:71:15 + | +LL | let n = 1i64 >> [64][0]; + | ^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:77:15 | LL | let n = 1_isize << BITS; | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:77:15 + | +LL | let n = 1_isize << BITS; + | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +warning: this arithmetic operation will overflow + --> $DIR/lint-exceeding-bitshifts.rs:78:15 + | +LL | let n = 1_usize << BITS; + | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow + warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:78:15 | LL | let n = 1_usize << BITS; | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -warning: 24 warnings emitted +warning: 48 warnings emitted diff --git a/tests/ui/numbers-arithmetic/overflowing-lsh-1.stderr b/tests/ui/numbers-arithmetic/overflowing-lsh-1.stderr index 5d2c4a6c8e270..b808374a8fcbc 100644 --- a/tests/ui/numbers-arithmetic/overflowing-lsh-1.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-lsh-1.stderr @@ -10,5 +10,13 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: this arithmetic operation will overflow + --> $DIR/overflowing-lsh-1.rs:7:14 + | +LL | let _x = 1_i32 << 32; + | ^^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 2 previous errors diff --git a/tests/ui/numbers-arithmetic/overflowing-lsh-2.stderr b/tests/ui/numbers-arithmetic/overflowing-lsh-2.stderr index 8ac72aefe0dc0..3bba0889e76bf 100644 --- a/tests/ui/numbers-arithmetic/overflowing-lsh-2.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-lsh-2.stderr @@ -10,5 +10,13 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: this arithmetic operation will overflow + --> $DIR/overflowing-lsh-2.rs:7:14 + | +LL | let _x = 1 << -1; + | ^^^^^^^ attempt to shift left by `-1_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 2 previous errors diff --git a/tests/ui/numbers-arithmetic/overflowing-lsh-3.stderr b/tests/ui/numbers-arithmetic/overflowing-lsh-3.stderr index 43d541b030433..027a98cb02d50 100644 --- a/tests/ui/numbers-arithmetic/overflowing-lsh-3.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-lsh-3.stderr @@ -10,5 +10,13 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: this arithmetic operation will overflow + --> $DIR/overflowing-lsh-3.rs:7:14 + | +LL | let _x = 1_u64 << 64; + | ^^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 2 previous errors diff --git a/tests/ui/numbers-arithmetic/overflowing-lsh-4.stderr b/tests/ui/numbers-arithmetic/overflowing-lsh-4.stderr index 00a3581069f5b..b002fc6b38146 100644 --- a/tests/ui/numbers-arithmetic/overflowing-lsh-4.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-lsh-4.stderr @@ -10,5 +10,13 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: this arithmetic operation will overflow + --> $DIR/overflowing-lsh-4.rs:11:13 + | +LL | let x = 1_i8 << 17; + | ^^^^^^^^^^ attempt to shift left by `17_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 2 previous errors diff --git a/tests/ui/numbers-arithmetic/overflowing-rsh-1.stderr b/tests/ui/numbers-arithmetic/overflowing-rsh-1.stderr index 62763e9e1df8b..9d32482d68a54 100644 --- a/tests/ui/numbers-arithmetic/overflowing-rsh-1.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-rsh-1.stderr @@ -10,5 +10,13 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: this arithmetic operation will overflow + --> $DIR/overflowing-rsh-1.rs:7:14 + | +LL | let _x = -1_i32 >> 32; + | ^^^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 2 previous errors diff --git a/tests/ui/numbers-arithmetic/overflowing-rsh-2.stderr b/tests/ui/numbers-arithmetic/overflowing-rsh-2.stderr index 519e62fef7d89..08c845838dad7 100644 --- a/tests/ui/numbers-arithmetic/overflowing-rsh-2.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-rsh-2.stderr @@ -10,5 +10,13 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: this arithmetic operation will overflow + --> $DIR/overflowing-rsh-2.rs:7:14 + | +LL | let _x = -1_i32 >> -1; + | ^^^^^^^^^^^^ attempt to shift right by `-1_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 2 previous errors diff --git a/tests/ui/numbers-arithmetic/overflowing-rsh-3.stderr b/tests/ui/numbers-arithmetic/overflowing-rsh-3.stderr index de24ea1fcde93..41cfa79a0c5f2 100644 --- a/tests/ui/numbers-arithmetic/overflowing-rsh-3.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-rsh-3.stderr @@ -10,5 +10,13 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: this arithmetic operation will overflow + --> $DIR/overflowing-rsh-3.rs:7:14 + | +LL | let _x = -1_i64 >> 64; + | ^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 2 previous errors diff --git a/tests/ui/numbers-arithmetic/overflowing-rsh-4.stderr b/tests/ui/numbers-arithmetic/overflowing-rsh-4.stderr index 47588012fb692..2c1ced80a5afb 100644 --- a/tests/ui/numbers-arithmetic/overflowing-rsh-4.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-rsh-4.stderr @@ -10,5 +10,13 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: this arithmetic operation will overflow + --> $DIR/overflowing-rsh-4.rs:11:13 + | +LL | let x = 2_i8 >> 17; + | ^^^^^^^^^^ attempt to shift right by `17_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 2 previous errors diff --git a/tests/ui/numbers-arithmetic/overflowing-rsh-5.stderr b/tests/ui/numbers-arithmetic/overflowing-rsh-5.stderr index e9a1572d3cc9d..274a26db711b2 100644 --- a/tests/ui/numbers-arithmetic/overflowing-rsh-5.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-rsh-5.stderr @@ -10,5 +10,13 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: this arithmetic operation will overflow + --> $DIR/overflowing-rsh-5.rs:7:14 + | +LL | let _n = 1i64 >> [64][0]; + | ^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 2 previous errors diff --git a/tests/ui/numbers-arithmetic/overflowing-rsh-6.stderr b/tests/ui/numbers-arithmetic/overflowing-rsh-6.stderr index 005f7378226c1..c5fd78276afad 100644 --- a/tests/ui/numbers-arithmetic/overflowing-rsh-6.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-rsh-6.stderr @@ -10,5 +10,13 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: this arithmetic operation will overflow + --> $DIR/overflowing-rsh-6.rs:7:14 + | +LL | let _n = 1i64 >> [64][0]; + | ^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 2 previous errors From 2d8b401a7ee84064261c502c53453eda5ccf7367 Mon Sep 17 00:00:00 2001 From: Gurinder Singh Date: Fri, 29 Dec 2023 09:35:07 +0530 Subject: [PATCH 2/2] Remove the now redundant checks for shifts in check_binary_op() --- .../src/const_prop_lint.rs | 41 +--- .../lint-exceeding-bitshifts.noopt.stderr | 194 +----------------- .../lint/lint-exceeding-bitshifts.opt.stderr | 148 +------------ ...-bitshifts.opt_with_overflow_checks.stderr | 194 +----------------- .../overflowing-lsh-1.stderr | 10 +- .../overflowing-lsh-2.stderr | 10 +- .../overflowing-lsh-3.stderr | 10 +- .../overflowing-lsh-4.stderr | 10 +- .../overflowing-rsh-1.stderr | 10 +- .../overflowing-rsh-2.stderr | 10 +- .../overflowing-rsh-3.stderr | 10 +- .../overflowing-rsh-4.stderr | 10 +- .../overflowing-rsh-5.stderr | 10 +- .../overflowing-rsh-6.stderr | 10 +- 14 files changed, 19 insertions(+), 658 deletions(-) diff --git a/compiler/rustc_mir_transform/src/const_prop_lint.rs b/compiler/rustc_mir_transform/src/const_prop_lint.rs index 18214b8f6bbcf..42ad7cc9f806e 100644 --- a/compiler/rustc_mir_transform/src/const_prop_lint.rs +++ b/compiler/rustc_mir_transform/src/const_prop_lint.rs @@ -17,9 +17,7 @@ use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::*; use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout}; use rustc_middle::ty::GenericArgs; -use rustc_middle::ty::{ - self, ConstInt, Instance, ParamEnv, ScalarInt, Ty, TyCtxt, TypeVisitableExt, -}; +use rustc_middle::ty::{self, Instance, ParamEnv, Ty, TyCtxt, TypeVisitableExt}; use rustc_span::Span; use rustc_target::abi::{HasDataLayout, Size, TargetDataLayout}; @@ -312,43 +310,16 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { right: &Operand<'tcx>, location: Location, ) -> Option<()> { + if matches!(op, BinOp::Shr | BinOp::Shl) { + // Shifts are linted in check_assertion() not here + return None; + } + let r = self.use_ecx(location, |this| { this.ecx.read_immediate(&this.ecx.eval_operand(right, None)?) }); let l = self .use_ecx(location, |this| this.ecx.read_immediate(&this.ecx.eval_operand(left, None)?)); - // Check for exceeding shifts *even if* we cannot evaluate the LHS. - if matches!(op, BinOp::Shr | BinOp::Shl) { - let r = r.clone()?; - // We need the type of the LHS. We cannot use `place_layout` as that is the type - // of the result, which for checked binops is not the same! - let left_ty = left.ty(self.local_decls(), self.tcx); - let left_size = self.ecx.layout_of(left_ty).ok()?.size; - let right_size = r.layout.size; - let r_bits = r.to_scalar().to_bits(right_size).ok(); - if r_bits.is_some_and(|b| b >= left_size.bits() as u128) { - debug!("check_binary_op: reporting assert for {:?}", location); - let source_info = self.body().source_info(location); - let panic = AssertKind::Overflow( - op, - match l { - Some(l) => l.to_const_int(), - // Invent a dummy value, the diagnostic ignores it anyway - None => ConstInt::new( - ScalarInt::try_from_uint(1_u8, left_size).unwrap(), - left_ty.is_signed(), - left_ty.is_ptr_sized_integral(), - ), - }, - r.to_const_int(), - ); - self.report_assert_as_lint( - source_info, - AssertLint::ArithmeticOverflow(source_info.span, panic), - ); - return None; - } - } if let (Some(l), Some(r)) = (l, r) { // The remaining operators are handled through `overflowing_binary_op`. diff --git a/tests/ui/lint/lint-exceeding-bitshifts.noopt.stderr b/tests/ui/lint/lint-exceeding-bitshifts.noopt.stderr index 8049a55a54672..3a84c6c1fb1f9 100644 --- a/tests/ui/lint/lint-exceeding-bitshifts.noopt.stderr +++ b/tests/ui/lint/lint-exceeding-bitshifts.noopt.stderr @@ -10,41 +10,17 @@ note: the lint level is defined here LL | #![warn(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:18:20 - | -LL | const N: i32 = T::N << 42; - | ^^^^^^^^^^ attempt to shift left by `42_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:22:13 | LL | let _ = x << 42; | ^^^^^^^ attempt to shift left by `42_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:22:13 - | -LL | let _ = x << 42; - | ^^^^^^^ attempt to shift left by `42_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:27:15 - | -LL | let n = 1u8 << 8; - | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:27:15 | LL | let n = 1u8 << 8; | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:29:15 @@ -52,41 +28,17 @@ warning: this arithmetic operation will overflow LL | let n = 1u16 << 16; | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:29:15 - | -LL | let n = 1u16 << 16; - | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:31:15 | LL | let n = 1u32 << 32; | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:31:15 - | -LL | let n = 1u32 << 32; - | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:33:15 - | -LL | let n = 1u64 << 64; - | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:33:15 | LL | let n = 1u64 << 64; | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:35:15 @@ -94,41 +46,17 @@ warning: this arithmetic operation will overflow LL | let n = 1i8 << 8; | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:35:15 - | -LL | let n = 1i8 << 8; - | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:37:15 | LL | let n = 1i16 << 16; | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:37:15 - | -LL | let n = 1i16 << 16; - | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:39:15 - | -LL | let n = 1i32 << 32; - | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:39:15 | LL | let n = 1i32 << 32; | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:41:15 @@ -136,41 +64,17 @@ warning: this arithmetic operation will overflow LL | let n = 1i64 << 64; | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:41:15 - | -LL | let n = 1i64 << 64; - | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:44:15 | LL | let n = 1u8 >> 8; | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:44:15 - | -LL | let n = 1u8 >> 8; - | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:46:15 - | -LL | let n = 1u16 >> 16; - | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:46:15 | LL | let n = 1u16 >> 16; | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:48:15 @@ -178,41 +82,17 @@ warning: this arithmetic operation will overflow LL | let n = 1u32 >> 32; | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:48:15 - | -LL | let n = 1u32 >> 32; - | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:50:15 | LL | let n = 1u64 >> 64; | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:50:15 - | -LL | let n = 1u64 >> 64; - | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:52:15 - | -LL | let n = 1i8 >> 8; - | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:52:15 | LL | let n = 1i8 >> 8; | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:54:15 @@ -220,41 +100,17 @@ warning: this arithmetic operation will overflow LL | let n = 1i16 >> 16; | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:54:15 - | -LL | let n = 1i16 >> 16; - | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:56:15 | LL | let n = 1i32 >> 32; | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:56:15 - | -LL | let n = 1i32 >> 32; - | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:58:15 - | -LL | let n = 1i64 >> 64; - | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:58:15 | LL | let n = 1i64 >> 64; | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:62:15 @@ -262,41 +118,17 @@ warning: this arithmetic operation will overflow LL | let n = n << 8; | ^^^^^^ attempt to shift left by `8_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:62:15 - | -LL | let n = n << 8; - | ^^^^^^ attempt to shift left by `8_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:64:15 | LL | let n = 1u8 << -8; | ^^^^^^^^^ attempt to shift left by `-8_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:64:15 - | -LL | let n = 1u8 << -8; - | ^^^^^^^^^ attempt to shift left by `-8_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:69:15 - | -LL | let n = 1u8 << (4+4); - | ^^^^^^^^^^^^ attempt to shift left by `8_i32`, which would overflow - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:69:15 | LL | let n = 1u8 << (4+4); | ^^^^^^^^^^^^ attempt to shift left by `8_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:71:15 @@ -304,41 +136,17 @@ warning: this arithmetic operation will overflow LL | let n = 1i64 >> [64][0]; | ^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:71:15 - | -LL | let n = 1i64 >> [64][0]; - | ^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:77:15 | LL | let n = 1_isize << BITS; | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:77:15 - | -LL | let n = 1_isize << BITS; - | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:78:15 - | -LL | let n = 1_usize << BITS; - | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:78:15 | LL | let n = 1_usize << BITS; | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -warning: 48 warnings emitted +warning: 24 warnings emitted diff --git a/tests/ui/lint/lint-exceeding-bitshifts.opt.stderr b/tests/ui/lint/lint-exceeding-bitshifts.opt.stderr index 71ccbceff3375..77cea4b495235 100644 --- a/tests/ui/lint/lint-exceeding-bitshifts.opt.stderr +++ b/tests/ui/lint/lint-exceeding-bitshifts.opt.stderr @@ -10,151 +10,5 @@ note: the lint level is defined here LL | #![warn(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:18:20 - | -LL | const N: i32 = T::N << 42; - | ^^^^^^^^^^ attempt to shift left by `42_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:22:13 - | -LL | let _ = x << 42; - | ^^^^^^^ attempt to shift left by `42_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:27:15 - | -LL | let n = 1u8 << 8; - | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:29:15 - | -LL | let n = 1u16 << 16; - | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:31:15 - | -LL | let n = 1u32 << 32; - | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:33:15 - | -LL | let n = 1u64 << 64; - | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:35:15 - | -LL | let n = 1i8 << 8; - | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:37:15 - | -LL | let n = 1i16 << 16; - | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:39:15 - | -LL | let n = 1i32 << 32; - | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:41:15 - | -LL | let n = 1i64 << 64; - | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:44:15 - | -LL | let n = 1u8 >> 8; - | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:46:15 - | -LL | let n = 1u16 >> 16; - | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:48:15 - | -LL | let n = 1u32 >> 32; - | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:50:15 - | -LL | let n = 1u64 >> 64; - | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:52:15 - | -LL | let n = 1i8 >> 8; - | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:54:15 - | -LL | let n = 1i16 >> 16; - | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:56:15 - | -LL | let n = 1i32 >> 32; - | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:58:15 - | -LL | let n = 1i64 >> 64; - | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:62:15 - | -LL | let n = n << 8; - | ^^^^^^ attempt to shift left by `8_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:64:15 - | -LL | let n = 1u8 << -8; - | ^^^^^^^^^ attempt to shift left by `-8_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:69:15 - | -LL | let n = 1u8 << (4+4); - | ^^^^^^^^^^^^ attempt to shift left by `8_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:71:15 - | -LL | let n = 1i64 >> [64][0]; - | ^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:77:15 - | -LL | let n = 1_isize << BITS; - | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:78:15 - | -LL | let n = 1_usize << BITS; - | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow - -warning: 25 warnings emitted +warning: 1 warning emitted diff --git a/tests/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr b/tests/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr index 8049a55a54672..3a84c6c1fb1f9 100644 --- a/tests/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr +++ b/tests/ui/lint/lint-exceeding-bitshifts.opt_with_overflow_checks.stderr @@ -10,41 +10,17 @@ note: the lint level is defined here LL | #![warn(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:18:20 - | -LL | const N: i32 = T::N << 42; - | ^^^^^^^^^^ attempt to shift left by `42_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:22:13 | LL | let _ = x << 42; | ^^^^^^^ attempt to shift left by `42_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:22:13 - | -LL | let _ = x << 42; - | ^^^^^^^ attempt to shift left by `42_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:27:15 - | -LL | let n = 1u8 << 8; - | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:27:15 | LL | let n = 1u8 << 8; | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:29:15 @@ -52,41 +28,17 @@ warning: this arithmetic operation will overflow LL | let n = 1u16 << 16; | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:29:15 - | -LL | let n = 1u16 << 16; - | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:31:15 | LL | let n = 1u32 << 32; | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:31:15 - | -LL | let n = 1u32 << 32; - | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:33:15 - | -LL | let n = 1u64 << 64; - | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:33:15 | LL | let n = 1u64 << 64; | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:35:15 @@ -94,41 +46,17 @@ warning: this arithmetic operation will overflow LL | let n = 1i8 << 8; | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:35:15 - | -LL | let n = 1i8 << 8; - | ^^^^^^^^ attempt to shift left by `8_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:37:15 | LL | let n = 1i16 << 16; | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:37:15 - | -LL | let n = 1i16 << 16; - | ^^^^^^^^^^ attempt to shift left by `16_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:39:15 - | -LL | let n = 1i32 << 32; - | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:39:15 | LL | let n = 1i32 << 32; | ^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:41:15 @@ -136,41 +64,17 @@ warning: this arithmetic operation will overflow LL | let n = 1i64 << 64; | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:41:15 - | -LL | let n = 1i64 << 64; - | ^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:44:15 | LL | let n = 1u8 >> 8; | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:44:15 - | -LL | let n = 1u8 >> 8; - | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:46:15 - | -LL | let n = 1u16 >> 16; - | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:46:15 | LL | let n = 1u16 >> 16; | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:48:15 @@ -178,41 +82,17 @@ warning: this arithmetic operation will overflow LL | let n = 1u32 >> 32; | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:48:15 - | -LL | let n = 1u32 >> 32; - | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:50:15 | LL | let n = 1u64 >> 64; | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:50:15 - | -LL | let n = 1u64 >> 64; - | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:52:15 - | -LL | let n = 1i8 >> 8; - | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:52:15 | LL | let n = 1i8 >> 8; | ^^^^^^^^ attempt to shift right by `8_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:54:15 @@ -220,41 +100,17 @@ warning: this arithmetic operation will overflow LL | let n = 1i16 >> 16; | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:54:15 - | -LL | let n = 1i16 >> 16; - | ^^^^^^^^^^ attempt to shift right by `16_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:56:15 | LL | let n = 1i32 >> 32; | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:56:15 - | -LL | let n = 1i32 >> 32; - | ^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:58:15 - | -LL | let n = 1i64 >> 64; - | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:58:15 | LL | let n = 1i64 >> 64; | ^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:62:15 @@ -262,41 +118,17 @@ warning: this arithmetic operation will overflow LL | let n = n << 8; | ^^^^^^ attempt to shift left by `8_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:62:15 - | -LL | let n = n << 8; - | ^^^^^^ attempt to shift left by `8_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:64:15 | LL | let n = 1u8 << -8; | ^^^^^^^^^ attempt to shift left by `-8_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:64:15 - | -LL | let n = 1u8 << -8; - | ^^^^^^^^^ attempt to shift left by `-8_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:69:15 - | -LL | let n = 1u8 << (4+4); - | ^^^^^^^^^^^^ attempt to shift left by `8_i32`, which would overflow - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:69:15 | LL | let n = 1u8 << (4+4); | ^^^^^^^^^^^^ attempt to shift left by `8_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:71:15 @@ -304,41 +136,17 @@ warning: this arithmetic operation will overflow LL | let n = 1i64 >> [64][0]; | ^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:71:15 - | -LL | let n = 1i64 >> [64][0]; - | ^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:77:15 | LL | let n = 1_isize << BITS; | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:77:15 - | -LL | let n = 1_isize << BITS; - | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -warning: this arithmetic operation will overflow - --> $DIR/lint-exceeding-bitshifts.rs:78:15 - | -LL | let n = 1_usize << BITS; - | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow - warning: this arithmetic operation will overflow --> $DIR/lint-exceeding-bitshifts.rs:78:15 | LL | let n = 1_usize << BITS; | ^^^^^^^^^^^^^^^ attempt to shift left by `%BITS%`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -warning: 48 warnings emitted +warning: 24 warnings emitted diff --git a/tests/ui/numbers-arithmetic/overflowing-lsh-1.stderr b/tests/ui/numbers-arithmetic/overflowing-lsh-1.stderr index b808374a8fcbc..5d2c4a6c8e270 100644 --- a/tests/ui/numbers-arithmetic/overflowing-lsh-1.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-lsh-1.stderr @@ -10,13 +10,5 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: this arithmetic operation will overflow - --> $DIR/overflowing-lsh-1.rs:7:14 - | -LL | let _x = 1_i32 << 32; - | ^^^^^^^^^^^ attempt to shift left by `32_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error diff --git a/tests/ui/numbers-arithmetic/overflowing-lsh-2.stderr b/tests/ui/numbers-arithmetic/overflowing-lsh-2.stderr index 3bba0889e76bf..8ac72aefe0dc0 100644 --- a/tests/ui/numbers-arithmetic/overflowing-lsh-2.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-lsh-2.stderr @@ -10,13 +10,5 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: this arithmetic operation will overflow - --> $DIR/overflowing-lsh-2.rs:7:14 - | -LL | let _x = 1 << -1; - | ^^^^^^^ attempt to shift left by `-1_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error diff --git a/tests/ui/numbers-arithmetic/overflowing-lsh-3.stderr b/tests/ui/numbers-arithmetic/overflowing-lsh-3.stderr index 027a98cb02d50..43d541b030433 100644 --- a/tests/ui/numbers-arithmetic/overflowing-lsh-3.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-lsh-3.stderr @@ -10,13 +10,5 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: this arithmetic operation will overflow - --> $DIR/overflowing-lsh-3.rs:7:14 - | -LL | let _x = 1_u64 << 64; - | ^^^^^^^^^^^ attempt to shift left by `64_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error diff --git a/tests/ui/numbers-arithmetic/overflowing-lsh-4.stderr b/tests/ui/numbers-arithmetic/overflowing-lsh-4.stderr index b002fc6b38146..00a3581069f5b 100644 --- a/tests/ui/numbers-arithmetic/overflowing-lsh-4.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-lsh-4.stderr @@ -10,13 +10,5 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: this arithmetic operation will overflow - --> $DIR/overflowing-lsh-4.rs:11:13 - | -LL | let x = 1_i8 << 17; - | ^^^^^^^^^^ attempt to shift left by `17_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error diff --git a/tests/ui/numbers-arithmetic/overflowing-rsh-1.stderr b/tests/ui/numbers-arithmetic/overflowing-rsh-1.stderr index 9d32482d68a54..62763e9e1df8b 100644 --- a/tests/ui/numbers-arithmetic/overflowing-rsh-1.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-rsh-1.stderr @@ -10,13 +10,5 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: this arithmetic operation will overflow - --> $DIR/overflowing-rsh-1.rs:7:14 - | -LL | let _x = -1_i32 >> 32; - | ^^^^^^^^^^^^ attempt to shift right by `32_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error diff --git a/tests/ui/numbers-arithmetic/overflowing-rsh-2.stderr b/tests/ui/numbers-arithmetic/overflowing-rsh-2.stderr index 08c845838dad7..519e62fef7d89 100644 --- a/tests/ui/numbers-arithmetic/overflowing-rsh-2.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-rsh-2.stderr @@ -10,13 +10,5 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: this arithmetic operation will overflow - --> $DIR/overflowing-rsh-2.rs:7:14 - | -LL | let _x = -1_i32 >> -1; - | ^^^^^^^^^^^^ attempt to shift right by `-1_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error diff --git a/tests/ui/numbers-arithmetic/overflowing-rsh-3.stderr b/tests/ui/numbers-arithmetic/overflowing-rsh-3.stderr index 41cfa79a0c5f2..de24ea1fcde93 100644 --- a/tests/ui/numbers-arithmetic/overflowing-rsh-3.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-rsh-3.stderr @@ -10,13 +10,5 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: this arithmetic operation will overflow - --> $DIR/overflowing-rsh-3.rs:7:14 - | -LL | let _x = -1_i64 >> 64; - | ^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error diff --git a/tests/ui/numbers-arithmetic/overflowing-rsh-4.stderr b/tests/ui/numbers-arithmetic/overflowing-rsh-4.stderr index 2c1ced80a5afb..47588012fb692 100644 --- a/tests/ui/numbers-arithmetic/overflowing-rsh-4.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-rsh-4.stderr @@ -10,13 +10,5 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: this arithmetic operation will overflow - --> $DIR/overflowing-rsh-4.rs:11:13 - | -LL | let x = 2_i8 >> 17; - | ^^^^^^^^^^ attempt to shift right by `17_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error diff --git a/tests/ui/numbers-arithmetic/overflowing-rsh-5.stderr b/tests/ui/numbers-arithmetic/overflowing-rsh-5.stderr index 274a26db711b2..e9a1572d3cc9d 100644 --- a/tests/ui/numbers-arithmetic/overflowing-rsh-5.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-rsh-5.stderr @@ -10,13 +10,5 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: this arithmetic operation will overflow - --> $DIR/overflowing-rsh-5.rs:7:14 - | -LL | let _n = 1i64 >> [64][0]; - | ^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error diff --git a/tests/ui/numbers-arithmetic/overflowing-rsh-6.stderr b/tests/ui/numbers-arithmetic/overflowing-rsh-6.stderr index c5fd78276afad..005f7378226c1 100644 --- a/tests/ui/numbers-arithmetic/overflowing-rsh-6.stderr +++ b/tests/ui/numbers-arithmetic/overflowing-rsh-6.stderr @@ -10,13 +10,5 @@ note: the lint level is defined here LL | #![deny(arithmetic_overflow)] | ^^^^^^^^^^^^^^^^^^^ -error: this arithmetic operation will overflow - --> $DIR/overflowing-rsh-6.rs:7:14 - | -LL | let _n = 1i64 >> [64][0]; - | ^^^^^^^^^^^^^^^ attempt to shift right by `64_i32`, which would overflow - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error