Skip to content

Commit

Permalink
don't report bitshift overflow twice
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Apr 26, 2016
1 parent 735c018 commit 89d1046
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/librustc_const_math/lib.rs
Expand Up @@ -40,4 +40,4 @@ mod err;
pub use int::*;
pub use us::*;
pub use is::*;
pub use err::ConstMathErr;
pub use err::{ConstMathErr, Op};
5 changes: 4 additions & 1 deletion src/librustc_passes/consts.rs
Expand Up @@ -28,9 +28,10 @@ use rustc::dep_graph::DepNode;
use rustc::ty::cast::{CastKind};
use rustc_const_eval::{ConstEvalErr, lookup_const_fn_by_id, compare_lit_exprs};
use rustc_const_eval::{eval_const_expr_partial, lookup_const_by_id};
use rustc_const_eval::ErrKind::{IndexOpFeatureGated, UnimplementedConstVal, MiscCatchAll};
use rustc_const_eval::ErrKind::{ErroneousReferencedConstant, MiscBinaryOp};
use rustc_const_eval::ErrKind::{IndexOpFeatureGated, UnimplementedConstVal, MiscCatchAll, Math};
use rustc_const_eval::EvalHint::ExprTypeChecked;
use rustc_const_math::{ConstMathErr, Op};
use rustc::hir::def::Def;
use rustc::hir::def_id::DefId;
use rustc::middle::expr_use_visitor as euv;
Expand Down Expand Up @@ -490,6 +491,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
Err(ConstEvalErr { kind: MiscCatchAll, ..}) |
Err(ConstEvalErr { kind: MiscBinaryOp, ..}) |
Err(ConstEvalErr { kind: ErroneousReferencedConstant(_), ..}) |
Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shr)), ..}) |
Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shl)), ..}) |
Err(ConstEvalErr { kind: IndexOpFeatureGated, ..}) => {},
Err(msg) => {
self.qualif = self.qualif | ConstQualif::NOT_CONST;
Expand Down
1 change: 1 addition & 0 deletions src/librustc_passes/lib.rs
Expand Up @@ -30,6 +30,7 @@
extern crate core;
#[macro_use] extern crate rustc;
extern crate rustc_const_eval;
extern crate rustc_const_math;

#[macro_use] extern crate log;
#[macro_use] extern crate syntax;
Expand Down
20 changes: 0 additions & 20 deletions src/test/compile-fail/lint-exceeding-bitshifts.rs
Expand Up @@ -16,53 +16,37 @@
fn main() {
let n = 1u8 << 7;
let n = 1u8 << 8; //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift left with overflow
let n = 1u16 << 15;
let n = 1u16 << 16; //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift left with overflow
let n = 1u32 << 31;
let n = 1u32 << 32; //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift left with overflow
let n = 1u64 << 63;
let n = 1u64 << 64; //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift left with overflow
let n = 1i8 << 7;
let n = 1i8 << 8; //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift left with overflow
let n = 1i16 << 15;
let n = 1i16 << 16; //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift left with overflow
let n = 1i32 << 31;
let n = 1i32 << 32; //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift left with overflow
let n = 1i64 << 63;
let n = 1i64 << 64; //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift left with overflow

let n = 1u8 >> 7;
let n = 1u8 >> 8; //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift right with overflow
let n = 1u16 >> 15;
let n = 1u16 >> 16; //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift right with overflow
let n = 1u32 >> 31;
let n = 1u32 >> 32; //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift right with overflow
let n = 1u64 >> 63;
let n = 1u64 >> 64; //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift right with overflow
let n = 1i8 >> 7;
let n = 1i8 >> 8; //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift right with overflow
let n = 1i16 >> 15;
let n = 1i16 >> 16; //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift right with overflow
let n = 1i32 >> 31;
let n = 1i32 >> 32; //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift right with overflow
let n = 1i64 >> 63;
let n = 1i64 >> 64; //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift right with overflow

let n = 1u8;
let n = n << 7;
Expand All @@ -73,22 +57,18 @@ fn main() {

let n = 1u8 << (4+3);
let n = 1u8 << (4+4); //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift left 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: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift left with overflow
let n = 1_usize << BITS; //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift left with overflow


let n = 1i8<<(1isize+-1);

let n = 1i64 >> [63][0];
let n = 1i64 >> [64][0]; //~ ERROR: bitshift exceeds the type's number of bits
//~^ WARN: attempted to shift right with overflow
}

0 comments on commit 89d1046

Please sign in to comment.