rustc: merge check_static into check_const.

This commit is contained in:
Eduard Burtescu 2014-12-30 22:36:03 +02:00
parent 8dd1f6a0dc
commit 4d8f995c3a
11 changed files with 317 additions and 411 deletions

View file

@ -11,6 +11,6 @@
// Checks that immutable static items can't have mutable slices
static TEST: &'static mut [isize] = &mut [];
//~^ ERROR statics are not allowed to have mutable references
//~^ ERROR references in statics may only refer to immutable values
pub fn main() { }

View file

@ -99,7 +99,7 @@ static STATIC10: UnsafeStruct = UnsafeStruct;
struct MyOwned;
static STATIC11: Box<MyOwned> = box MyOwned;
//~^ ERROR statics are not allowed to have custom pointers
//~^ ERROR allocations are not allowed in statics
// The following examples test that mutable structs are just forbidden
// to have types with destructors
@ -117,16 +117,17 @@ static mut STATIC14: SafeStruct = SafeStruct {
//~^ ERROR mutable statics are not allowed to have destructors
field1: SafeEnum::Variant1,
field2: SafeEnum::Variant4("str".to_string())
//~^ ERROR static contains unimplemented expression type
};
static STATIC15: &'static [Box<MyOwned>] = &[
box MyOwned, //~ ERROR statics are not allowed to have custom pointers
box MyOwned, //~ ERROR statics are not allowed to have custom pointers
box MyOwned, //~ ERROR allocations are not allowed in statics
box MyOwned, //~ ERROR allocations are not allowed in statics
];
static STATIC16: (&'static Box<MyOwned>, &'static Box<MyOwned>) = (
&box MyOwned, //~ ERROR statics are not allowed to have custom pointers
&box MyOwned, //~ ERROR statics are not allowed to have custom pointers
&box MyOwned, //~ ERROR allocations are not allowed in statics
&box MyOwned, //~ ERROR allocations are not allowed in statics
);
static mut STATIC17: SafeEnum = SafeEnum::Variant1;
@ -134,9 +135,9 @@ static mut STATIC17: SafeEnum = SafeEnum::Variant1;
static STATIC19: Box<isize> =
box 3;
//~^ ERROR statics are not allowed to have custom pointers
//~^ ERROR allocations are not allowed in statics
pub fn main() {
let y = { static x: Box<isize> = box 3; x };
//~^ ERROR statics are not allowed to have custom pointers
//~^ ERROR allocations are not allowed in statics
}

View file

@ -9,7 +9,7 @@
// except according to those terms.
static X: usize = 0 as *const usize as usize;
//~^ ERROR: can not cast a pointer to an integer in a constant expression
//~^ ERROR: can not cast a pointer to an integer in statics
fn main() {
assert_eq!(X, 0);

View file

@ -9,12 +9,12 @@
// except according to those terms.
const C1: &'static mut [usize] = &mut [];
//~^ ERROR: constants are not allowed to have mutable references
//~^ 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: are not allowed to have mutable references
//~^^ ERROR: references in constants may only refer to immutable values
fn main() {}

View file

@ -11,7 +11,8 @@
pub fn main() {
static z: &'static isize = {
let p = 3;
//~^ ERROR blocks in constants are limited to items and tail expressions
&p
//~^ ERROR cannot borrow a local variable inside a static block, define a separate static instead
//~^ ERROR paths in constants may only refer to constants or functions
};
}

View file

@ -14,8 +14,9 @@ use std::cell::RefCell;
// Regression test for issue 7364
static boxed: Box<RefCell<isize>> = box RefCell::new(0);
//~^ ERROR statics are not allowed to have custom pointers
//~^ ERROR allocations are not allowed in statics
//~| ERROR: the trait `core::marker::Sync` is not implemented for the type
//~| ERROR: the trait `core::marker::Sync` is not implemented for the type
//~^^^^^ ERROR function calls in constants are limited to struct and enum constructors
fn main() { }

View file

@ -11,7 +11,7 @@
#![feature(box_syntax)]
static mut a: Box<isize> = box 3;
//~^ ERROR statics are not allowed to have custom pointers
//~^ ERROR allocations are not allowed in statics
//~^^ ERROR mutable statics are not allowed to have owned pointers
fn main() {}