test: adjust for the move to MIR-based const checking.

This commit is contained in:
Eduard Burtescu 2016-05-03 01:57:35 +03:00
parent 78884b7659
commit 4f5900aefa
19 changed files with 47 additions and 75 deletions

@ -8,4 +8,4 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub static ARRAY: &'static [u8] = &[1];
pub static ARRAY: [u8; 1] = [1];

@ -12,5 +12,6 @@
static TEST: &'static mut [isize] = &mut [];
//~^ ERROR references in statics may only refer to immutable values
//~^^ ERROR references in statics may only refer to immutable values
pub fn main() { }

@ -140,4 +140,5 @@ static STATIC19: Box<isize> =
pub fn main() {
let y = { static x: Box<isize> = box 3; x };
//~^ ERROR allocations are not allowed in statics
//~^^ ERROR cannot move out of static item
}

@ -13,6 +13,11 @@
#![feature(const_fn)]
// no destructuring
const fn i((a, b): (u32, u32)) -> u32 { a + b } //~ ERROR: E0022
const fn i((
a, //~ ERROR: E0022
b //~ ERROR: E0022
): (u32, u32)) -> u32 {
a + b
}
fn main() {}

@ -8,19 +8,16 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// test that const fn signature and body errors are checked
// even in array lengths, which are evaluated before check_const
#![feature(const_fn)]
const X : usize = 2;
const fn f(x: usize) -> usize {
let mut sum = 0; //~ ERROR: E0016
for i in 0..x { //~ ERROR: E0016
let mut sum = 0;
for i in 0..x {
sum += i;
}
sum
sum //~ ERROR: E0250
}
#[allow(unused_variables)]

@ -29,7 +29,7 @@ static Y: u32 = 0;
const fn get_Y() -> u32 {
Y
//~^ ERROR E0013
//~| ERROR cannot refer to other statics by value
//~| ERROR cannot refer to statics by value
}
const fn get_Y_addr() -> &'static u32 {
@ -37,5 +37,11 @@ const fn get_Y_addr() -> &'static u32 {
//~^ ERROR E0013
}
const fn get() -> u32 {
let x = 22; //~ ERROR E0016
let y = 44; //~ ERROR E0016
x + y
}
fn main() {
}

@ -1,44 +0,0 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Test that we can't call random fns in a const fn or do other bad things.
#![feature(const_fn)]
use std::mem::transmute;
fn random() -> u32 { 0 }
const fn sub(x: &u32) -> usize {
unsafe { transmute(x) }
}
const fn sub1() -> u32 {
random()
}
static Y: u32 = 0;
const fn get_Y() -> u32 {
Y
}
const fn get_Y_addr() -> &'static u32 {
&Y
}
const fn get() -> u32 {
let x = 22; //~ ERROR E0016
let y = 44; //~ ERROR E0016
x + y
}
fn main() {
}

@ -17,7 +17,8 @@ static C: &'static usize = &(A.a);
static D: [usize; 1] = [1];
static E: usize = D[0];
//~^ ERROR: cannot refer to other statics by value
//~^ ERROR: cannot refer to the interior of another static
//~^^ ERROR: cannot refer to other statics by value
static F: &'static usize = &D[0];
//~^ ERROR: cannot refer to the interior of another static

@ -10,10 +10,13 @@
const C1: &'static mut [usize] = &mut [];
//~^ ERROR: references in constants may only refer to immutable values
//~| ERROR: references in constants may only refer to immutable values
static mut S: usize = 3;
const C2: &'static mut usize = &mut S;
//~^ ERROR: constants cannot refer to other statics
//~^^ ERROR: references in constants may only refer to immutable values
const C2: &'static mut usize = unsafe { &mut S };
//~^ ERROR: constants cannot refer to statics
//~| ERROR: references in constants may only refer to immutable values
//~| ERROR: references in constants may only refer to immutable values
//~| ERROR: references in constants may only refer to immutable values
fn main() {}

