left: &Operand<'tcx>,
right: &Operand<'tcx>,
source_info: SourceInfo,
- place_layout: TyLayout<'tcx>,
) -> Option<()> {
let r =
self.use_ecx(|this| this.ecx.read_immediate(this.ecx.eval_operand(right, None)?))?;
// Check for exceeding shifts *even if* we cannot evaluate the LHS.
if op == BinOp::Shr || op == BinOp::Shl {
- let left_bits = place_layout.size.bits();
+ // 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_bits = self.ecx.layout_of(left_ty).ok()?.size.bits();
let right_size = r.layout.size;
let r_bits = r.to_scalar().and_then(|r| r.to_bits(right_size));
- if r_bits.map_or(false, |b| b >= left_bits as u128) {
+ if r_bits.map_or(false, |b| b >= left_size_bits as u128) {
self.report_assert_as_lint(
lint::builtin::EXCEEDING_BITSHIFTS,
source_info,
}
Rvalue::BinaryOp(op, left, right) => {
trace!("checking BinaryOp(op = {:?}, left = {:?}, right = {:?})", op, left, right);
- self.check_binary_op(*op, left, right, source_info, place_layout)?;
+ self.check_binary_op(*op, left, right, source_info)?;
}
Rvalue::CheckedBinaryOp(op, left, right) => {
trace!(
left,
right
);
- self.check_binary_op(*op, left, right, source_info, place_layout)?;
+ self.check_binary_op(*op, left, right, source_info)?;
}
// Do not try creating references (#67862)
--- /dev/null
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:22:13
+ |
+LL | let _ = x << 42;
+ | ^^^^^^^ attempt to shift left with overflow
+ |
+note: the lint level is defined here
+ --> $DIR/lint-exceeding-bitshifts.rs:9:9
+ |
+LL | #![deny(exceeding_bitshifts, const_err)]
+ | ^^^^^^^^^^^^^^^^^^^
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:27:15
+ |
+LL | let n = 1u8 << 8;
+ | ^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:29:15
+ |
+LL | let n = 1u16 << 16;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:31:15
+ |
+LL | let n = 1u32 << 32;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:33:15
+ |
+LL | let n = 1u64 << 64;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:35:15
+ |
+LL | let n = 1i8 << 8;
+ | ^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:37:15
+ |
+LL | let n = 1i16 << 16;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:39:15
+ |
+LL | let n = 1i32 << 32;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:41:15
+ |
+LL | let n = 1i64 << 64;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:44:15
+ |
+LL | let n = 1u8 >> 8;
+ | ^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:46:15
+ |
+LL | let n = 1u16 >> 16;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:48:15
+ |
+LL | let n = 1u32 >> 32;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:50:15
+ |
+LL | let n = 1u64 >> 64;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:52:15
+ |
+LL | let n = 1i8 >> 8;
+ | ^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:54:15
+ |
+LL | let n = 1i16 >> 16;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:56:15
+ |
+LL | let n = 1i32 >> 32;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:58:15
+ |
+LL | let n = 1i64 >> 64;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:62:15
+ |
+LL | let n = n << 8;
+ | ^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:64:15
+ |
+LL | let n = 1u8 << -8;
+ | ^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:69:15
+ |
+LL | let n = 1u8 << (4+4);
+ | ^^^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:71:15
+ |
+LL | let n = 1i64 >> [64][0];
+ | ^^^^^^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:77:15
+ |
+LL | let n = 1_isize << BITS;
+ | ^^^^^^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:78:15
+ |
+LL | let n = 1_usize << BITS;
+ | ^^^^^^^^^^^^^^^ attempt to shift left with overflow
+
+error: aborting due to 23 previous errors
+
--- /dev/null
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:22:13
+ |
+LL | let _ = x << 42;
+ | ^^^^^^^ attempt to shift left with overflow
+ |
+note: the lint level is defined here
+ --> $DIR/lint-exceeding-bitshifts.rs:9:9
+ |
+LL | #![deny(exceeding_bitshifts, const_err)]
+ | ^^^^^^^^^^^^^^^^^^^
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:27:15
+ |
+LL | let n = 1u8 << 8;
+ | ^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:29:15
+ |
+LL | let n = 1u16 << 16;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:31:15
+ |
+LL | let n = 1u32 << 32;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:33:15
+ |
+LL | let n = 1u64 << 64;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:35:15
+ |
+LL | let n = 1i8 << 8;
+ | ^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:37:15
+ |
+LL | let n = 1i16 << 16;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:39:15
+ |
+LL | let n = 1i32 << 32;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:41:15
+ |
+LL | let n = 1i64 << 64;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:44:15
+ |
+LL | let n = 1u8 >> 8;
+ | ^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:46:15
+ |
+LL | let n = 1u16 >> 16;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:48:15
+ |
+LL | let n = 1u32 >> 32;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:50:15
+ |
+LL | let n = 1u64 >> 64;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:52:15
+ |
+LL | let n = 1i8 >> 8;
+ | ^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:54:15
+ |
+LL | let n = 1i16 >> 16;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:56:15
+ |
+LL | let n = 1i32 >> 32;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:58:15
+ |
+LL | let n = 1i64 >> 64;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:62:15
+ |
+LL | let n = n << 8;
+ | ^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:64:15
+ |
+LL | let n = 1u8 << -8;
+ | ^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:69:15
+ |
+LL | let n = 1u8 << (4+4);
+ | ^^^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:71:15
+ |
+LL | let n = 1i64 >> [64][0];
+ | ^^^^^^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:77:15
+ |
+LL | let n = 1_isize << BITS;
+ | ^^^^^^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:78:15
+ |
+LL | let n = 1_usize << BITS;
+ | ^^^^^^^^^^^^^^^ attempt to shift left with overflow
+
+error: aborting due to 23 previous errors
+
--- /dev/null
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:22:13
+ |
+LL | let _ = x << 42;
+ | ^^^^^^^ attempt to shift left with overflow
+ |
+note: the lint level is defined here
+ --> $DIR/lint-exceeding-bitshifts.rs:9:9
+ |
+LL | #![deny(exceeding_bitshifts, const_err)]
+ | ^^^^^^^^^^^^^^^^^^^
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:27:15
+ |
+LL | let n = 1u8 << 8;
+ | ^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:29:15
+ |
+LL | let n = 1u16 << 16;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:31:15
+ |
+LL | let n = 1u32 << 32;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:33:15
+ |
+LL | let n = 1u64 << 64;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:35:15
+ |
+LL | let n = 1i8 << 8;
+ | ^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:37:15
+ |
+LL | let n = 1i16 << 16;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:39:15
+ |
+LL | let n = 1i32 << 32;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:41:15
+ |
+LL | let n = 1i64 << 64;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:44:15
+ |
+LL | let n = 1u8 >> 8;
+ | ^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:46:15
+ |
+LL | let n = 1u16 >> 16;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:48:15
+ |
+LL | let n = 1u32 >> 32;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:50:15
+ |
+LL | let n = 1u64 >> 64;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:52:15
+ |
+LL | let n = 1i8 >> 8;
+ | ^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:54:15
+ |
+LL | let n = 1i16 >> 16;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:56:15
+ |
+LL | let n = 1i32 >> 32;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:58:15
+ |
+LL | let n = 1i64 >> 64;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:62:15
+ |
+LL | let n = n << 8;
+ | ^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:64:15
+ |
+LL | let n = 1u8 << -8;
+ | ^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:69:15
+ |
+LL | let n = 1u8 << (4+4);
+ | ^^^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:71:15
+ |
+LL | let n = 1i64 >> [64][0];
+ | ^^^^^^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:77:15
+ |
+LL | let n = 1_isize << BITS;
+ | ^^^^^^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:78:15
+ |
+LL | let n = 1_usize << BITS;
+ | ^^^^^^^^^^^^^^^ attempt to shift left with overflow
+
+error: aborting due to 23 previous errors
+
--- /dev/null
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:22:13
+ |
+LL | let _ = x << 42;
+ | ^^^^^^^ attempt to shift left with overflow
+ |
+note: the lint level is defined here
+ --> $DIR/lint-exceeding-bitshifts.rs:9:9
+ |
+LL | #![deny(exceeding_bitshifts, const_err)]
+ | ^^^^^^^^^^^^^^^^^^^
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:27:15
+ |
+LL | let n = 1u8 << 8;
+ | ^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:29:15
+ |
+LL | let n = 1u16 << 16;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:31:15
+ |
+LL | let n = 1u32 << 32;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:33:15
+ |
+LL | let n = 1u64 << 64;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:35:15
+ |
+LL | let n = 1i8 << 8;
+ | ^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:37:15
+ |
+LL | let n = 1i16 << 16;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:39:15
+ |
+LL | let n = 1i32 << 32;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:41:15
+ |
+LL | let n = 1i64 << 64;
+ | ^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:44:15
+ |
+LL | let n = 1u8 >> 8;
+ | ^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:46:15
+ |
+LL | let n = 1u16 >> 16;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:48:15
+ |
+LL | let n = 1u32 >> 32;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:50:15
+ |
+LL | let n = 1u64 >> 64;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:52:15
+ |
+LL | let n = 1i8 >> 8;
+ | ^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:54:15
+ |
+LL | let n = 1i16 >> 16;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:56:15
+ |
+LL | let n = 1i32 >> 32;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:58:15
+ |
+LL | let n = 1i64 >> 64;
+ | ^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:62:15
+ |
+LL | let n = n << 8;
+ | ^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:64:15
+ |
+LL | let n = 1u8 << -8;
+ | ^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:69:15
+ |
+LL | let n = 1u8 << (4+4);
+ | ^^^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:71:15
+ |
+LL | let n = 1i64 >> [64][0];
+ | ^^^^^^^^^^^^^^^ attempt to shift right with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:77:15
+ |
+LL | let n = 1_isize << BITS;
+ | ^^^^^^^^^^^^^^^ attempt to shift left with overflow
+
+error: this arithmetic operation will overflow
+ --> $DIR/lint-exceeding-bitshifts.rs:78:15
+ |
+LL | let n = 1_usize << BITS;
+ | ^^^^^^^^^^^^^^^ attempt to shift left with overflow
+
+error: aborting due to 23 previous errors
+
+// revisions: default noopt opt opt_with_overflow_checks
+//[noopt]compile-flags: -C opt-level=0
+//[opt]compile-flags: -O
+//[opt_with_overflow_checks]compile-flags: -C overflow-checks=on -O
+
// build-fail
-// compile-flags: -O
+#![crate_type="lib"]
#![deny(exceeding_bitshifts, const_err)]
#![allow(unused_variables)]
#![allow(dead_code)]
-fn main() {
+pub trait Foo {
+ const N: i32;
+}
+
+impl<T: Foo> Foo for Vec<T> {
+ const N: i32 = T::N << 42; // FIXME this should warn
+}
+
+pub fn foo(x: i32) {
+ let _ = x << 42; //~ ERROR: arithmetic operation will overflow
+}
+
+pub fn main() {
let n = 1u8 << 7;
- let n = 1u8 << 8; //~ ERROR: attempt to shift left with overflow
+ let n = 1u8 << 8; //~ ERROR: arithmetic operation will overflow
let n = 1u16 << 15;
- let n = 1u16 << 16; //~ ERROR: attempt to shift left with overflow
+ let n = 1u16 << 16; //~ ERROR: arithmetic operation will overflow
let n = 1u32 << 31;
- let n = 1u32 << 32; //~ ERROR: attempt to shift left with overflow
+ let n = 1u32 << 32; //~ ERROR: arithmetic operation will overflow
let n = 1u64 << 63;
- let n = 1u64 << 64; //~ ERROR: attempt to shift left with overflow
+ let n = 1u64 << 64; //~ ERROR: arithmetic operation will overflow
let n = 1i8 << 7;
- let n = 1i8 << 8; //~ ERROR: attempt to shift left with overflow
+ let n = 1i8 << 8; //~ ERROR: arithmetic operation will overflow
let n = 1i16 << 15;
- let n = 1i16 << 16; //~ ERROR: attempt to shift left with overflow
+ let n = 1i16 << 16; //~ ERROR: arithmetic operation will overflow
let n = 1i32 << 31;
- let n = 1i32 << 32; //~ ERROR: attempt to shift left with overflow
+ let n = 1i32 << 32; //~ ERROR: arithmetic operation will overflow
let n = 1i64 << 63;
- let n = 1i64 << 64; //~ ERROR: attempt to shift left with overflow
+ let n = 1i64 << 64; //~ ERROR: arithmetic operation will overflow
let n = 1u8 >> 7;
- let n = 1u8 >> 8; //~ ERROR: attempt to shift right with overflow
+ let n = 1u8 >> 8; //~ ERROR: arithmetic operation will overflow
let n = 1u16 >> 15;
- let n = 1u16 >> 16; //~ ERROR: attempt to shift right with overflow
+ let n = 1u16 >> 16; //~ ERROR: arithmetic operation will overflow
let n = 1u32 >> 31;
- let n = 1u32 >> 32; //~ ERROR: attempt to shift right with overflow
+ let n = 1u32 >> 32; //~ ERROR: arithmetic operation will overflow
let n = 1u64 >> 63;
- let n = 1u64 >> 64; //~ ERROR: attempt to shift right with overflow
+ let n = 1u64 >> 64; //~ ERROR: arithmetic operation will overflow
let n = 1i8 >> 7;
- let n = 1i8 >> 8; //~ ERROR: attempt to shift right with overflow
+ let n = 1i8 >> 8; //~ ERROR: arithmetic operation will overflow
let n = 1i16 >> 15;
- let n = 1i16 >> 16; //~ ERROR: attempt to shift right with overflow
+ let n = 1i16 >> 16; //~ ERROR: arithmetic operation will overflow
let n = 1i32 >> 31;
- let n = 1i32 >> 32; //~ ERROR: attempt to shift right with overflow
+ let n = 1i32 >> 32; //~ ERROR: arithmetic operation will overflow
let n = 1i64 >> 63;
- let n = 1i64 >> 64; //~ ERROR: attempt to shift right with overflow
+ let n = 1i64 >> 64; //~ ERROR: arithmetic operation will overflow
let n = 1u8;
let n = n << 7;
- let n = n << 8; //~ ERROR: attempt to shift left with overflow
+ let n = n << 8; //~ ERROR: arithmetic operation will overflow
- let n = 1u8 << -8; //~ ERROR: attempt to shift left with overflow
+ let n = 1u8 << -8; //~ ERROR: arithmetic operation will overflow
let n = 1i8<<(1isize+-1);
+
+ let n = 1u8 << (4+3);
+ let n = 1u8 << (4+4); //~ ERROR: arithmetic operation will overflow
+ let n = 1i64 >> [63][0];
+ let n = 1i64 >> [64][0]; //~ ERROR: arithmetic operation will overflow
+
+ #[cfg(target_pointer_width = "32")]
+ const BITS: usize = 32;
+ #[cfg(target_pointer_width = "64")]
+ const BITS: usize = 64;
+ let n = 1_isize << BITS; //~ ERROR: arithmetic operation will overflow
+ let n = 1_usize << BITS; //~ ERROR: arithmetic operation will overflow
}
+++ /dev/null
-error: attempt to shift left with overflow
- --> $DIR/lint-exceeding-bitshifts.rs:10:15
- |
-LL | let n = 1u8 << 8;
- | ^^^^^^^^
- |
-note: the lint level is defined here
- --> $DIR/lint-exceeding-bitshifts.rs:4:9
- |
-LL | #![deny(exceeding_bitshifts, const_err)]
- | ^^^^^^^^^^^^^^^^^^^
-
-error: attempt to shift left with overflow
- --> $DIR/lint-exceeding-bitshifts.rs:12:15
- |
-LL | let n = 1u16 << 16;
- | ^^^^^^^^^^
-
-error: attempt to shift left with overflow
- --> $DIR/lint-exceeding-bitshifts.rs:14:15
- |
-LL | let n = 1u32 << 32;
- | ^^^^^^^^^^
-
-error: attempt to shift left with overflow
- --> $DIR/lint-exceeding-bitshifts.rs:16:15
- |
-LL | let n = 1u64 << 64;
- | ^^^^^^^^^^
-
-error: attempt to shift left with overflow
- --> $DIR/lint-exceeding-bitshifts.rs:18:15
- |
-LL | let n = 1i8 << 8;
- | ^^^^^^^^
-
-error: attempt to shift left with overflow
- --> $DIR/lint-exceeding-bitshifts.rs:20:15
- |
-LL | let n = 1i16 << 16;
- | ^^^^^^^^^^
-
-error: attempt to shift left with overflow
- --> $DIR/lint-exceeding-bitshifts.rs:22:15
- |
-LL | let n = 1i32 << 32;
- | ^^^^^^^^^^
-
-error: attempt to shift left with overflow
- --> $DIR/lint-exceeding-bitshifts.rs:24:15
- |
-LL | let n = 1i64 << 64;
- | ^^^^^^^^^^
-
-error: attempt to shift right with overflow
- --> $DIR/lint-exceeding-bitshifts.rs:27:15
- |
-LL | let n = 1u8 >> 8;
- | ^^^^^^^^
-
-error: attempt to shift right with overflow
- --> $DIR/lint-exceeding-bitshifts.rs:29:15
- |
-LL | let n = 1u16 >> 16;
- | ^^^^^^^^^^
-
-error: attempt to shift right with overflow
- --> $DIR/lint-exceeding-bitshifts.rs:31:15
- |
-LL | let n = 1u32 >> 32;
- | ^^^^^^^^^^
-
-error: attempt to shift right with overflow
- --> $DIR/lint-exceeding-bitshifts.rs:33:15
- |
-LL | let n = 1u64 >> 64;
- | ^^^^^^^^^^
-
-error: attempt to shift right with overflow
- --> $DIR/lint-exceeding-bitshifts.rs:35:15
- |
-LL | let n = 1i8 >> 8;
- | ^^^^^^^^
-
-error: attempt to shift right with overflow
- --> $DIR/lint-exceeding-bitshifts.rs:37:15
- |
-LL | let n = 1i16 >> 16;
- | ^^^^^^^^^^
-
-error: attempt to shift right with overflow
- --> $DIR/lint-exceeding-bitshifts.rs:39:15
- |
-LL | let n = 1i32 >> 32;
- | ^^^^^^^^^^
-
-error: attempt to shift right with overflow
- --> $DIR/lint-exceeding-bitshifts.rs:41:15
- |
-LL | let n = 1i64 >> 64;
- | ^^^^^^^^^^
-
-error: attempt to shift left with overflow
- --> $DIR/lint-exceeding-bitshifts.rs:45:15
- |
-LL | let n = n << 8;
- | ^^^^^^
-
-error: attempt to shift left with overflow
- --> $DIR/lint-exceeding-bitshifts.rs:47:15
- |
-LL | let n = 1u8 << -8;
- | ^^^^^^^^^
-
-error: aborting due to 18 previous errors
-
+++ /dev/null
-// build-fail
-// compile-flags: -O
-
-#![deny(exceeding_bitshifts, const_err)]
-#![allow(unused_variables)]
-#![allow(dead_code)]
-
-fn main() {
- let n = 1u8 << (4+3);
- let n = 1u8 << (4+4); //~ ERROR: attempt to shift left with overflow
- let n = 1i64 >> [63][0];
- let n = 1i64 >> [64][0]; //~ ERROR: attempt to shift right with overflow
-
- #[cfg(target_pointer_width = "32")]
- const BITS: usize = 32;
- #[cfg(target_pointer_width = "64")]
- const BITS: usize = 64;
- let n = 1_isize << BITS; //~ ERROR: attempt to shift left with overflow
- let n = 1_usize << BITS; //~ ERROR: attempt to shift left with overflow
-}
+++ /dev/null
-error: attempt to shift left with overflow
- --> $DIR/lint-exceeding-bitshifts2.rs:10:15
- |
-LL | let n = 1u8 << (4+4);
- | ^^^^^^^^^^^^
- |
-note: the lint level is defined here
- --> $DIR/lint-exceeding-bitshifts2.rs:4:9
- |
-LL | #![deny(exceeding_bitshifts, const_err)]
- | ^^^^^^^^^^^^^^^^^^^
-
-error: attempt to shift right with overflow
- --> $DIR/lint-exceeding-bitshifts2.rs:12:15
- |
-LL | let n = 1i64 >> [64][0];
- | ^^^^^^^^^^^^^^^
-
-error: attempt to shift left with overflow
- --> $DIR/lint-exceeding-bitshifts2.rs:18:15
- |
-LL | let n = 1_isize << BITS;
- | ^^^^^^^^^^^^^^^
-
-error: attempt to shift left with overflow
- --> $DIR/lint-exceeding-bitshifts2.rs:19:15
- |
-LL | let n = 1_usize << BITS;
- | ^^^^^^^^^^^^^^^
-
-error: aborting due to 4 previous errors
-