Skip to content

Commit f2aa8c4

Browse files
committed
rollup merge of #18593 : hirschenberger/issue-18587
Conflicts: src/test/compile-fail/lint-exceeding-bitshifts.rs
2 parents 5d6cd77 + e7f3109 commit f2aa8c4

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/librustc/lint/builtin.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use std::cmp;
3939
use std::collections::HashMap;
4040
use std::collections::hash_map::{Occupied, Vacant};
4141
use std::slice;
42-
use std::{int, i8, i16, i32, i64, uint, u8, u16, u32, u64, f32, f64};
42+
use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64};
4343
use syntax::abi;
4444
use syntax::ast_map;
4545
use syntax::ast_util::is_shift_binop;
@@ -180,8 +180,8 @@ impl LintPass for TypeLimits {
180180

181181
if is_shift_binop(binop) {
182182
let opt_ty_bits = match ty::get(ty::expr_ty(cx.tcx, &**l)).sty {
183-
ty::ty_int(t) => Some(int_ty_bits(t)),
184-
ty::ty_uint(t) => Some(uint_ty_bits(t)),
183+
ty::ty_int(t) => Some(int_ty_bits(t, cx.sess().targ_cfg.int_type)),
184+
ty::ty_uint(t) => Some(uint_ty_bits(t, cx.sess().targ_cfg.uint_type)),
185185
_ => None
186186
};
187187

@@ -312,19 +312,19 @@ impl LintPass for TypeLimits {
312312
}
313313
}
314314

315-
fn int_ty_bits(int_ty: ast::IntTy) -> u64 {
315+
fn int_ty_bits(int_ty: ast::IntTy, target_int_ty: ast::IntTy) -> u64 {
316316
match int_ty {
317-
ast::TyI => int::BITS as u64,
317+
ast::TyI => int_ty_bits(target_int_ty, target_int_ty),
318318
ast::TyI8 => i8::BITS as u64,
319319
ast::TyI16 => i16::BITS as u64,
320320
ast::TyI32 => i32::BITS as u64,
321321
ast::TyI64 => i64::BITS as u64
322322
}
323323
}
324324

325-
fn uint_ty_bits(uint_ty: ast::UintTy) -> u64 {
325+
fn uint_ty_bits(uint_ty: ast::UintTy, target_uint_ty: ast::UintTy) -> u64 {
326326
match uint_ty {
327-
ast::TyU => uint::BITS as u64,
327+
ast::TyU => uint_ty_bits(target_uint_ty, target_uint_ty),
328328
ast::TyU8 => u8::BITS as u64,
329329
ast::TyU16 => u16::BITS as u64,
330330
ast::TyU32 => u32::BITS as u64,

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

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#![deny(exceeding_bitshifts)]
1212
#![allow(unused_variables)]
13+
#![allow(dead_code)]
1314

1415
fn main() {
1516
let n = 1u8 << 7;
@@ -54,5 +55,8 @@ fn main() {
5455

5556
let n = 1u8 << (4+3);
5657
let n = 1u8 << (4+4); //~ ERROR: bitshift exceeds the type's number of bits
58+
59+
let n = 1i << std::int::BITS; //~ ERROR: bitshift exceeds the type's number of bits
60+
let n = 1u << std::uint::BITS; //~ ERROR: bitshift exceeds the type's number of bits
5761
}
5862

0 commit comments

Comments
 (0)