diff options
19 files changed, 47 insertions, 75 deletions
diff --git a/src/test/compile-fail/auxiliary/pub_static_array.rs b/src/test/compile-fail/auxiliary/pub_static_array.rs index 4419a5ae83c..7248d0e543b 100644 --- a/src/test/compile-fail/auxiliary/pub_static_array.rs +++ b/src/test/compile-fail/auxiliary/pub_static_array.rs @@ -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]; diff --git a/src/test/compile-fail/check-static-immutable-mut-slices.rs b/src/test/compile-fail/check-static-immutable-mut-slices.rs index 1804b9e04c2..370cfe9d550 100644 --- a/src/test/compile-fail/check-static-immutable-mut-slices.rs +++ b/src/test/compile-fail/check-static-immutable-mut-slices.rs @@ -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() { } diff --git a/src/test/compile-fail/check-static-values-constraints.rs b/src/test/compile-fail/check-static-values-constraints.rs index c3a1de11752..ded0d07d737 100644 --- a/src/test/compile-fail/check-static-values-constraints.rs +++ b/src/test/compile-fail/check-static-values-constraints.rs @@ -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 } diff --git a/src/test/compile-fail/const-fn-destructuring-arg.rs b/src/test/compile-fail/const-fn-destructuring-arg.rs index 1642c041067..c3d5975fe01 100644 --- a/src/test/compile-fail/const-fn-destructuring-arg.rs +++ b/src/test/compile-fail/const-fn-destructuring-arg.rs @@ -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() {} diff --git a/src/test/compile-fail/const-fn-error.rs b/src/test/compile-fail/const-fn-error.rs index cb6f2d0215f..45a00de48e7 100644 --- a/src/test/compile-fail/const-fn-error.rs +++ b/src/test/compile-fail/const-fn-error.rs @@ -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)] diff --git a/src/test/compile-fail/const-fn-not-safe-for-const.rs b/src/test/compile-fail/const-fn-not-safe-for-const.rs index f8381978dc7..48877a60d25 100644 --- a/src/test/compile-fail/const-fn-not-safe-for-const.rs +++ b/src/test/compile-fail/const-fn-not-safe-for-const.rs @@ -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() { } diff --git a/src/test/compile-fail/const-fn-not-safe-for-const2.rs b/src/test/compile-fail/const-fn-not-safe-for-const2.rs deleted file mode 100644 index a053847e882..00000000000 --- a/src/test/compile-fail/const-fn-not-safe-for-const2.rs +++ /dev/null @@ -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() { -} diff --git a/src/test/compile-fail/issue-17718-borrow-interior.rs b/src/test/compile-fail/issue-17718-borrow-interior.rs index d33c12668f2..31352c57f1b 100644 --- a/src/test/compile-fail/issue-17718-borrow-interior.rs +++ b/src/test/compile-fail/issue-17718-borrow-interior.rs @@ -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 diff --git a/src/test/compile-fail/issue-17718-const-bad-values.rs b/src/test/compile-fail/issue-17718-const-bad-values.rs index 6ee869d65a8..af356588ed9 100644 --- a/src/test/compile-fail/issue-17718-const-bad-values.rs +++ b/src/test/compile-fail/issue-17718-const-bad-values.rs @@ -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() {} diff --git a/src/test/compile-fail/issue-17718-references.rs b/src/test/compile-fail/issue-17718-references.rs index 9d8b116f569..c159168030b 100644 --- a/src/test/compile-fail/issue-17718-references.rs +++ b/src/test/compile-fail/issue-17718-references.rs @@ -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 diff --git a/src/test/compile-fail/issue-18118-2.rs b/src/test/compile-fail/issue-18118-2.rs index 1fbf48f5b21..6efe532b5fd 100644 --- a/src/test/compile-fail/issue-18118-2.rs +++ b/src/test/compile-fail/issue-18118-2.rs @@ -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 }; } diff --git a/src/test/compile-fail/issue-18118.rs b/src/test/compile-fail/issue-18118.rs index 9c8ed314d22..3afb34f037b 100644 --- a/src/test/compile-fail/issue-18118.rs +++ b/src/test/compile-fail/issue-18118.rs @@ -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 diff --git a/src/test/compile-fail/issue-25901.rs b/src/test/compile-fail/issue-25901.rs index 3254f0b2aa9..72fb2a682eb 100644 --- a/src/test/compile-fail/issue-25901.rs +++ b/src/test/compile-fail/issue-25901.rs @@ -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; diff --git a/src/test/compile-fail/issue-27895.rs b/src/test/compile-fail/issue-27895.rs index 959818b49c9..3b3abc94a49 100644 --- a/src/test/compile-fail/issue-27895.rs +++ b/src/test/compile-fail/issue-27895.rs @@ -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"), } } diff --git a/src/test/compile-fail/issue-28113.rs b/src/test/compile-fail/issue-28113.rs index c5c4fb07017..5c697b69c80 100644 --- a/src/test/compile-fail/issue-28113.rs +++ b/src/test/compile-fail/issue-28113.rs @@ -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() {} diff --git a/src/test/compile-fail/non-constant-in-const-path.rs b/src/test/compile-fail/non-constant-in-const-path.rs index 124a2ffc185..ee88168515d 100644 --- a/src/test/compile-fail/non-constant-in-const-path.rs +++ b/src/test/compile-fail/non-constant-in-const-path.rs @@ -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 }; } diff --git a/src/test/compile-fail/static-array-across-crate.rs b/src/test/compile-fail/static-array-across-crate.rs index 04a731e847a..d101432f6d1 100644 --- a/src/test/compile-fail/static-array-across-crate.rs +++ b/src/test/compile-fail/static-array-across-crate.rs @@ -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() {} diff --git a/src/test/run-pass/const-str-ptr.rs b/src/test/run-pass/const-str-ptr.rs index 1736ab5bb82..f58bf4fc39f 100644 --- a/src/test/run-pass/const-str-ptr.rs +++ b/src/test/run-pass/const-str-ptr.rs @@ -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; diff --git a/src/test/run-pass/mir_raw_fat_ptr.rs b/src/test/run-pass/mir_raw_fat_ptr.rs index c0ba7a76dba..a632f00d9ee 100644 --- a/src/test/run-pass/mir_raw_fat_ptr.rs +++ b/src/test/run-pass/mir_raw_fat_ptr.rs @@ -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]; |
