Skip to content

Commit 11790a5

Browse files
committed
rollup merge of #18580 : hirschenberger/issue-17713
2 parents 1b363f0 + 32b903d commit 11790a5

File tree

2 files changed

+40
-40
lines changed

2 files changed

+40
-40
lines changed

src/librustc/lint/builtin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ impl LintPass for TypeLimits {
187187

188188
if let Some(bits) = opt_ty_bits {
189189
let exceeding = if let ast::ExprLit(ref lit) = r.node {
190-
if let ast::LitInt(shift, _) = lit.node { shift > bits }
190+
if let ast::LitInt(shift, _) = lit.node { shift >= bits }
191191
else { false }
192192
} else {
193193
match eval_const_expr_partial(cx.tcx, &**r) {
194-
Ok(const_int(shift)) => { shift as u64 > bits },
195-
Ok(const_uint(shift)) => { shift > bits },
194+
Ok(const_int(shift)) => { shift as u64 >= bits },
195+
Ok(const_uint(shift)) => { shift >= bits },
196196
_ => { false }
197197
}
198198
};

src/test/compile-fail/lint-exceeding-bitshifts.rs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,47 +12,47 @@
1212
#![allow(unused_variables)]
1313

1414
fn main() {
15-
let n = 1u8 << 8;
16-
let n = 1u8 << 9; //~ ERROR: bitshift exceeds the type's number of bits
17-
let n = 1u16 << 16;
18-
let n = 1u16 << 17; //~ ERROR: bitshift exceeds the type's number of bits
19-
let n = 1u32 << 32;
20-
let n = 1u32 << 33; //~ ERROR: bitshift exceeds the type's number of bits
21-
let n = 1u64 << 64;
22-
let n = 1u64 << 65; //~ ERROR: bitshift exceeds the type's number of bits
23-
let n = 1i8 << 8;
24-
let n = 1i8 << 9; //~ ERROR: bitshift exceeds the type's number of bits
25-
let n = 1i16 << 16;
26-
let n = 1i16 << 17; //~ ERROR: bitshift exceeds the type's number of bits
27-
let n = 1i32 << 32;
28-
let n = 1i32 << 33; //~ ERROR: bitshift exceeds the type's number of bits
29-
let n = 1i64 << 64;
30-
let n = 1i64 << 65; //~ ERROR: bitshift exceeds the type's number of bits
15+
let n = 1u8 << 7;
16+
let n = 1u8 << 8; //~ ERROR: bitshift exceeds the type's number of bits
17+
let n = 1u16 << 15;
18+
let n = 1u16 << 16; //~ ERROR: bitshift exceeds the type's number of bits
19+
let n = 1u32 << 31;
20+
let n = 1u32 << 32; //~ ERROR: bitshift exceeds the type's number of bits
21+
let n = 1u64 << 63;
22+
let n = 1u64 << 64; //~ ERROR: bitshift exceeds the type's number of bits
23+
let n = 1i8 << 7;
24+
let n = 1i8 << 8; //~ ERROR: bitshift exceeds the type's number of bits
25+
let n = 1i16 << 15;
26+
let n = 1i16 << 16; //~ ERROR: bitshift exceeds the type's number of bits
27+
let n = 1i32 << 31;
28+
let n = 1i32 << 32; //~ ERROR: bitshift exceeds the type's number of bits
29+
let n = 1i64 << 63;
30+
let n = 1i64 << 64; //~ ERROR: bitshift exceeds the type's number of bits
3131

32-
let n = 1u8 >> 8;
33-
let n = 1u8 >> 9; //~ ERROR: bitshift exceeds the type's number of bits
34-
let n = 1u16 >> 16;
35-
let n = 1u16 >> 17; //~ ERROR: bitshift exceeds the type's number of bits
36-
let n = 1u32 >> 32;
37-
let n = 1u32 >> 33; //~ ERROR: bitshift exceeds the type's number of bits
38-
let n = 1u64 >> 64;
39-
let n = 1u64 >> 65; //~ ERROR: bitshift exceeds the type's number of bits
40-
let n = 1i8 >> 8;
41-
let n = 1i8 >> 9; //~ ERROR: bitshift exceeds the type's number of bits
42-
let n = 1i16 >> 16;
43-
let n = 1i16 >> 17; //~ ERROR: bitshift exceeds the type's number of bits
44-
let n = 1i32 >> 32;
45-
let n = 1i32 >> 33; //~ ERROR: bitshift exceeds the type's number of bits
46-
let n = 1i64 >> 64;
47-
let n = 1i64 >> 65; //~ ERROR: bitshift exceeds the type's number of bits
32+
let n = 1u8 >> 7;
33+
let n = 1u8 >> 8; //~ ERROR: bitshift exceeds the type's number of bits
34+
let n = 1u16 >> 15;
35+
let n = 1u16 >> 16; //~ ERROR: bitshift exceeds the type's number of bits
36+
let n = 1u32 >> 31;
37+
let n = 1u32 >> 32; //~ ERROR: bitshift exceeds the type's number of bits
38+
let n = 1u64 >> 63;
39+
let n = 1u64 >> 64; //~ ERROR: bitshift exceeds the type's number of bits
40+
let n = 1i8 >> 7;
41+
let n = 1i8 >> 8; //~ ERROR: bitshift exceeds the type's number of bits
42+
let n = 1i16 >> 15;
43+
let n = 1i16 >> 16; //~ ERROR: bitshift exceeds the type's number of bits
44+
let n = 1i32 >> 31;
45+
let n = 1i32 >> 32; //~ ERROR: bitshift exceeds the type's number of bits
46+
let n = 1i64 >> 63;
47+
let n = 1i64 >> 64; //~ ERROR: bitshift exceeds the type's number of bits
4848

4949
let n = 1u8;
50-
let n = n << 8;
51-
let n = n << 9; //~ ERROR: bitshift exceeds the type's number of bits
50+
let n = n << 7;
51+
let n = n << 8; //~ ERROR: bitshift exceeds the type's number of bits
5252

53-
let n = 1u8 << -9; //~ ERROR: bitshift exceeds the type's number of bits
53+
let n = 1u8 << -8; //~ ERROR: bitshift exceeds the type's number of bits
5454

55-
let n = 1u8 << (4+4);
56-
let n = 1u8 << (4+5); //~ ERROR: bitshift exceeds the type's number of bits
55+
let n = 1u8 << (4+3);
56+
let n = 1u8 << (4+4); //~ ERROR: bitshift exceeds the type's number of bits
5757
}
5858

0 commit comments

Comments
 (0)