about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Schneider <git-no-reply-9879165716479413131@oli-obk.de>2018-01-29 20:47:09 +0100
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>2018-03-08 08:34:14 +0100
commitceb634a7323b9957ae94873c6bcb623bf61af34f (patch)
treea3fbc96e78aca5501d18a204bc66f6748949ae69
parent45abb1ba8436efe960768b067a2683d577e16b8b (diff)
downloadrust-ceb634a7323b9957ae94873c6bcb623bf61af34f.tar.gz
rust-ceb634a7323b9957ae94873c6bcb623bf61af34f.zip
Update tests
-rw-r--r--src/librustc_mir/hair/pattern/_match.rs8
-rw-r--r--src/librustc_mir/transform/const_prop.rs7
-rw-r--r--src/test/compile-fail/array_const_index-0.rs1
-rw-r--r--src/test/compile-fail/array_const_index-1.rs1
-rw-r--r--src/test/compile-fail/const-err-early.rs11
-rw-r--r--src/test/compile-fail/const-err-multi.rs5
-rw-r--r--src/test/compile-fail/const-err.rs1
-rw-r--r--src/test/compile-fail/const-eval-overflow2.rs28
-rw-r--r--src/test/compile-fail/const-eval-overflow2b.rs28
-rw-r--r--src/test/compile-fail/const-eval-overflow2c.rs28
-rw-r--r--src/test/compile-fail/const-slice-oob.rs1
-rw-r--r--src/test/compile-fail/lint-exceeding-bitshifts.rs1
-rw-r--r--src/test/compile-fail/lint-exceeding-bitshifts2.rs6
-rw-r--r--src/test/compile-fail/lint-type-overflow2.rs1
-rw-r--r--src/test/ui/error-codes/E0080.rs1
-rw-r--r--src/test/ui/infinite-recursion-const-fn.rs4
16 files changed, 75 insertions, 57 deletions
diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs
index 7f443893544..5476d73fb6b 100644
--- a/src/librustc_mir/hair/pattern/_match.rs
+++ b/src/librustc_mir/hair/pattern/_match.rs
@@ -185,7 +185,7 @@ impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> {
                     match b {
                         Value::ByVal(PrimVal::Ptr(ptr)) => {
                             let is_array_ptr = ty
-                                .builtin_deref(true, ty::NoPreference)
+                                .builtin_deref(true)
                                 .and_then(|t| t.ty.builtin_index())
                                 .map_or(false, |t| t == tcx.types.u8);
                             assert!(is_array_ptr);
@@ -560,7 +560,7 @@ fn max_slice_length<'p, 'a: 'p, 'tcx: 'a, I>(
                 }
             } => {
                 let is_array_ptr = ty
-                    .builtin_deref(true, ty::NoPreference)
+                    .builtin_deref(true)
                     .and_then(|t| t.ty.builtin_index())
                     .map_or(false, |t| t == cx.tcx.types.u8);
                 if is_array_ptr {
@@ -949,7 +949,7 @@ fn slice_pat_covered_by_constructor(tcx: TyCtxt, _span: Span,
             Value::ByVal(PrimVal::Ptr(ptr))
         ), ty }) => {
             let is_array_ptr = ty
-                .builtin_deref(true, ty::NoPreference)
+                .builtin_deref(true)
                 .and_then(|t| t.ty.builtin_index())
                 .map_or(false, |t| t == tcx.types.u8);
             assert!(is_array_ptr);
@@ -1089,7 +1089,7 @@ fn specialize<'p, 'a: 'p, 'tcx: 'a>(
                 Slice(..) => match value.val {
                     ConstVal::Value(Value::ByVal(PrimVal::Ptr(ptr))) => {
                         let is_array_ptr = value.ty
-                            .builtin_deref(true, ty::NoPreference)
+                            .builtin_deref(true)
                             .and_then(|t| t.ty.builtin_index())
                             .map_or(false, |t| t == cx.tcx.types.u8);
                         assert!(is_array_ptr);
diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs
index e0d8744f7c4..039aecdb0b3 100644
--- a/src/librustc_mir/transform/const_prop.rs
+++ b/src/librustc_mir/transform/const_prop.rs
@@ -198,7 +198,6 @@ impl<'b, 'a, 'tcx:'b> OptimizationFinder<'b, 'a, 'tcx> {
             Rvalue::CheckedBinaryOp(op, ref left, ref right) |
             Rvalue::BinaryOp(op, ref left, ref right) => {
                 trace!("rvalue binop {:?} for {:?} and {:?}", op, left, right);
-                let left = self.eval_operand(left)?;
                 let right = self.eval_operand(right)?;
                 let def_id = if self.tcx.is_closure(self.source.def_id) {
                     self.tcx.closure_base_def_id(self.source.def_id)
@@ -218,8 +217,8 @@ impl<'b, 'a, 'tcx:'b> OptimizationFinder<'b, 'a, 'tcx> {
                 let r = ecx.value_to_primval(ValTy { value: right.0, ty: right.1 }).ok()?;
                 if op == BinOp::Shr || op == BinOp::Shl {
                     let param_env = self.tcx.param_env(self.source.def_id);
-                    let bits = (self.tcx, param_env).layout_of(left.1).unwrap().size.bits();
-                    if r.to_bytes().ok()? >= bits as u128 {
+                    let bits = (self.tcx, param_env).layout_of(place_ty).unwrap().size.bits();
+                    if r.to_bytes().ok().map_or(false, |b| b >= bits as u128) {
                         let scope_info = match self.mir.visibility_scope_info {
                             ClearCrossCrate::Set(ref data) => data,
                             ClearCrossCrate::Clear => return None,
@@ -230,8 +229,10 @@ impl<'b, 'a, 'tcx:'b> OptimizationFinder<'b, 'a, 'tcx> {
                             node_id,
                             span,
                             "bitshift exceeds the type's number of bits");
+                        return None;
                     }
                 }
+                let left = self.eval_operand(left)?;
                 let l = ecx.value_to_primval(ValTy { value: left.0, ty: left.1 }).ok()?;
                 trace!("const evaluating {:?} for {:?} and {:?}", op, left, right);
                 match ecx.binary_op(op, l, left.1, r, right.1) {
diff --git a/src/test/compile-fail/array_const_index-0.rs b/src/test/compile-fail/array_const_index-0.rs
index 501c66e75cd..35e7a422562 100644
--- a/src/test/compile-fail/array_const_index-0.rs
+++ b/src/test/compile-fail/array_const_index-0.rs
@@ -11,6 +11,7 @@
 const A: &'static [i32] = &[];
 const B: i32 = (&A)[1];
 //~^ ERROR constant evaluation error
+//~| ERROR E0080
 //~| index out of bounds: the len is 0 but the index is 1
 
 fn main() {
diff --git a/src/test/compile-fail/array_const_index-1.rs b/src/test/compile-fail/array_const_index-1.rs
index d3b43e83bfe..db4cfa42689 100644
--- a/src/test/compile-fail/array_const_index-1.rs
+++ b/src/test/compile-fail/array_const_index-1.rs
@@ -11,6 +11,7 @@
 const A: [i32; 0] = [];
 const B: i32 = A[1];
 //~^ ERROR constant evaluation error
+//~| ERROR E0080
 //~| index out of bounds: the len is 0 but the index is 1
 
 fn main() {
diff --git a/src/test/compile-fail/const-err-early.rs b/src/test/compile-fail/const-err-early.rs
index 4a146d8de3c..3182ffa73b0 100644
--- a/src/test/compile-fail/const-err-early.rs
+++ b/src/test/compile-fail/const-err-early.rs
@@ -8,18 +8,27 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-#![feature(const_indexing)]
 #![deny(const_err)]
 
 pub const A: i8 = -std::i8::MIN; //~ ERROR E0080
 //~| ERROR const_err
 //~| ERROR const_err
+//~| ERROR E0080
 pub const B: u8 = 200u8 + 200u8; //~ ERROR E0080
+//~| ERROR E0080
 pub const C: u8 = 200u8 * 4; //~ ERROR E0080
+//~| ERROR E0080
 pub const D: u8 = 42u8 - (42u8 + 1); //~ ERROR E0080
+//~| ERROR E0080
 pub const E: u8 = [5u8][1];
 //~^ ERROR E0080
+//~| ERROR E0080
 
 fn main() {
+    let _a = A;
+    let _b = B;
+    let _c = C;
+    let _d = D;
+    let _e = E;
     let _e = [6u8][1];
 }
diff --git a/src/test/compile-fail/const-err-multi.rs b/src/test/compile-fail/const-err-multi.rs
index eb24a698419..1e3150a74d9 100644
--- a/src/test/compile-fail/const-err-multi.rs
+++ b/src/test/compile-fail/const-err-multi.rs
@@ -14,12 +14,17 @@ pub const A: i8 = -std::i8::MIN;
 //~^ ERROR E0080
 //~| ERROR const_err
 //~| ERROR const_err
+//~| ERROR E0080
 pub const B: i8 = A;
 //~^ ERROR E0080
+//~| ERROR E0080
 pub const C: u8 = A as u8;
 //~^ ERROR E0080
+//~| ERROR E0080
 pub const D: i8 = 50 - A;
 //~^ ERROR E0080
+//~| ERROR E0080
 
 fn main() {
+    let _ = (A, B, C, D);
 }
diff --git a/src/test/compile-fail/const-err.rs b/src/test/compile-fail/const-err.rs
index 8bd759b6d37..5f55cc82e6d 100644
--- a/src/test/compile-fail/const-err.rs
+++ b/src/test/compile-fail/const-err.rs
@@ -24,6 +24,7 @@ fn black_box<T>(_: T) {
 const FOO: u8 = [5u8][1];
 //~^ ERROR constant evaluation error
 //~| index out of bounds: the len is 1 but the index is 1
+//~| ERROR E0080
 
 fn main() {
     black_box((FOO, FOO));
diff --git a/src/test/compile-fail/const-eval-overflow2.rs b/src/test/compile-fail/const-eval-overflow2.rs
index 61a653589ff..aa735cc0453 100644
--- a/src/test/compile-fail/const-eval-overflow2.rs
+++ b/src/test/compile-fail/const-eval-overflow2.rs
@@ -22,57 +22,57 @@ use std::{i8, i16, i32, i64, isize};
 use std::{u8, u16, u32, u64, usize};
 
 const VALS_I8: (i8,) =
-    (
-     i8::MIN - 1,
      //~^ ERROR constant evaluation error
      //~| attempt to subtract with overflow
+    (
+     i8::MIN - 1,
      );
 
 const VALS_I16: (i16,) =
-    (
-     i16::MIN - 1,
      //~^ ERROR constant evaluation error
      //~| attempt to subtract with overflow
+    (
+     i16::MIN - 1,
      );
 
 const VALS_I32: (i32,) =
-    (
-     i32::MIN - 1,
      //~^ ERROR constant evaluation error
      //~| attempt to subtract with overflow
+    (
+     i32::MIN - 1,
      );
 
 const VALS_I64: (i64,) =
-    (
-     i64::MIN - 1,
      //~^ ERROR constant evaluation error
      //~| attempt to subtract with overflow
+    (
+     i64::MIN - 1,
      );
 
 const VALS_U8: (u8,) =
-    (
-     u8::MIN - 1,
      //~^ ERROR constant evaluation error
      //~| attempt to subtract with overflow
+    (
+     u8::MIN - 1,
      );
 
 const VALS_U16: (u16,) = (
-     u16::MIN - 1,
      //~^ ERROR constant evaluation error
      //~| attempt to subtract with overflow
+     u16::MIN - 1,
      );
 
 const VALS_U32: (u32,) = (
-     u32::MIN - 1,
      //~^ ERROR constant evaluation error
      //~| attempt to subtract with overflow
+     u32::MIN - 1,
      );
 
 const VALS_U64: (u64,) =
-    (
-     u64::MIN - 1,
      //~^ ERROR constant evaluation error
      //~| attempt to subtract with overflow
+    (
+     u64::MIN - 1,
      );
 
 fn main() {
diff --git a/src/test/compile-fail/const-eval-overflow2b.rs b/src/test/compile-fail/const-eval-overflow2b.rs
index b2e84486101..01c3ea1ff42 100644
--- a/src/test/compile-fail/const-eval-overflow2b.rs
+++ b/src/test/compile-fail/const-eval-overflow2b.rs
@@ -22,57 +22,57 @@ use std::{i8, i16, i32, i64, isize};
 use std::{u8, u16, u32, u64, usize};
 
 const VALS_I8: (i8,) =
-    (
-     i8::MAX + 1,
      //~^ ERROR constant evaluation error
      //~| attempt to add with overflow
+    (
+     i8::MAX + 1,
      );
 
 const VALS_I16: (i16,) =
-    (
-     i16::MAX + 1,
      //~^ ERROR constant evaluation error
      //~| attempt to add with overflow
+    (
+     i16::MAX + 1,
      );
 
 const VALS_I32: (i32,) =
-    (
-     i32::MAX + 1,
      //~^ ERROR constant evaluation error
      //~| attempt to add with overflow
+    (
+     i32::MAX + 1,
      );
 
 const VALS_I64: (i64,) =
-    (
-     i64::MAX + 1,
      //~^ ERROR constant evaluation error
      //~| attempt to add with overflow
+    (
+     i64::MAX + 1,
      );
 
 const VALS_U8: (u8,) =
-    (
-     u8::MAX + 1,
      //~^ ERROR constant evaluation error
      //~| attempt to add with overflow
+    (
+     u8::MAX + 1,
      );
 
 const VALS_U16: (u16,) = (
-     u16::MAX + 1,
      //~^ ERROR constant evaluation error
      //~| attempt to add with overflow
+     u16::MAX + 1,
      );
 
 const VALS_U32: (u32,) = (
-     u32::MAX + 1,
      //~^ ERROR constant evaluation error
      //~| attempt to add with overflow
+     u32::MAX + 1,
      );
 
 const VALS_U64: (u64,) =
-    (
-     u64::MAX + 1,
      //~^ ERROR constant evaluation error
      //~| attempt to add with overflow
+    (
+     u64::MAX + 1,
      );
 
 fn main() {
diff --git a/src/test/compile-fail/const-eval-overflow2c.rs b/src/test/compile-fail/const-eval-overflow2c.rs
index c4a8beaf0f0..dd7c151d85f 100644
--- a/src/test/compile-fail/const-eval-overflow2c.rs
+++ b/src/test/compile-fail/const-eval-overflow2c.rs
@@ -22,57 +22,57 @@ use std::{i8, i16, i32, i64, isize};
 use std::{u8, u16, u32, u64, usize};
 
 const VALS_I8: (i8,) =
-    (
-     i8::MIN * 2,
      //~^ ERROR constant evaluation error
      //~| attempt to multiply with overflow
+    (
+     i8::MIN * 2,
      );
 
 const VALS_I16: (i16,) =
-    (
-     i16::MIN * 2,
      //~^ ERROR constant evaluation error
      //~| attempt to multiply with overflow
+    (
+     i16::MIN * 2,
      );
 
 const VALS_I32: (i32,) =
-    (
-     i32::MIN * 2,
      //~^ ERROR constant evaluation error
      //~| attempt to multiply with overflow
+    (
+     i32::MIN * 2,
      );
 
 const VALS_I64: (i64,) =
-    (
-     i64::MIN * 2,
      //~^ ERROR constant evaluation error
      //~| attempt to multiply with overflow
+    (
+     i64::MIN * 2,
      );
 
 const VALS_U8: (u8,) =
-    (
-     u8::MAX * 2,
      //~^ ERROR constant evaluation error
      //~| attempt to multiply with overflow
+    (
+     u8::MAX * 2,
      );
 
 const VALS_U16: (u16,) = (
-     u16::MAX * 2,
      //~^ ERROR constant evaluation error
      //~| attempt to multiply with overflow
+     u16::MAX * 2,
      );
 
 const VALS_U32: (u32,) = (
-     u32::MAX * 2,
      //~^ ERROR constant evaluation error
      //~| attempt to multiply with overflow
+     u32::MAX * 2,
      );
 
 const VALS_U64: (u64,) =
-    (
-     u64::MAX * 2,
      //~^ ERROR constant evaluation error
      //~| attempt to multiply with overflow
+    (
+     u64::MAX * 2,
      );
 
 fn main() {
diff --git a/src/test/compile-fail/const-slice-oob.rs b/src/test/compile-fail/const-slice-oob.rs
index 179ea9e853f..cb884313f33 100644
--- a/src/test/compile-fail/const-slice-oob.rs
+++ b/src/test/compile-fail/const-slice-oob.rs
@@ -13,6 +13,7 @@
 const FOO: &'static[u32] = &[1, 2, 3];
 const BAR: u32 = FOO[5];
 //~^ ERROR constant evaluation error [E0080]
+//~| ERROR constant evaluation error [E0080]
 //~| index out of bounds: the len is 3 but the index is 5
 
 fn main() {
diff --git a/src/test/compile-fail/lint-exceeding-bitshifts.rs b/src/test/compile-fail/lint-exceeding-bitshifts.rs
index 2634157c806..34b43c5badb 100644
--- a/src/test/compile-fail/lint-exceeding-bitshifts.rs
+++ b/src/test/compile-fail/lint-exceeding-bitshifts.rs
@@ -11,7 +11,6 @@
 #![deny(exceeding_bitshifts)]
 #![allow(unused_variables)]
 #![allow(dead_code, const_err)]
-#![feature(const_indexing)]
 
 fn main() {
       let n = 1u8 << 7;
diff --git a/src/test/compile-fail/lint-exceeding-bitshifts2.rs b/src/test/compile-fail/lint-exceeding-bitshifts2.rs
index 0eab143fa49..a8027034fbe 100644
--- a/src/test/compile-fail/lint-exceeding-bitshifts2.rs
+++ b/src/test/compile-fail/lint-exceeding-bitshifts2.rs
@@ -14,7 +14,7 @@
 
 fn main() {
       let n = 1u8 << (4+3);
-      let n = 1u8 << (4+4); //~ ERROR: const_err
+      let n = 1u8 << (4+4); //~ ERROR: bitshift exceeds
       let n = 1i64 >> [63][0];
       let n = 1i64 >> [64][0]; // should be linting, needs to wait for const propagation
 
@@ -22,6 +22,6 @@ fn main() {
       const BITS: usize = 32;
       #[cfg(target_pointer_width = "64")]
       const BITS: usize = 64;
-      let n = 1_isize << BITS; //~ ERROR: const_err
-      let n = 1_usize << BITS; //~ ERROR: const_err
+      let n = 1_isize << BITS; //~ ERROR: bitshift exceeds
+      let n = 1_usize << BITS; //~ ERROR: bitshift exceeds
 }
diff --git a/src/test/compile-fail/lint-type-overflow2.rs b/src/test/compile-fail/lint-type-overflow2.rs
index 9178d8d2f6e..f7cf8a68d56 100644
--- a/src/test/compile-fail/lint-type-overflow2.rs
+++ b/src/test/compile-fail/lint-type-overflow2.rs
@@ -17,7 +17,6 @@
 #[rustc_error]
 fn main() { //~ ERROR: compilation successful
     let x2: i8 = --128; //~ warn: literal out of range for i8
-    //~^ WARN constant evaluation error
 
     let x = -3.40282357e+38_f32; //~ warn: literal out of range for f32
     let x =  3.40282357e+38_f32; //~ warn: literal out of range for f32
diff --git a/src/test/ui/error-codes/E0080.rs b/src/test/ui/error-codes/E0080.rs
index c8e42571128..cca63f23b77 100644
--- a/src/test/ui/error-codes/E0080.rs
+++ b/src/test/ui/error-codes/E0080.rs
@@ -10,6 +10,7 @@
 
 enum Enum {
     X = (1 << 500), //~ ERROR E0080
+    //~| ERROR bitshift exceeds
     //~| shift left with overflow
     Y = (1 / 0) //~ ERROR E0080
     //~| const_err
diff --git a/src/test/ui/infinite-recursion-const-fn.rs b/src/test/ui/infinite-recursion-const-fn.rs
index 05e40abdc0f..f98074bc554 100644
--- a/src/test/ui/infinite-recursion-const-fn.rs
+++ b/src/test/ui/infinite-recursion-const-fn.rs
@@ -11,8 +11,8 @@
 //https://github.com/rust-lang/rust/issues/31364
 
 #![feature(const_fn)]
-const fn a() -> usize { b() }
+const fn a() -> usize { b() } //~ ERROR constant evaluation error
 const fn b() -> usize { a() }
-const ARR: [i32; a()] = [5; 6]; //~ ERROR constant evaluation error
+const ARR: [i32; a()] = [5; 6];
 
 fn main(){}