mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
test: Convert statics to constants
Additionally, add lots of tests for new functionality around statics and `static mut`.
This commit is contained in:
parent
9c09c94347
commit
d03a4b0046
@ -11,6 +11,6 @@
|
||||
pub extern fn bar() {
|
||||
}
|
||||
|
||||
pub static foopy: &'static str = "hi there";
|
||||
pub static uint_val: uint = 12;
|
||||
pub static uint_expr: uint = (1 << uint_val) - 1;
|
||||
pub const foopy: &'static str = "hi there";
|
||||
pub const uint_val: uint = 12;
|
||||
pub const uint_expr: uint = (1 << uint_val) - 1;
|
||||
|
@ -17,7 +17,7 @@ pub struct C<'a> {
|
||||
}
|
||||
|
||||
fn no_op() { }
|
||||
pub static D : C<'static> = C {
|
||||
pub const D : C<'static> = C {
|
||||
k: no_op
|
||||
};
|
||||
|
||||
|
@ -14,6 +14,6 @@ pub struct Foo {
|
||||
|
||||
extern fn the_foo() {}
|
||||
|
||||
pub static FOO: Foo = Foo {
|
||||
pub const FOO: Foo = Foo {
|
||||
foo: the_foo
|
||||
};
|
||||
|
18
src/test/auxiliary/issue-17718-const-privacy.rs
Normal file
18
src/test/auxiliary/issue-17718-const-privacy.rs
Normal file
@ -0,0 +1,18 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
pub use foo::FOO2;
|
||||
|
||||
pub const FOO: uint = 3;
|
||||
const BAR: uint = 3;
|
||||
|
||||
mod foo {
|
||||
pub const FOO2: uint = 3;
|
||||
}
|
22
src/test/auxiliary/issue-17718.rs
Normal file
22
src/test/auxiliary/issue-17718.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
use std::sync::atomic;
|
||||
|
||||
pub const C1: uint = 1;
|
||||
pub const C2: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
|
||||
pub const C3: fn() = foo;
|
||||
pub const C4: uint = C1 * C1 + C1 / C1;
|
||||
pub const C5: &'static uint = &C4;
|
||||
|
||||
pub static S1: uint = 3;
|
||||
pub static S2: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
|
||||
|
||||
fn foo() {}
|
@ -21,7 +21,7 @@ mod private {
|
||||
pub struct P {
|
||||
p: i32,
|
||||
}
|
||||
pub static THREE: P = P { p: 3 };
|
||||
pub const THREE: P = P { p: 3 };
|
||||
}
|
||||
|
||||
pub static A: S = S { p: private::THREE };
|
||||
|
@ -45,16 +45,16 @@ use std::io::{stdout, IoResult};
|
||||
use std::os;
|
||||
use std::slice::bytes::copy_memory;
|
||||
|
||||
static LINE_LEN: uint = 60;
|
||||
static LOOKUP_SIZE: uint = 4 * 1024;
|
||||
static LOOKUP_SCALE: f32 = (LOOKUP_SIZE - 1) as f32;
|
||||
const LINE_LEN: uint = 60;
|
||||
const LOOKUP_SIZE: uint = 4 * 1024;
|
||||
const LOOKUP_SCALE: f32 = (LOOKUP_SIZE - 1) as f32;
|
||||
|
||||
// Random number generator constants
|
||||
static IM: u32 = 139968;
|
||||
static IA: u32 = 3877;
|
||||
static IC: u32 = 29573;
|
||||
const IM: u32 = 139968;
|
||||
const IA: u32 = 3877;
|
||||
const IC: u32 = 29573;
|
||||
|
||||
static ALU: &'static str = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTG\
|
||||
const ALU: &'static str = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTG\
|
||||
GGAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGA\
|
||||
GACCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAA\
|
||||
AATACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAAT\
|
||||
@ -62,7 +62,7 @@ static ALU: &'static str = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTG\
|
||||
CCGGGAGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTG\
|
||||
CACTCCAGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA";
|
||||
|
||||
static NULL_AMINO_ACID: AminoAcid = AminoAcid { c: ' ' as u8, p: 0.0 };
|
||||
const NULL_AMINO_ACID: AminoAcid = AminoAcid { c: ' ' as u8, p: 0.0 };
|
||||
|
||||
static IUB: [AminoAcid, ..15] = [
|
||||
AminoAcid { c: 'a' as u8, p: 0.27 },
|
||||
|
@ -45,8 +45,8 @@ use std::io::{BufferedWriter, File};
|
||||
use std::cmp::min;
|
||||
use std::os;
|
||||
|
||||
static LINE_LENGTH: uint = 60;
|
||||
static IM: u32 = 139968;
|
||||
const LINE_LENGTH: uint = 60;
|
||||
const IM: u32 = 139968;
|
||||
|
||||
struct MyRandom {
|
||||
last: u32
|
||||
|
@ -49,9 +49,9 @@ use std::os;
|
||||
use std::simd::f64x2;
|
||||
use std::sync::{Arc, Future};
|
||||
|
||||
static ITER: int = 50;
|
||||
static LIMIT: f64 = 2.0;
|
||||
static WORKERS: uint = 16;
|
||||
const ITER: int = 50;
|
||||
const LIMIT: f64 = 2.0;
|
||||
const WORKERS: uint = 16;
|
||||
|
||||
#[inline(always)]
|
||||
fn mandelbrot<W: io::Writer>(w: uint, mut out: W) -> io::IoResult<()> {
|
||||
@ -144,7 +144,7 @@ fn mandelbrot<W: io::Writer>(w: uint, mut out: W) -> io::IoResult<()> {
|
||||
fn write_line(init_i: f64, vec_init_r: &[f64], res: &mut Vec<u8>) {
|
||||
let v_init_i : f64x2 = f64x2(init_i, init_i);
|
||||
let v_2 : f64x2 = f64x2(2.0, 2.0);
|
||||
static LIMIT_SQUARED: f64 = LIMIT * LIMIT;
|
||||
const LIMIT_SQUARED: f64 = LIMIT * LIMIT;
|
||||
|
||||
for chunk_init_r in vec_init_r.chunks(8) {
|
||||
let mut cur_byte = 0xff;
|
||||
|
@ -38,10 +38,10 @@
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
// OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
static PI: f64 = 3.141592653589793;
|
||||
static SOLAR_MASS: f64 = 4.0 * PI * PI;
|
||||
static YEAR: f64 = 365.24;
|
||||
static N_BODIES: uint = 5;
|
||||
const PI: f64 = 3.141592653589793;
|
||||
const SOLAR_MASS: f64 = 4.0 * PI * PI;
|
||||
const YEAR: f64 = 365.24;
|
||||
const N_BODIES: uint = 5;
|
||||
|
||||
static BODIES: [Planet, ..N_BODIES] = [
|
||||
// Sun
|
||||
|
@ -11,6 +11,6 @@
|
||||
// Checks that immutable static items can't have mutable slices
|
||||
|
||||
static TEST: &'static mut [int] = &mut [];
|
||||
//~^ ERROR static items are not allowed to have mutable slices
|
||||
//~^ ERROR statics are not allowed to have mutable references
|
||||
|
||||
pub fn main() { }
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Verifies all possible restrictions for static items values.
|
||||
// Verifies all possible restrictions for statics values.
|
||||
|
||||
use std::kinds::marker;
|
||||
|
||||
@ -21,7 +21,7 @@ impl Drop for WithDtor {
|
||||
// This enum will be used to test the following rules:
|
||||
// 1. Variants are safe for static
|
||||
// 2. Expr calls are allowed as long as they arguments are safe
|
||||
// 3. Expr calls with unsafe arguments for static items are rejected
|
||||
// 3. Expr calls with unsafe arguments for statics are rejected
|
||||
enum SafeEnum {
|
||||
Variant1,
|
||||
Variant2(int),
|
||||
@ -35,7 +35,7 @@ static STATIC2: SafeEnum = Variant2(0);
|
||||
|
||||
// This one should fail
|
||||
static STATIC3: SafeEnum = Variant3(WithDtor);
|
||||
//~^ ERROR static items are not allowed to have destructors
|
||||
//~^ ERROR statics are not allowed to have destructors
|
||||
|
||||
|
||||
// This enum will be used to test that variants
|
||||
@ -52,9 +52,9 @@ impl Drop for UnsafeEnum {
|
||||
|
||||
|
||||
static STATIC4: UnsafeEnum = Variant5;
|
||||
//~^ ERROR static items are not allowed to have destructors
|
||||
//~^ ERROR statics are not allowed to have destructors
|
||||
static STATIC5: UnsafeEnum = Variant6(0);
|
||||
//~^ ERROR static items are not allowed to have destructors
|
||||
//~^ ERROR statics are not allowed to have destructors
|
||||
|
||||
|
||||
struct SafeStruct {
|
||||
@ -68,7 +68,7 @@ static STATIC6: SafeStruct = SafeStruct{field1: Variant1, field2: Variant2(0)};
|
||||
|
||||
// field2 has an unsafe value, hence this should fail
|
||||
static STATIC7: SafeStruct = SafeStruct{field1: Variant1, field2: Variant3(WithDtor)};
|
||||
//~^ ERROR static items are not allowed to have destructors
|
||||
//~^ ERROR statics are not allowed to have destructors
|
||||
|
||||
// Test variadic constructor for structs. The base struct should be examined
|
||||
// as well as every field present in the constructor.
|
||||
@ -79,7 +79,7 @@ static STATIC8: SafeStruct = SafeStruct{field1: Variant1,
|
||||
// This example should fail because field1 in the base struct is not safe
|
||||
static STATIC9: SafeStruct = SafeStruct{field1: Variant1,
|
||||
..SafeStruct{field1: Variant3(WithDtor), field2: Variant1}};
|
||||
//~^ ERROR static items are not allowed to have destructors
|
||||
//~^ ERROR statics are not allowed to have destructors
|
||||
|
||||
struct UnsafeStruct;
|
||||
|
||||
@ -89,44 +89,48 @@ impl Drop for UnsafeStruct {
|
||||
|
||||
// Types with destructors are not allowed for statics
|
||||
static STATIC10: UnsafeStruct = UnsafeStruct;
|
||||
//~^ ERROR static items are not allowed to have destructor
|
||||
//~^ ERROR statics are not allowed to have destructor
|
||||
|
||||
struct MyOwned;
|
||||
|
||||
static STATIC11: Box<MyOwned> = box MyOwned;
|
||||
//~^ ERROR static items are not allowed to have custom pointers
|
||||
//~^ ERROR statics are not allowed to have custom pointers
|
||||
|
||||
// The following examples test that mutable structs are just forbidden
|
||||
// to have types with destructors
|
||||
// These should fail
|
||||
static mut STATIC12: UnsafeStruct = UnsafeStruct;
|
||||
//~^ ERROR mutable static items are not allowed to have destructors
|
||||
//~^ ERROR mutable statics are not allowed to have destructors
|
||||
//~^^ ERROR statics are not allowed to have destructors
|
||||
|
||||
static mut STATIC13: SafeStruct = SafeStruct{field1: Variant1, field2: Variant3(WithDtor)};
|
||||
//~^ ERROR mutable static items are not allowed to have destructors
|
||||
//~^ ERROR mutable statics are not allowed to have destructors
|
||||
//~^^ ERROR: statics are not allowed to have destructors
|
||||
|
||||
static mut STATIC14: SafeStruct = SafeStruct {
|
||||
//~^ ERROR mutable static items are not allowed to have destructors
|
||||
//~^ ERROR mutable statics are not allowed to have destructors
|
||||
field1: Variant1,
|
||||
field2: Variant4("str".to_string())
|
||||
};
|
||||
|
||||
static STATIC15: &'static [Box<MyOwned>] = &[box MyOwned, box MyOwned];
|
||||
//~^ ERROR static items are not allowed to have custom pointers
|
||||
//~^^ ERROR static items are not allowed to have custom pointers
|
||||
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
|
||||
];
|
||||
|
||||
static STATIC16: (&'static Box<MyOwned>, &'static Box<MyOwned>) =
|
||||
(&box MyOwned, &box MyOwned);
|
||||
//~^ ERROR static items are not allowed to have custom pointers
|
||||
//~^^ ERROR static items are not allowed to have custom pointers
|
||||
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
|
||||
);
|
||||
|
||||
static mut STATIC17: SafeEnum = Variant1;
|
||||
//~^ ERROR mutable static items are not allowed to have destructors
|
||||
//~^ ERROR mutable statics are not allowed to have destructors
|
||||
|
||||
static STATIC19: Box<int> = box 3;
|
||||
//~^ ERROR static items are not allowed to have custom pointers
|
||||
static STATIC19: Box<int> =
|
||||
box 3;
|
||||
//~^ ERROR statics are not allowed to have custom pointers
|
||||
|
||||
pub fn main() {
|
||||
let y = { static x: Box<int> = box 3; x };
|
||||
//~^ ERROR static items are not allowed to have custom pointers
|
||||
//~^ ERROR statics are not allowed to have custom pointers
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
static N: int = 1;
|
||||
const N: int = 1;
|
||||
|
||||
enum Foo {
|
||||
A = 1,
|
||||
|
@ -15,7 +15,7 @@ extern {
|
||||
fn main() {
|
||||
let boolValue = match 42 {
|
||||
externalValue => true,
|
||||
//~^ ERROR extern statics cannot be referenced in patterns
|
||||
//~^ ERROR static variables cannot be referenced in a pattern
|
||||
_ => false
|
||||
};
|
||||
}
|
||||
|
24
src/test/compile-fail/issue-17718-borrow-interior.rs
Normal file
24
src/test/compile-fail/issue-17718-borrow-interior.rs
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
struct S { a: uint }
|
||||
static A: S = S { a: 3 };
|
||||
static B: &'static uint = &A.a;
|
||||
//~^ ERROR: cannot refer to the interior of another static
|
||||
static C: &'static uint = &(A.a);
|
||||
//~^ ERROR: cannot refer to the interior of another static
|
||||
|
||||
static D: [uint, ..1] = [1];
|
||||
static E: uint = D[0];
|
||||
//~^ ERROR: cannot refer to other statics by value
|
||||
static F: &'static uint = &D[0];
|
||||
//~^ ERROR: cannot refer to the interior of another static
|
||||
|
||||
fn main() {}
|
20
src/test/compile-fail/issue-17718-const-bad-values.rs
Normal file
20
src/test/compile-fail/issue-17718-const-bad-values.rs
Normal file
@ -0,0 +1,20 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
const C1: &'static mut [uint] = &mut [];
|
||||
//~^ ERROR: constants are not allowed to have mutable references
|
||||
|
||||
static mut S: uint = 3;
|
||||
const C2: &'static mut uint = &mut S;
|
||||
//~^ ERROR: constants cannot refer to other statics
|
||||
//~^^ ERROR: are not allowed to have mutable references
|
||||
|
||||
fn main() {}
|
||||
|
24
src/test/compile-fail/issue-17718-const-borrow.rs
Normal file
24
src/test/compile-fail/issue-17718-const-borrow.rs
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
use std::cell::UnsafeCell;
|
||||
|
||||
const A: UnsafeCell<uint> = UnsafeCell { value: 1 };
|
||||
const B: &'static UnsafeCell<uint> = &A;
|
||||
//~^ ERROR: cannot borrow a constant which contains interior mutability
|
||||
|
||||
struct C { a: UnsafeCell<uint> }
|
||||
const D: C = C { a: UnsafeCell { value: 1 } };
|
||||
const E: &'static UnsafeCell<uint> = &D.a;
|
||||
//~^ ERROR: cannot borrow a constant which contains interior mutability
|
||||
const F: &'static C = &D;
|
||||
//~^ ERROR: cannot borrow a constant which contains interior mutability
|
||||
|
||||
fn main() {}
|
@ -14,6 +14,6 @@ impl Drop for A {
|
||||
}
|
||||
|
||||
const FOO: A = A;
|
||||
//~ ERROR: constants are not allowed to have destructors
|
||||
//~^ ERROR: constants are not allowed to have destructors
|
||||
|
||||
fn main() {}
|
||||
|
16
src/test/compile-fail/issue-17718-const-naming.rs
Normal file
16
src/test/compile-fail/issue-17718-const-naming.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
#[deny(warnings)]
|
||||
|
||||
const foo: int = 3;
|
||||
//~^ ERROR: should have an uppercase name such as
|
||||
|
||||
fn main() {}
|
26
src/test/compile-fail/issue-17718-const-privacy.rs
Normal file
26
src/test/compile-fail/issue-17718-const-privacy.rs
Normal file
@ -0,0 +1,26 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
// aux-build:issue-17718-const-privacy.rs
|
||||
|
||||
extern crate "issue-17718-const-privacy" as other;
|
||||
|
||||
use a::B; //~ ERROR: const `B` is private
|
||||
use other::{
|
||||
FOO,
|
||||
BAR, //~ ERROR: const `BAR` is private
|
||||
FOO2,
|
||||
};
|
||||
|
||||
mod a {
|
||||
const B: uint = 3;
|
||||
}
|
||||
|
||||
fn main() {}
|
17
src/test/compile-fail/issue-17718-constants-not-static.rs
Normal file
17
src/test/compile-fail/issue-17718-constants-not-static.rs
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
const FOO: uint = 3;
|
||||
|
||||
fn foo() -> &'static uint { &FOO }
|
||||
//~^ ERROR: borrowed value does not live long enough
|
||||
|
||||
fn main() {
|
||||
}
|
15
src/test/compile-fail/issue-17718-extern-const.rs
Normal file
15
src/test/compile-fail/issue-17718-extern-const.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
extern {
|
||||
const FOO: uint; //~ ERROR: unexpected token: `const`
|
||||
}
|
||||
|
||||
fn main() {}
|
22
src/test/compile-fail/issue-17718-patterns.rs
Normal file
22
src/test/compile-fail/issue-17718-patterns.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
static A1: uint = 1;
|
||||
static mut A2: uint = 1;
|
||||
const A3: uint = 1;
|
||||
|
||||
fn main() {
|
||||
match 1u {
|
||||
A1 => {} //~ ERROR: static variables cannot be referenced in a pattern
|
||||
A2 => {} //~ ERROR: static variables cannot be referenced in a pattern
|
||||
A3 => {}
|
||||
_ => {}
|
||||
}
|
||||
}
|
14
src/test/compile-fail/issue-17718-recursive.rs
Normal file
14
src/test/compile-fail/issue-17718-recursive.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
const A: uint = B; //~ ERROR: recursive constant
|
||||
const B: uint = A; //~ ERROR: recursive constant
|
||||
|
||||
fn main() {}
|
33
src/test/compile-fail/issue-17718-references.rs
Normal file
33
src/test/compile-fail/issue-17718-references.rs
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
struct Struct { a: uint }
|
||||
|
||||
const C: uint = 1;
|
||||
static S: uint = 1;
|
||||
|
||||
const T1: &'static uint = &C;
|
||||
const T2: &'static uint = &S; //~ ERROR: constants cannot refer to other statics
|
||||
static T3: &'static uint = &C;
|
||||
static T4: &'static uint = &S;
|
||||
|
||||
const T5: uint = C;
|
||||
const T6: uint = S; //~ ERROR: constants cannot refer to other statics
|
||||
//~^ cannot refer to other statics
|
||||
static T7: uint = C;
|
||||
static T8: uint = 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
|
||||
static T11: Struct = Struct { a: C };
|
||||
static T12: Struct = Struct { a: S }; //~ ERROR: cannot refer to other statics by value
|
||||
|
||||
fn main() {}
|
19
src/test/compile-fail/issue-17718-static-move.rs
Normal file
19
src/test/compile-fail/issue-17718-static-move.rs
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
use std::kinds::marker;
|
||||
|
||||
struct Foo { nc: marker::NoCopy }
|
||||
const INIT: Foo = Foo { nc: marker::NoCopy };
|
||||
static FOO: Foo = INIT;
|
||||
|
||||
fn main() {
|
||||
let _a = FOO; //~ ERROR: cannot move out of static item
|
||||
}
|
19
src/test/compile-fail/issue-17718-static-sync.rs
Normal file
19
src/test/compile-fail/issue-17718-static-sync.rs
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
use std::kinds::marker;
|
||||
|
||||
struct Foo { marker: marker::NoSync }
|
||||
|
||||
static FOO: uint = 3;
|
||||
static BAR: Foo = Foo { marker: marker::NoSync };
|
||||
//~^ ERROR: shared static items must have a type which implements Sync
|
||||
|
||||
fn main() {}
|
@ -10,7 +10,7 @@
|
||||
|
||||
// Regression test for issue #4968
|
||||
|
||||
static A: (int,int) = (4,2);
|
||||
const A: (int,int) = (4,2);
|
||||
fn main() {
|
||||
match 42 { A => () }
|
||||
//~^ ERROR mismatched types: expected `<generic integer #0>`, found `(int,int)`
|
||||
|
@ -13,6 +13,7 @@ use std::cell::RefCell;
|
||||
|
||||
// Regresion test for issue 7364
|
||||
static boxed: Box<RefCell<int>> = box RefCell::new(0);
|
||||
//~^ ERROR static items are not allowed to have custom pointers
|
||||
//~^ ERROR statics are not allowed to have custom pointers
|
||||
//~^^ ERROR: shared static items must have a type which implements Sync
|
||||
|
||||
fn main() { }
|
||||
|
@ -14,7 +14,7 @@ struct Test {
|
||||
mem: int,
|
||||
}
|
||||
|
||||
pub static g_test: Test = Test {mem: 0}; //~ ERROR static items are not allowed to have destructors
|
||||
pub static g_test: Test = Test {mem: 0}; //~ ERROR statics are not allowed to have destructors
|
||||
|
||||
impl Drop for Test {
|
||||
fn drop(&mut self) {}
|
||||
|
@ -13,14 +13,12 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_uppercase_statics)]
|
||||
#![deny(dead_code)]
|
||||
#![feature(lang_items)]
|
||||
|
||||
#![crate_type="lib"]
|
||||
|
||||
pub use foo2::Bar2;
|
||||
extern crate core;
|
||||
|
||||
#[lang="sized"]
|
||||
pub trait Sized {}
|
||||
pub use foo2::Bar2;
|
||||
|
||||
mod foo {
|
||||
pub struct Bar; //~ ERROR: struct is never used
|
||||
@ -32,10 +30,10 @@ mod foo2 {
|
||||
|
||||
pub static pub_static: int = 0;
|
||||
static priv_static: int = 0; //~ ERROR: static item is never used
|
||||
static used_static: int = 0;
|
||||
const used_static: int = 0;
|
||||
pub static used_static2: int = used_static;
|
||||
static USED_STATIC: int = 0;
|
||||
static STATIC_USED_IN_ENUM_DISCRIMINANT: int = 10;
|
||||
const USED_STATIC: int = 0;
|
||||
const STATIC_USED_IN_ENUM_DISCRIMINANT: int = 10;
|
||||
|
||||
pub type typ = *const UsedStruct4;
|
||||
pub struct PubStruct;
|
||||
@ -107,7 +105,3 @@ fn bar() { //~ ERROR: function is never used
|
||||
#[allow(dead_code)]
|
||||
fn g() { h(); }
|
||||
fn h() {}
|
||||
|
||||
// Similarly, lang items are live
|
||||
#[lang="fail"]
|
||||
fn fail(_: *const u8, _: *const u8, _: uint) -> ! { loop {} }
|
||||
|
@ -17,7 +17,7 @@ enum Direction {
|
||||
West
|
||||
}
|
||||
|
||||
static TRUE_TRUE: (bool, bool) = (true, true);
|
||||
const TRUE_TRUE: (bool, bool) = (true, true);
|
||||
|
||||
fn nonexhaustive_1() {
|
||||
match (true, false) {
|
||||
@ -39,8 +39,8 @@ fn unreachable_1() {
|
||||
}
|
||||
}
|
||||
|
||||
static NONE: Option<Direction> = None;
|
||||
static EAST: Direction = East;
|
||||
const NONE: Option<Direction> = None;
|
||||
const EAST: Direction = East;
|
||||
|
||||
fn nonexhaustive_2() {
|
||||
match Some(Some(North)) {
|
||||
@ -66,13 +66,13 @@ fn unreachable_2() {
|
||||
}
|
||||
}
|
||||
|
||||
static NEW_FALSE: NewBool = NewBool(false);
|
||||
const NEW_FALSE: NewBool = NewBool(false);
|
||||
struct Foo {
|
||||
bar: Option<Direction>,
|
||||
baz: NewBool
|
||||
}
|
||||
|
||||
static STATIC_FOO: Foo = Foo { bar: None, baz: NEW_FALSE };
|
||||
const STATIC_FOO: Foo = Foo { bar: None, baz: NEW_FALSE };
|
||||
|
||||
fn nonexhaustive_3() {
|
||||
match (Foo { bar: Some(North), baz: NewBool(true) }) {
|
||||
|
@ -14,7 +14,7 @@
|
||||
#![deny(non_uppercase_statics)]
|
||||
|
||||
#[allow(non_uppercase_statics)]
|
||||
pub static a : int = 97;
|
||||
pub const a : int = 97;
|
||||
|
||||
fn f() {
|
||||
let r = match (0,0) {
|
||||
@ -27,7 +27,7 @@ fn f() {
|
||||
|
||||
mod m {
|
||||
#[allow(non_uppercase_statics)]
|
||||
pub static aha : int = 7;
|
||||
pub const aha : int = 7;
|
||||
}
|
||||
|
||||
fn g() {
|
||||
@ -41,7 +41,7 @@ fn g() {
|
||||
}
|
||||
|
||||
mod n {
|
||||
pub static OKAY : int = 8;
|
||||
pub const OKAY : int = 8;
|
||||
}
|
||||
|
||||
fn h() {
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
|
||||
static mut a: Box<int> = box 3;
|
||||
//~^ ERROR mutable static items are not allowed to have owned pointers
|
||||
//~^ ERROR statics are not allowed to have custom pointers
|
||||
//~^^ ERROR mutable statics are not allowed to have owned pointers
|
||||
|
||||
fn main() {}
|
||||
|
@ -20,7 +20,7 @@ fn main() {
|
||||
// instead of spitting out a custom error about some identifier collisions
|
||||
// (we should allow shadowing)
|
||||
match 4i {
|
||||
a => {} //~ ERROR mutable static variables cannot be referenced in a pattern
|
||||
a => {} //~ ERROR static variables cannot be referenced in a pattern
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@ -32,7 +32,7 @@ enum Direction {
|
||||
South,
|
||||
West
|
||||
}
|
||||
static NEW_FALSE: NewBool = NewBool(false);
|
||||
const NEW_FALSE: NewBool = NewBool(false);
|
||||
struct Foo {
|
||||
bar: Option<Direction>,
|
||||
baz: NewBool
|
||||
@ -44,7 +44,7 @@ fn mutable_statics() {
|
||||
match (Foo { bar: Some(North), baz: NewBool(true) }) {
|
||||
Foo { bar: None, baz: NewBool(true) } => (),
|
||||
STATIC_MUT_FOO => (),
|
||||
//~^ ERROR mutable static variables cannot be referenced in a pattern
|
||||
//~^ ERROR static variables cannot be referenced in a pattern
|
||||
Foo { bar: Some(South), .. } => (),
|
||||
Foo { bar: Some(EAST), .. } => (),
|
||||
Foo { bar: Some(North), baz: NewBool(true) } => (),
|
||||
|
@ -16,11 +16,11 @@ use std::sync::atomic::*;
|
||||
use std::ptr;
|
||||
|
||||
fn main() {
|
||||
let x = INIT_ATOMIC_BOOL; //~ ERROR cannot move out of static item
|
||||
let x = INIT_ATOMIC_BOOL;
|
||||
let x = *&x; //~ ERROR: cannot move out of dereference
|
||||
let x = INIT_ATOMIC_INT; //~ ERROR cannot move out of static item
|
||||
let x = INIT_ATOMIC_INT;
|
||||
let x = *&x; //~ ERROR: cannot move out of dereference
|
||||
let x = INIT_ATOMIC_UINT; //~ ERROR cannot move out of static item
|
||||
let x = INIT_ATOMIC_UINT;
|
||||
let x = *&x; //~ ERROR: cannot move out of dereference
|
||||
let x: AtomicPtr<uint> = AtomicPtr::new(ptr::null_mut());
|
||||
let x = *&x; //~ ERROR: cannot move out of dereference
|
||||
|
@ -25,7 +25,7 @@ use std::prelude::*;
|
||||
pub fn foo(_: [int, ..(3 as uint)]) { }
|
||||
|
||||
pub fn bar() {
|
||||
static FOO: uint = ((5u as uint) - (4u as uint) as uint);
|
||||
const FOO: uint = ((5u as uint) - (4u as uint) as uint);
|
||||
let _: [(), ..(FOO as uint)] = ([(() as ())] as [(), ..1]);
|
||||
|
||||
let _: [(), ..(1u as uint)] = ([(() as ())] as [(), ..1]);
|
||||
|
@ -17,7 +17,7 @@
|
||||
pub fn foo(_: [int, ..3]) {}
|
||||
|
||||
pub fn bar() {
|
||||
static FOO: uint = 5u - 4u;
|
||||
const FOO: uint = 5u - 4u;
|
||||
let _: [(), ..FOO] = [()];
|
||||
|
||||
let _ : [(), ..1u] = [()];
|
||||
|
@ -7,4 +7,3 @@ all:
|
||||
$(RUSTC) cci_lib.rs
|
||||
$(RUSTC) foo.rs --emit=ir -C codegen-units=3
|
||||
[ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c define\ .*cci_fn)" -eq "2" ]
|
||||
[ "$$(cat "$(TMPDIR)"/foo.?.ll | grep -c CCI_STATIC.*=.*constant)" -eq "2" ]
|
||||
|
@ -14,6 +14,3 @@
|
||||
pub fn cci_fn() -> uint {
|
||||
1234
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub static CCI_STATIC: uint = 2345;
|
||||
|
@ -9,10 +9,10 @@
|
||||
// except according to those terms.
|
||||
|
||||
extern crate cci_lib;
|
||||
use cci_lib::{cci_fn, CCI_STATIC};
|
||||
use cci_lib::{cci_fn};
|
||||
|
||||
fn call1() -> uint {
|
||||
cci_fn() + CCI_STATIC
|
||||
cci_fn()
|
||||
}
|
||||
|
||||
mod a {
|
||||
@ -23,9 +23,8 @@ mod a {
|
||||
}
|
||||
|
||||
mod b {
|
||||
use cci_lib::CCI_STATIC;
|
||||
pub fn call3() -> uint {
|
||||
CCI_STATIC
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
static FOO: &'static [u8] = bytes!("hello, world");
|
||||
|
||||
pub fn main() {
|
||||
let b = match true {
|
||||
let b: &'static [u8] = match true {
|
||||
true => bytes!("test"),
|
||||
false => unreachable!()
|
||||
};
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
|
||||
// issues #10618 and #16382
|
||||
static SIZE: int = 25;
|
||||
const SIZE: int = 25;
|
||||
|
||||
fn main() {
|
||||
let _a: [bool, ..1 as uint];
|
||||
|
@ -11,12 +11,12 @@
|
||||
// Check that the various ways of getting to a reference to a vec (both sized
|
||||
// and unsized) work properly.
|
||||
|
||||
static aa: [int, ..3] = [1, 2, 3];
|
||||
static ab: &'static [int, ..3] = &aa;
|
||||
static ac: &'static [int] = ab;
|
||||
static ad: &'static [int] = &aa;
|
||||
static ae: &'static [int, ..3] = &[1, 2, 3];
|
||||
static af: &'static [int] = &[1, 2, 3];
|
||||
const aa: [int, ..3] = [1, 2, 3];
|
||||
const ab: &'static [int, ..3] = &aa;
|
||||
const ac: &'static [int] = ab;
|
||||
const ad: &'static [int] = &aa;
|
||||
const ae: &'static [int, ..3] = &[1, 2, 3];
|
||||
const af: &'static [int] = &[1, 2, 3];
|
||||
|
||||
static ca: int = aa[0];
|
||||
static cb: int = ab[1];
|
||||
|
@ -12,9 +12,9 @@ extern crate libc;
|
||||
|
||||
extern fn foo() {}
|
||||
|
||||
static x: extern "C" fn() = foo;
|
||||
const x: extern "C" fn() = foo;
|
||||
static y: *const libc::c_void = x as *const libc::c_void;
|
||||
static a: &'static int = &10;
|
||||
const a: &'static int = &10;
|
||||
static b: *const int = a as *const int;
|
||||
|
||||
pub fn main() {
|
||||
|
@ -8,8 +8,8 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
static a: int = 1;
|
||||
static b: int = a + 2;
|
||||
const a: int = 1;
|
||||
const b: int = a + 2;
|
||||
|
||||
pub fn main() {
|
||||
assert_eq!(b, 3);
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
static C: &'static int = &1000;
|
||||
const C: &'static int = &1000;
|
||||
static D: int = *C;
|
||||
|
||||
pub fn main() {
|
||||
|
@ -9,10 +9,10 @@
|
||||
// except according to those terms.
|
||||
|
||||
enum E { V1(int), V0 }
|
||||
static C: &'static [E] = &[V0, V1(0xDEADBEE)];
|
||||
const C: &'static [E] = &[V0, V1(0xDEADBEE)];
|
||||
static C0: E = C[0];
|
||||
static C1: E = C[1];
|
||||
static D: &'static [E, ..2] = &[V0, V1(0xDEADBEE)];
|
||||
const D: &'static [E, ..2] = &[V0, V1(0xDEADBEE)];
|
||||
static D0: E = C[0];
|
||||
static D1: E = C[1];
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
pub fn main() {
|
||||
|
||||
static FOO: uint = 2;
|
||||
const FOO: uint = 2;
|
||||
let _v: [int, ..FOO*3];
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
pub fn main() {
|
||||
|
||||
static FOO: uint = 2;
|
||||
const FOO: uint = 2;
|
||||
let _v = [0i, ..FOO*3*2/2];
|
||||
|
||||
}
|
||||
|
@ -10,20 +10,20 @@
|
||||
|
||||
extern crate debug;
|
||||
|
||||
static x : [int, ..4] = [1,2,3,4];
|
||||
const x : [int, ..4] = [1,2,3,4];
|
||||
static p : int = x[2];
|
||||
static y : &'static [int] = &[1,2,3,4];
|
||||
const y : &'static [int] = &[1,2,3,4];
|
||||
static q : int = y[2];
|
||||
|
||||
struct S {a: int, b: int}
|
||||
|
||||
static s : S = S {a: 10, b: 20};
|
||||
const s : S = S {a: 10, b: 20};
|
||||
static t : int = s.b;
|
||||
|
||||
struct K {a: int, b: int, c: D}
|
||||
struct D { d: int, e: int }
|
||||
|
||||
static k : K = K {a: 10, b: 20, c: D {d: 30, e: 40}};
|
||||
const k : K = K {a: 10, b: 20, c: D {d: 30, e: 40}};
|
||||
static m : int = k.c.e;
|
||||
|
||||
pub fn main() {
|
||||
|
@ -10,8 +10,8 @@
|
||||
|
||||
type Big = [u64, ..8];
|
||||
struct Pair<'a> { a: int, b: &'a Big }
|
||||
static x: &'static Big = &([13, 14, 10, 13, 11, 14, 14, 15]);
|
||||
static y: &'static Pair<'static> = &Pair {a: 15, b: x};
|
||||
const x: &'static Big = &([13, 14, 10, 13, 11, 14, 14, 15]);
|
||||
const y: &'static Pair<'static> = &Pair {a: 15, b: x};
|
||||
|
||||
pub fn main() {
|
||||
assert_eq!(x as *const Big, y.b as *const Big);
|
||||
|
@ -10,9 +10,9 @@
|
||||
|
||||
struct Pair<'a> { a: int, b: &'a int }
|
||||
|
||||
static x: &'static int = &10;
|
||||
const x: &'static int = &10;
|
||||
|
||||
static y: &'static Pair<'static> = &Pair {a: 15, b: x};
|
||||
const y: &'static Pair<'static> = &Pair {a: 15, b: x};
|
||||
|
||||
pub fn main() {
|
||||
println!("x = {}", *x);
|
||||
|
@ -10,9 +10,9 @@
|
||||
|
||||
use std::{str, string};
|
||||
|
||||
static A: [u8, ..2] = ['h' as u8, 'i' as u8];
|
||||
static B: &'static [u8, ..2] = &A;
|
||||
static C: *const u8 = B as *const u8;
|
||||
const A: [u8, ..2] = ['h' as u8, 'i' as u8];
|
||||
const B: &'static [u8, ..2] = &A;
|
||||
const C: *const u8 = B as *const u8;
|
||||
|
||||
pub fn main() {
|
||||
unsafe {
|
||||
|
@ -22,10 +22,10 @@ impl cmp::PartialEq for foo {
|
||||
fn ne(&self, other: &foo) -> bool { !(*self).eq(other) }
|
||||
}
|
||||
|
||||
static x : foo = foo { a:1, b:2, c: 3 };
|
||||
static y : foo = foo { b:2, c:3, a: 1 };
|
||||
static z : &'static foo = &foo { a: 10, b: 22, c: 12 };
|
||||
static w : foo = foo { a:5, ..x };
|
||||
const x : foo = foo { a:1, b:2, c: 3 };
|
||||
const y : foo = foo { b:2, c:3, a: 1 };
|
||||
const z : &'static foo = &foo { a: 10, b: 22, c: 12 };
|
||||
const w : foo = foo { a:5, ..x };
|
||||
|
||||
pub fn main() {
|
||||
assert_eq!(x.b, 2);
|
||||
|
@ -8,8 +8,8 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
static FOO: int = 10;
|
||||
static BAR: int = 3;
|
||||
const FOO: int = 10;
|
||||
const BAR: int = 3;
|
||||
|
||||
pub fn main() {
|
||||
let x: int = 3i;
|
||||
|
@ -12,13 +12,13 @@ enum Flopsy {
|
||||
Bunny = 2
|
||||
}
|
||||
|
||||
static BAR:uint = Bunny as uint;
|
||||
static BAR2:uint = BAR;
|
||||
const BAR:uint = Bunny as uint;
|
||||
const BAR2:uint = BAR;
|
||||
|
||||
pub fn main() {
|
||||
let _v = [0i, .. Bunny as uint];
|
||||
let _v = [0i, .. BAR];
|
||||
let _v = [0i, .. BAR2];
|
||||
static BAR3:uint = BAR2;
|
||||
const BAR3:uint = BAR2;
|
||||
let _v = [0i, .. BAR3];
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
static TEST_STR: &'static str = "abcd";
|
||||
const TEST_STR: &'static str = "abcd";
|
||||
|
||||
fn main() {
|
||||
let s = "abcd";
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
use std::u8;
|
||||
|
||||
static NUM: uint = u8::BITS as uint;
|
||||
const NUM: uint = u8::BITS as uint;
|
||||
|
||||
struct MyStruct { nums: [uint, ..8] }
|
||||
|
||||
|
@ -8,8 +8,10 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
static X: u64 = -1 as u16 as u64;
|
||||
static Y: u64 = -1 as u32 as u64;
|
||||
static X2: u64 = -1 as u16 as u64;
|
||||
static Y2: u64 = -1 as u32 as u64;
|
||||
const X: u64 = -1 as u16 as u64;
|
||||
const Y: u64 = -1 as u32 as u64;
|
||||
|
||||
fn main() {
|
||||
assert_eq!(match 1 {
|
||||
|
@ -8,9 +8,6 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Verify that it is not possible to take the address of
|
||||
// static items with unsafe interior.
|
||||
|
||||
use std::kinds::marker;
|
||||
use std::cell::UnsafeCell;
|
||||
|
||||
@ -30,10 +27,10 @@ enum UnsafeEnum<T> {
|
||||
static STATIC1: UnsafeEnum<int> = VariantSafe;
|
||||
|
||||
static STATIC2: UnsafeCell<int> = UnsafeCell { value: 1 };
|
||||
static STATIC3: MyUnsafe<int> = MyUnsafe{value: STATIC2};
|
||||
const CONST: UnsafeCell<int> = UnsafeCell { value: 1 };
|
||||
static STATIC3: MyUnsafe<int> = MyUnsafe{value: CONST};
|
||||
|
||||
static STATIC4: &'static UnsafeCell<int> = &STATIC2;
|
||||
//~^ ERROR borrow of immutable static items with unsafe interior is not allowed
|
||||
|
||||
struct Wrap<T> {
|
||||
value: T
|
||||
@ -41,14 +38,11 @@ struct Wrap<T> {
|
||||
|
||||
static UNSAFE: UnsafeCell<int> = UnsafeCell{value: 1};
|
||||
static WRAPPED_UNSAFE: Wrap<&'static UnsafeCell<int>> = Wrap { value: &UNSAFE };
|
||||
//~^ ERROR borrow of immutable static items with unsafe interior is not allowed
|
||||
|
||||
fn main() {
|
||||
let a = &STATIC1;
|
||||
//~^ ERROR borrow of immutable static items with unsafe interior is not allowed
|
||||
|
||||
STATIC3.forbidden()
|
||||
//~^ ERROR borrow of immutable static items with unsafe interior is not allowed
|
||||
}
|
||||
|
||||
|
83
src/test/run-pass/issue-17718.rs
Normal file
83
src/test/run-pass/issue-17718.rs
Normal file
@ -0,0 +1,83 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
// aux-build:issue-17718.rs
|
||||
|
||||
extern crate "issue-17718" as other;
|
||||
|
||||
use std::sync::atomic;
|
||||
|
||||
const C1: uint = 1;
|
||||
const C2: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
|
||||
const C3: fn() = foo;
|
||||
const C4: uint = C1 * C1 + C1 / C1;
|
||||
const C5: &'static uint = &C4;
|
||||
const C6: uint = {
|
||||
const C: uint = 3;
|
||||
C
|
||||
};
|
||||
|
||||
static S1: uint = 3;
|
||||
static S2: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
|
||||
|
||||
mod test {
|
||||
static A: uint = 4;
|
||||
static B: &'static uint = &A;
|
||||
static C: &'static uint = &(A);
|
||||
}
|
||||
|
||||
fn foo() {}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(C1, 1);
|
||||
assert_eq!(C3(), ());
|
||||
assert_eq!(C2.fetch_add(1, atomic::SeqCst), 0);
|
||||
assert_eq!(C2.fetch_add(1, atomic::SeqCst), 0);
|
||||
assert_eq!(C4, 2);
|
||||
assert_eq!(*C5, 2);
|
||||
assert_eq!(C6, 3);
|
||||
assert_eq!(S1, 3);
|
||||
assert_eq!(S2.fetch_add(1, atomic::SeqCst), 0);
|
||||
assert_eq!(S2.fetch_add(1, atomic::SeqCst), 1);
|
||||
|
||||
match 1 {
|
||||
C1 => {}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
let _a = C1;
|
||||
let _a = C2;
|
||||
let _a = C3;
|
||||
let _a = C4;
|
||||
let _a = C5;
|
||||
let _a = C6;
|
||||
let _a = S1;
|
||||
|
||||
assert_eq!(other::C1, 1);
|
||||
assert_eq!(other::C3(), ());
|
||||
assert_eq!(other::C2.fetch_add(1, atomic::SeqCst), 0);
|
||||
assert_eq!(other::C2.fetch_add(1, atomic::SeqCst), 0);
|
||||
assert_eq!(other::C4, 2);
|
||||
assert_eq!(*other::C5, 2);
|
||||
assert_eq!(other::S1, 3);
|
||||
assert_eq!(other::S2.fetch_add(1, atomic::SeqCst), 0);
|
||||
assert_eq!(other::S2.fetch_add(1, atomic::SeqCst), 1);
|
||||
|
||||
let _a = other::C1;
|
||||
let _a = other::C2;
|
||||
let _a = other::C3;
|
||||
let _a = other::C4;
|
||||
let _a = other::C5;
|
||||
|
||||
match 1 {
|
||||
other::C1 => {}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@
|
||||
|
||||
pub fn main() {
|
||||
let _foo = 100i;
|
||||
static quux: int = 5;
|
||||
const quux: int = 5;
|
||||
|
||||
enum Stuff {
|
||||
Bar = quux
|
||||
|
@ -8,8 +8,8 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
static INVALID_ENUM : u32 = 0;
|
||||
static INVALID_VALUE : u32 = 1;
|
||||
const INVALID_ENUM : u32 = 0;
|
||||
const INVALID_VALUE : u32 = 1;
|
||||
|
||||
fn gl_err_str(err: u32) -> String
|
||||
{
|
||||
|
@ -9,7 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
pub fn main() {
|
||||
static FOO: f64 = 10.0;
|
||||
const FOO: f64 = 10.0;
|
||||
|
||||
match 0.0 {
|
||||
0.0 ... FOO => (),
|
||||
|
@ -9,5 +9,5 @@
|
||||
// except according to those terms.
|
||||
|
||||
pub fn main() {
|
||||
static S: uint = 23 as uint; [0i, ..S]; ()
|
||||
const S: uint = 23 as uint; [0i, ..S]; ()
|
||||
}
|
||||
|
@ -29,19 +29,19 @@ enum EnumWithStructVariants {
|
||||
}
|
||||
}
|
||||
|
||||
static TRUE_TRUE: (bool, bool) = (true, true);
|
||||
static NONE: Option<Direction> = None;
|
||||
static EAST: Direction = East;
|
||||
static NEW_FALSE: NewBool = NewBool(false);
|
||||
static STATIC_FOO: Foo = Foo { bar: Some(South), baz: NEW_FALSE };
|
||||
static VARIANT2_NORTH: EnumWithStructVariants = Variant2 { dir: North };
|
||||
const TRUE_TRUE: (bool, bool) = (true, true);
|
||||
const NONE: Option<Direction> = None;
|
||||
const EAST: Direction = East;
|
||||
const NEW_FALSE: NewBool = NewBool(false);
|
||||
const STATIC_FOO: Foo = Foo { bar: Some(South), baz: NEW_FALSE };
|
||||
const VARIANT2_NORTH: EnumWithStructVariants = Variant2 { dir: North };
|
||||
|
||||
pub mod glfw {
|
||||
pub struct InputState(uint);
|
||||
|
||||
pub static RELEASE : InputState = InputState(0);
|
||||
pub static PRESS : InputState = InputState(1);
|
||||
pub static REPEAT : InputState = InputState(2);
|
||||
pub const RELEASE : InputState = InputState(0);
|
||||
pub const PRESS : InputState = InputState(1);
|
||||
pub const REPEAT : InputState = InputState(2);
|
||||
}
|
||||
|
||||
fn issue_6533() {
|
||||
@ -63,7 +63,7 @@ fn issue_6533() {
|
||||
}
|
||||
|
||||
fn issue_13626() {
|
||||
static VAL: [u8, ..1] = [0];
|
||||
const VAL: [u8, ..1] = [0];
|
||||
match [1] {
|
||||
VAL => unreachable!(),
|
||||
_ => ()
|
||||
@ -72,8 +72,8 @@ fn issue_13626() {
|
||||
|
||||
fn issue_14576() {
|
||||
type Foo = (i32, i32);
|
||||
static ON: Foo = (1, 1);
|
||||
static OFF: Foo = (0, 0);
|
||||
const ON: Foo = (1, 1);
|
||||
const OFF: Foo = (0, 0);
|
||||
|
||||
match (1, 1) {
|
||||
OFF => unreachable!(),
|
||||
@ -82,14 +82,14 @@ fn issue_14576() {
|
||||
}
|
||||
|
||||
enum C { D = 3, E = 4 }
|
||||
static F : C = D;
|
||||
const F : C = D;
|
||||
|
||||
assert_eq!(match D { F => 1i, _ => 2, }, 1);
|
||||
}
|
||||
|
||||
fn issue_13731() {
|
||||
enum A { AA(()) }
|
||||
static B: A = AA(());
|
||||
const B: A = AA(());
|
||||
|
||||
match AA(()) {
|
||||
B => ()
|
||||
@ -102,8 +102,8 @@ fn issue_15393() {
|
||||
bits: uint
|
||||
}
|
||||
|
||||
static FOO: Flags = Flags { bits: 0x01 };
|
||||
static BAR: Flags = Flags { bits: 0x02 };
|
||||
const FOO: Flags = Flags { bits: 0x01 };
|
||||
const BAR: Flags = Flags { bits: 0x02 };
|
||||
match (Flags { bits: 0x02 }) {
|
||||
FOO => unreachable!(),
|
||||
BAR => (),
|
||||
|
@ -8,8 +8,8 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
static s: int = 1;
|
||||
static e: int = 42;
|
||||
const s: int = 1;
|
||||
const e: int = 42;
|
||||
|
||||
pub fn main() {
|
||||
match 7 {
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
#![deny(non_uppercase_statics)]
|
||||
|
||||
pub static A : int = 97;
|
||||
pub const A : int = 97;
|
||||
|
||||
fn f() {
|
||||
let r = match (0,0) {
|
||||
@ -35,7 +35,7 @@ fn f() {
|
||||
|
||||
mod m {
|
||||
#[allow(non_uppercase_statics)]
|
||||
pub static aha : int = 7;
|
||||
pub const aha : int = 7;
|
||||
}
|
||||
|
||||
fn g() {
|
||||
|
@ -8,6 +8,6 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
static foo: int = 4 >> 1;
|
||||
const foo: int = 4 >> 1;
|
||||
enum bs { thing = foo }
|
||||
pub fn main() { assert!((thing as int == foo)); }
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
fn pad() -> uint { 0 }
|
||||
|
||||
static ONE: uint = 1;
|
||||
const ONE: uint = 1;
|
||||
|
||||
mod b {
|
||||
// Separate compilation always switches to the LLVM module with the fewest
|
||||
@ -28,7 +28,7 @@ mod b {
|
||||
mod a {
|
||||
fn pad() -> uint { 0 }
|
||||
|
||||
pub static TWO: uint = ::ONE + ::ONE;
|
||||
pub const TWO: uint = ::ONE + ::ONE;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -11,15 +11,15 @@
|
||||
static static_vec: &'static [u8] = bytes!("abc", 0xFF, '!');
|
||||
|
||||
pub fn main() {
|
||||
let vec = bytes!("abc");
|
||||
let vec: &'static [u8] = bytes!("abc");
|
||||
let expected: &[u8] = &[97_u8, 98_u8, 99_u8];
|
||||
assert_eq!(vec, expected);
|
||||
|
||||
let vec = bytes!("null", 0);
|
||||
let vec: &'static [u8] = bytes!("null", 0);
|
||||
let expected: &[u8] = &[110_u8, 117_u8, 108_u8, 108_u8, 0_u8];
|
||||
assert_eq!(vec, expected);
|
||||
|
||||
let vec = bytes!(' ', " ", 32, 32u8);
|
||||
let vec: &'static [u8] = bytes!(' ', " ", 32, 32u8);
|
||||
let expected: &[u8] = &[32_u8, 32_u8, 32_u8, 32_u8];
|
||||
assert_eq!(vec, expected);
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
use std::task;
|
||||
use std::rand::{task_rng, Rng};
|
||||
|
||||
static MAX_LEN: uint = 20;
|
||||
const MAX_LEN: uint = 20;
|
||||
static mut drop_counts: [uint, .. MAX_LEN] = [0, .. MAX_LEN];
|
||||
static mut clone_count: uint = 0;
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
// aux-build:xcrate_unit_struct.rs
|
||||
extern crate xcrate_unit_struct;
|
||||
|
||||
static s1: xcrate_unit_struct::Struct = xcrate_unit_struct::Struct;
|
||||
const s1: xcrate_unit_struct::Struct = xcrate_unit_struct::Struct;
|
||||
static s2: xcrate_unit_struct::Unit = xcrate_unit_struct::UnitVariant;
|
||||
static s3: xcrate_unit_struct::Unit =
|
||||
xcrate_unit_struct::Argument(xcrate_unit_struct::Struct);
|
||||
|
Loading…
Reference in New Issue
Block a user