Update tests

This commit is contained in:
Oliver Schneider 2018-01-29 20:47:09 +01:00 committed by Oliver Schneider
parent 45abb1ba84
commit ceb634a732
No known key found for this signature in database
GPG Key ID: A69F8D225B3AD7D9
16 changed files with 75 additions and 57 deletions

View File

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

View File

@ -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) {

View File

@ -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() {

View File

@ -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() {

View File

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

View File

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

View File

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

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -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() {

View File

@ -11,7 +11,6 @@
#![deny(exceeding_bitshifts)]
#![allow(unused_variables)]
#![allow(dead_code, const_err)]
#![feature(const_indexing)]
fn main() {
let n = 1u8 << 7;

View File

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

View File

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

View File

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

View File

@ -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(){}