]> git.lizzy.rs Git - rust.git/commitdiff
don't report bitshift overflow twice
authorOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Tue, 26 Apr 2016 12:10:07 +0000 (14:10 +0200)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Tue, 26 Apr 2016 12:10:07 +0000 (14:10 +0200)
src/librustc_const_math/lib.rs
src/librustc_passes/consts.rs
src/librustc_passes/lib.rs
src/test/compile-fail/lint-exceeding-bitshifts.rs

index 9f66aac6e3899e4b07c13d0bab40474e5153f01b..59792d16e8bb6a484c1793de319d5d2965709ac6 100644 (file)
@@ -40,4 +40,4 @@
 pub use int::*;
 pub use us::*;
 pub use is::*;
-pub use err::ConstMathErr;
+pub use err::{ConstMathErr, Op};
index 32bcac40289eb466953c5b13950eaecb7bbcb168..0673188f53d6ff6ce9efc4007e5bdd5fa96a6c57 100644 (file)
 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 @@ fn visit_expr(&mut self, ex: &hir::Expr) {
                 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;
index 53ae1b30f7c1796dd48c3d2d776015f50d6e22c3..b235962eb9a3dcf6fddfd86d06c85253cc1a8bcf 100644 (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;
index a3ae0671c54cb2213a35f75df5bc4d3257859d9e..6d5abc944e78f7dc2ca80ab94e150889c31897a1 100644 (file)
 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
 }