don't report bitshift overflow twice

This commit is contained in:
Oliver Schneider 2016-04-26 14:10:07 +02:00
parent 735c018974
commit 89d1046503
4 changed files with 6 additions and 22 deletions

View File

@ -40,4 +40,4 @@ mod err;
pub use int::*;
pub use us::*;
pub use is::*;
pub use err::ConstMathErr;
pub use err::{ConstMathErr, Op};

View File

@ -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;
@ -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;

View File

@ -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;

View File

@ -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;
@ -73,7 +57,6 @@ 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;
@ -81,14 +64,11 @@ fn main() {
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
}