Skip to content

Commit 89d1046

Browse files
committed
don't report bitshift overflow twice
1 parent 735c018 commit 89d1046

File tree

4 files changed

+6
-22
lines changed

4 files changed

+6
-22
lines changed

src/librustc_const_math/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ mod err;
4040
pub use int::*;
4141
pub use us::*;
4242
pub use is::*;
43-
pub use err::ConstMathErr;
43+
pub use err::{ConstMathErr, Op};

src/librustc_passes/consts.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ use rustc::dep_graph::DepNode;
2828
use rustc::ty::cast::{CastKind};
2929
use rustc_const_eval::{ConstEvalErr, lookup_const_fn_by_id, compare_lit_exprs};
3030
use rustc_const_eval::{eval_const_expr_partial, lookup_const_by_id};
31-
use rustc_const_eval::ErrKind::{IndexOpFeatureGated, UnimplementedConstVal, MiscCatchAll};
3231
use rustc_const_eval::ErrKind::{ErroneousReferencedConstant, MiscBinaryOp};
32+
use rustc_const_eval::ErrKind::{IndexOpFeatureGated, UnimplementedConstVal, MiscCatchAll, Math};
3333
use rustc_const_eval::EvalHint::ExprTypeChecked;
34+
use rustc_const_math::{ConstMathErr, Op};
3435
use rustc::hir::def::Def;
3536
use rustc::hir::def_id::DefId;
3637
use rustc::middle::expr_use_visitor as euv;
@@ -490,6 +491,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
490491
Err(ConstEvalErr { kind: MiscCatchAll, ..}) |
491492
Err(ConstEvalErr { kind: MiscBinaryOp, ..}) |
492493
Err(ConstEvalErr { kind: ErroneousReferencedConstant(_), ..}) |
494+
Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shr)), ..}) |
495+
Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shl)), ..}) |
493496
Err(ConstEvalErr { kind: IndexOpFeatureGated, ..}) => {},
494497
Err(msg) => {
495498
self.qualif = self.qualif | ConstQualif::NOT_CONST;

src/librustc_passes/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
extern crate core;
3131
#[macro_use] extern crate rustc;
3232
extern crate rustc_const_eval;
33+
extern crate rustc_const_math;
3334

3435
#[macro_use] extern crate log;
3536
#[macro_use] extern crate syntax;

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

-20
Original file line numberDiff line numberDiff line change
@@ -16,53 +16,37 @@
1616
fn main() {
1717
let n = 1u8 << 7;
1818
let n = 1u8 << 8; //~ ERROR: bitshift exceeds the type's number of bits
19-
//~^ WARN: attempted to shift left with overflow
2019
let n = 1u16 << 15;
2120
let n = 1u16 << 16; //~ ERROR: bitshift exceeds the type's number of bits
22-
//~^ WARN: attempted to shift left with overflow
2321
let n = 1u32 << 31;
2422
let n = 1u32 << 32; //~ ERROR: bitshift exceeds the type's number of bits
25-
//~^ WARN: attempted to shift left with overflow
2623
let n = 1u64 << 63;
2724
let n = 1u64 << 64; //~ ERROR: bitshift exceeds the type's number of bits
28-
//~^ WARN: attempted to shift left with overflow
2925
let n = 1i8 << 7;
3026
let n = 1i8 << 8; //~ ERROR: bitshift exceeds the type's number of bits
31-
//~^ WARN: attempted to shift left with overflow
3227
let n = 1i16 << 15;
3328
let n = 1i16 << 16; //~ ERROR: bitshift exceeds the type's number of bits
34-
//~^ WARN: attempted to shift left with overflow
3529
let n = 1i32 << 31;
3630
let n = 1i32 << 32; //~ ERROR: bitshift exceeds the type's number of bits
37-
//~^ WARN: attempted to shift left with overflow
3831
let n = 1i64 << 63;
3932
let n = 1i64 << 64; //~ ERROR: bitshift exceeds the type's number of bits
40-
//~^ WARN: attempted to shift left with overflow
4133

4234
let n = 1u8 >> 7;
4335
let n = 1u8 >> 8; //~ ERROR: bitshift exceeds the type's number of bits
44-
//~^ WARN: attempted to shift right with overflow
4536
let n = 1u16 >> 15;
4637
let n = 1u16 >> 16; //~ ERROR: bitshift exceeds the type's number of bits
47-
//~^ WARN: attempted to shift right with overflow
4838
let n = 1u32 >> 31;
4939
let n = 1u32 >> 32; //~ ERROR: bitshift exceeds the type's number of bits
50-
//~^ WARN: attempted to shift right with overflow
5140
let n = 1u64 >> 63;
5241
let n = 1u64 >> 64; //~ ERROR: bitshift exceeds the type's number of bits
53-
//~^ WARN: attempted to shift right with overflow
5442
let n = 1i8 >> 7;
5543
let n = 1i8 >> 8; //~ ERROR: bitshift exceeds the type's number of bits
56-
//~^ WARN: attempted to shift right with overflow
5744
let n = 1i16 >> 15;
5845
let n = 1i16 >> 16; //~ ERROR: bitshift exceeds the type's number of bits
59-
//~^ WARN: attempted to shift right with overflow
6046
let n = 1i32 >> 31;
6147
let n = 1i32 >> 32; //~ ERROR: bitshift exceeds the type's number of bits
62-
//~^ WARN: attempted to shift right with overflow
6348
let n = 1i64 >> 63;
6449
let n = 1i64 >> 64; //~ ERROR: bitshift exceeds the type's number of bits
65-
//~^ WARN: attempted to shift right with overflow
6650

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

7458
let n = 1u8 << (4+3);
7559
let n = 1u8 << (4+4); //~ ERROR: bitshift exceeds the type's number of bits
76-
//~^ WARN: attempted to shift left with overflow
7760

7861
#[cfg(target_pointer_width = "32")]
7962
const BITS: usize = 32;
8063
#[cfg(target_pointer_width = "64")]
8164
const BITS: usize = 64;
8265

8366
let n = 1_isize << BITS; //~ ERROR: bitshift exceeds the type's number of bits
84-
//~^ WARN: attempted to shift left with overflow
8567
let n = 1_usize << BITS; //~ ERROR: bitshift exceeds the type's number of bits
86-
//~^ WARN: attempted to shift left with overflow
8768

8869

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

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

0 commit comments

Comments
 (0)