@ -14,19 +14,19 @@ const C: usize = 1;
static S: usize = 1;
const T1: &'static usize = &C;
const T2: &'static usize = &S; //~ ERROR: constants cannot refer to other statics
const T2: &'static usize = &S; //~ ERROR: constants cannot refer to statics
static T3: &'static usize = &C;
static T4: &'static usize = &S;
const T5: usize = C;
const T6: usize = S; //~ ERROR: constants cannot refer to other statics
//~^ cannot refer to other statics
const T6: usize = S; //~ ERROR: constants cannot refer to statics
//~^ cannot refer to statics
static T7: usize = C;
static T8: usize = S; //~ ERROR: cannot refer to other statics by value
const T9: Struct = Struct { a: C };
const T10: Struct = Struct { a: S }; //~ ERROR: cannot refer to other statics by value
//~^ ERROR: constants cannot refer to other statics
const T10: Struct = Struct { a: S }; //~ ERROR: cannot refer to statics by value
//~^ ERROR: constants cannot refer to statics
static T11: Struct = Struct { a: C };
static T12: Struct = Struct { a: S }; //~ ERROR: cannot refer to other statics by value

@ -12,6 +12,6 @@ pub fn main() {
const z: &'static isize = {
static p: isize = 3;
&p
//~^ ERROR constants cannot refer to other statics, insert an intermediate constant instead
//~^ ERROR constants cannot refer to statics, use a constant instead
};
}

@ -10,6 +10,7 @@
pub fn main() {
const z: &'static isize = {
//~^ ERROR blocks in constants are limited to items and tail expressions
let p = 3;
//~^ ERROR blocks in constants are limited to items and tail expressions
&p

@ -11,7 +11,8 @@
struct A;
struct B;
static S: &'static B = &A; //~ ERROR user-defined dereference operators
static S: &'static B = &A;
//~^ ERROR calls in statics are limited to constant functions
use std::ops::Deref;

@ -14,8 +14,7 @@ fn main() {
match i {
0...index => println!("winner"),
//~^ ERROR paths in constants may only refer to constants or functions
//~| ERROR non-constant path in constant expression
//~^ ERROR non-constant path in constant expression
_ => println!("hello"),
}
}

@ -9,7 +9,8 @@
// except according to those terms.
const X: u8 =
|| -> u8 { 5 }() //~ ERROR function calls in constants are limited
|| -> u8 { 5 }()
//~^ ERROR calls in constants are limited to constant functions
;
fn main() {}

@ -12,7 +12,6 @@ fn main() {
let x = 0;
match 1 {
0 ... x => {}
//~^ ERROR non-constant path in constant expr
//~| ERROR paths in constants may only refer to constants or functions
//~^ ERROR non-constant path in constant expression
};
}

@ -17,4 +17,11 @@ use array::ARRAY;
static X: &'static u8 = &ARRAY[0];
//~^ ERROR: cannot refer to the interior of another static, use a constant
static Y: &'static u8 = &(&ARRAY)[0];
//~^ ERROR: cannot refer to the interior of another static, use a constant
static Z: u8 = (&ARRAY)[0];
//~^ ERROR: cannot refer to the interior of another static, use a constant
//~^^ ERROR: cannot refer to other statics by value
pub fn main() {}

@ -8,17 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(rustc_attrs)]
// ignore-pretty : (#23623) problems when ending with // comments
use std::{str, string};
const A: [u8; 2] = ['h' as u8, 'i' as u8];
const B: &'static [u8; 2] = &A;
const C: *const u8 = B as *const u8;
#[rustc_no_mir] // FIXME #27840 MIR can't do rvalue promotion yet.
pub fn main() {
unsafe {
let foo = &A as *const u8;

@ -121,7 +121,6 @@ impl<T> Foo for T {
struct S<T:?Sized>(u32, T);
#[rustc_no_mir] // FIXME #27840 MIR can't do rvalue promotion yet.
fn main() {
let array = [0,1,2,3,4];
let array2 = [5,6,7,8,9];