diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-11-03 15:56:59 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-11-03 16:24:26 -0800 |
| commit | f2aa8c41876cce93c6bb4ada79600b8ef8e3d599 (patch) | |
| tree | 9b084ab7e33e8f857167d3baf2500d484db27f7e | |
| parent | 5d6cd7707036ef75a6fad90d4e5189e6916e1be8 (diff) | |
| parent | e7f310970867061ae1eb8d95ce7a674560533857 (diff) | |
| download | rust-f2aa8c41876cce93c6bb4ada79600b8ef8e3d599.tar.gz rust-f2aa8c41876cce93c6bb4ada79600b8ef8e3d599.zip | |
rollup merge of #18593 : hirschenberger/issue-18587
Conflicts: src/test/compile-fail/lint-exceeding-bitshifts.rs
| -rw-r--r-- | src/librustc/lint/builtin.rs | 14 | ||||
| -rw-r--r-- | src/test/compile-fail/lint-exceeding-bitshifts.rs | 4 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 032d6e2e348..f83facbb621 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -39,7 +39,7 @@ use std::cmp; use std::collections::HashMap; use std::collections::hash_map::{Occupied, Vacant}; use std::slice; -use std::{int, i8, i16, i32, i64, uint, u8, u16, u32, u64, f32, f64}; +use std::{i8, i16, i32, i64, u8, u16, u32, u64, f32, f64}; use syntax::abi; use syntax::ast_map; use syntax::ast_util::is_shift_binop; @@ -180,8 +180,8 @@ impl LintPass for TypeLimits { if is_shift_binop(binop) { let opt_ty_bits = match ty::get(ty::expr_ty(cx.tcx, &**l)).sty { - ty::ty_int(t) => Some(int_ty_bits(t)), - ty::ty_uint(t) => Some(uint_ty_bits(t)), + ty::ty_int(t) => Some(int_ty_bits(t, cx.sess().targ_cfg.int_type)), + ty::ty_uint(t) => Some(uint_ty_bits(t, cx.sess().targ_cfg.uint_type)), _ => None }; @@ -312,9 +312,9 @@ impl LintPass for TypeLimits { } } - fn int_ty_bits(int_ty: ast::IntTy) -> u64 { + fn int_ty_bits(int_ty: ast::IntTy, target_int_ty: ast::IntTy) -> u64 { match int_ty { - ast::TyI => int::BITS as u64, + ast::TyI => int_ty_bits(target_int_ty, target_int_ty), ast::TyI8 => i8::BITS as u64, ast::TyI16 => i16::BITS as u64, ast::TyI32 => i32::BITS as u64, @@ -322,9 +322,9 @@ impl LintPass for TypeLimits { } } - fn uint_ty_bits(uint_ty: ast::UintTy) -> u64 { + fn uint_ty_bits(uint_ty: ast::UintTy, target_uint_ty: ast::UintTy) -> u64 { match uint_ty { - ast::TyU => uint::BITS as u64, + ast::TyU => uint_ty_bits(target_uint_ty, target_uint_ty), ast::TyU8 => u8::BITS as u64, ast::TyU16 => u16::BITS as u64, ast::TyU32 => u32::BITS as u64, diff --git a/src/test/compile-fail/lint-exceeding-bitshifts.rs b/src/test/compile-fail/lint-exceeding-bitshifts.rs index eecc2168029..dbb65d8b7ce 100644 --- a/src/test/compile-fail/lint-exceeding-bitshifts.rs +++ b/src/test/compile-fail/lint-exceeding-bitshifts.rs @@ -10,6 +10,7 @@ #![deny(exceeding_bitshifts)] #![allow(unused_variables)] +#![allow(dead_code)] fn main() { let n = 1u8 << 7; @@ -54,5 +55,8 @@ fn main() { let n = 1u8 << (4+3); let n = 1u8 << (4+4); //~ ERROR: bitshift exceeds the type's number of bits + + let n = 1i << std::int::BITS; //~ ERROR: bitshift exceeds the type's number of bits + let n = 1u << std::uint::BITS; //~ ERROR: bitshift exceeds the type's number of bits } |
