diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-10-06 21:16:35 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-10-09 09:44:52 -0700 |
| commit | d03a4b0046a27968fc4eeaf1847776b90a48264b (patch) | |
| tree | 31bda6459d4342df1e457b25e80b7ffe1ffc6fc4 /src/test | |
| parent | 9c09c9434764127f857a9599b93dc090ac63cc2b (diff) | |
| download | rust-d03a4b0046a27968fc4eeaf1847776b90a48264b.tar.gz rust-d03a4b0046a27968fc4eeaf1847776b90a48264b.zip | |
test: Convert statics to constants
Additionally, add lots of tests for new functionality around statics and `static mut`.
Diffstat (limited to 'src/test')
74 files changed, 535 insertions, 172 deletions
diff --git a/src/test/auxiliary/cci_const.rs b/src/test/auxiliary/cci_const.rs index 17029b9d377..945004ede6d 100644 --- a/src/test/auxiliary/cci_const.rs +++ b/src/test/auxiliary/cci_const.rs @@ -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; diff --git a/src/test/auxiliary/iss.rs b/src/test/auxiliary/iss.rs index 75728c075d1..3a9d76406e1 100644 --- a/src/test/auxiliary/iss.rs +++ b/src/test/auxiliary/iss.rs @@ -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 }; diff --git a/src/test/auxiliary/issue-13620-1.rs b/src/test/auxiliary/issue-13620-1.rs index ddd1012017f..e373421fabf 100644 --- a/src/test/auxiliary/issue-13620-1.rs +++ b/src/test/auxiliary/issue-13620-1.rs @@ -14,6 +14,6 @@ pub struct Foo { extern fn the_foo() {} -pub static FOO: Foo = Foo { +pub const FOO: Foo = Foo { foo: the_foo }; diff --git a/src/test/auxiliary/issue-17718-const-privacy.rs b/src/test/auxiliary/issue-17718-const-privacy.rs new file mode 100644 index 00000000000..3657d39ff77 --- /dev/null +++ b/src/test/auxiliary/issue-17718-const-privacy.rs @@ -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; +} diff --git a/src/test/auxiliary/issue-17718.rs b/src/test/auxiliary/issue-17718.rs new file mode 100644 index 00000000000..f0b431b1db9 --- /dev/null +++ b/src/test/auxiliary/issue-17718.rs @@ -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() {} diff --git a/src/test/auxiliary/issue13213aux.rs b/src/test/auxiliary/issue13213aux.rs index ad8c823b991..5bd52ef5010 100644 --- a/src/test/auxiliary/issue13213aux.rs +++ b/src/test/auxiliary/issue13213aux.rs @@ -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 }; diff --git a/src/test/bench/shootout-fasta-redux.rs b/src/test/bench/shootout-fasta-redux.rs index b8af76ce17c..e151369ff38 100644 --- a/src/test/bench/shootout-fasta-redux.rs +++ b/src/test/bench/shootout-fasta-redux.rs @@ -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 }, diff --git a/src/test/bench/shootout-fasta.rs b/src/test/bench/shootout-fasta.rs index 7565525bc8c..77311edba4e 100644 --- a/src/test/bench/shootout-fasta.rs +++ b/src/test/bench/shootout-fasta.rs @@ -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 diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index 28db9ed14a7..66fe52d9ec7 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -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; diff --git a/src/test/bench/shootout-nbody.rs b/src/test/bench/shootout-nbody.rs index 6a39d2fdbb1..a945e0f7796 100644 --- a/src/test/bench/shootout-nbody.rs +++ b/src/test/bench/shootout-nbody.rs @@ -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 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 73ce488cbc6..2945a050247 100644 --- a/src/test/compile-fail/check-static-immutable-mut-slices.rs +++ b/src/test/compile-fail/check-static-immutable-mut-slices.rs @@ -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() { } diff --git a/src/test/compile-fail/check-static-values-constraints.rs b/src/test/compile-fail/check-static-values-constraints.rs index e29be22ca9a..d23aa317247 100644 --- a/src/test/compile-fail/check-static-values-constraints.rs +++ b/src/test/compile-fail/check-static-values-constraints.rs @@ -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 } diff --git a/src/test/compile-fail/issue-15524.rs b/src/test/compile-fail/issue-15524.rs index 1e7bd6fc623..6d9657ab289 100644 --- a/src/test/compile-fail/issue-15524.rs +++ b/src/test/compile-fail/issue-15524.rs @@ -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, diff --git a/src/test/compile-fail/issue-16149.rs b/src/test/compile-fail/issue-16149.rs index c52c53ec2e9..aa586e58f70 100644 --- a/src/test/compile-fail/issue-16149.rs +++ b/src/test/compile-fail/issue-16149.rs @@ -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 }; } diff --git a/src/test/compile-fail/issue-17718-borrow-interior.rs b/src/test/compile-fail/issue-17718-borrow-interior.rs new file mode 100644 index 00000000000..1f763dbdc9f --- /dev/null +++ b/src/test/compile-fail/issue-17718-borrow-interior.rs @@ -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() {} diff --git a/src/test/compile-fail/issue-17718-const-bad-values.rs b/src/test/compile-fail/issue-17718-const-bad-values.rs new file mode 100644 index 00000000000..6425dbda5c6 --- /dev/null +++ b/src/test/compile-fail/issue-17718-const-bad-values.rs @@ -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() {} + diff --git a/src/test/compile-fail/issue-17718-const-borrow.rs b/src/test/compile-fail/issue-17718-const-borrow.rs new file mode 100644 index 00000000000..21cc9a757cf --- /dev/null +++ b/src/test/compile-fail/issue-17718-const-borrow.rs @@ -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() {} diff --git a/src/test/compile-fail/issue-17718-const-destructors.rs b/src/test/compile-fail/issue-17718-const-destructors.rs index dffbfe15564..e888f917741 100644 --- a/src/test/compile-fail/issue-17718-const-destructors.rs +++ b/src/test/compile-fail/issue-17718-const-destructors.rs @@ -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() {} diff --git a/src/test/compile-fail/issue-17718-const-naming.rs b/src/test/compile-fail/issue-17718-const-naming.rs new file mode 100644 index 00000000000..046f038847b --- /dev/null +++ b/src/test/compile-fail/issue-17718-const-naming.rs @@ -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() {} diff --git a/src/test/compile-fail/issue-17718-const-privacy.rs b/src/test/compile-fail/issue-17718-const-privacy.rs new file mode 100644 index 00000000000..d3be9f3dd3f --- /dev/null +++ b/src/test/compile-fail/issue-17718-const-privacy.rs @@ -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() {} diff --git a/src/test/compile-fail/issue-17718-constants-not-static.rs b/src/test/compile-fail/issue-17718-constants-not-static.rs new file mode 100644 index 00000000000..8c51b592054 --- /dev/null +++ b/src/test/compile-fail/issue-17718-constants-not-static.rs @@ -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() { +} diff --git a/src/test/compile-fail/issue-17718-extern-const.rs b/src/test/compile-fail/issue-17718-extern-const.rs new file mode 100644 index 00000000000..235d1222d81 --- /dev/null +++ b/src/test/compile-fail/issue-17718-extern-const.rs @@ -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() {} diff --git a/src/test/compile-fail/issue-17718-patterns.rs b/src/test/compile-fail/issue-17718-patterns.rs new file mode 100644 index 00000000000..01dfb1b4af9 --- /dev/null +++ b/src/test/compile-fail/issue-17718-patterns.rs @@ -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 => {} + _ => {} + } +} diff --git a/src/test/compile-fail/issue-17718-recursive.rs b/src/test/compile-fail/issue-17718-recursive.rs new file mode 100644 index 00000000000..a13dfe639c1 --- /dev/null +++ b/src/test/compile-fail/issue-17718-recursive.rs @@ -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() {} diff --git a/src/test/compile-fail/issue-17718-references.rs b/src/test/compile-fail/issue-17718-references.rs new file mode 100644 index 00000000000..7b272e1610c --- /dev/null +++ b/src/test/compile-fail/issue-17718-references.rs @@ -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() {} diff --git a/src/test/compile-fail/issue-17718-static-move.rs b/src/test/compile-fail/issue-17718-static-move.rs new file mode 100644 index 00000000000..c57df9a3af4 --- /dev/null +++ b/src/test/compile-fail/issue-17718-static-move.rs @@ -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 +} diff --git a/src/test/compile-fail/issue-17718-static-sync.rs b/src/test/compile-fail/issue-17718-static-sync.rs new file mode 100644 index 00000000000..2304b18adb6 --- /dev/null +++ b/src/test/compile-fail/issue-17718-static-sync.rs @@ -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() {} diff --git a/src/test/compile-fail/issue-4968.rs b/src/test/compile-fail/issue-4968.rs index 220fb76411a..a181215f418 100644 --- a/src/test/compile-fail/issue-4968.rs +++ b/src/test/compile-fail/issue-4968.rs @@ -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)` diff --git a/src/test/compile-fail/issue-7364.rs b/src/test/compile-fail/issue-7364.rs index e29b8bc04d8..7f0d9ef3b11 100644 --- a/src/test/compile-fail/issue-7364.rs +++ b/src/test/compile-fail/issue-7364.rs @@ -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() { } diff --git a/src/test/compile-fail/issue-9243.rs b/src/test/compile-fail/issue-9243.rs index f1400c06ca2..eb3618c9f04 100644 --- a/src/test/compile-fail/issue-9243.rs +++ b/src/test/compile-fail/issue-9243.rs @@ -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) {} diff --git a/src/test/compile-fail/lint-dead-code-1.rs b/src/test/compile-fail/lint-dead-code-1.rs index 45380235a2a..a4320b8dc77 100644 --- a/src/test/compile-fail/lint-dead-code-1.rs +++ b/src/test/compile-fail/lint-dead-code-1.rs @@ -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 {} } diff --git a/src/test/compile-fail/match-arm-statics.rs b/src/test/compile-fail/match-arm-statics.rs index 69cb626b75a..cedc0098c00 100644 --- a/src/test/compile-fail/match-arm-statics.rs +++ b/src/test/compile-fail/match-arm-statics.rs @@ -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) }) { diff --git a/src/test/compile-fail/match-static-const-lc.rs b/src/test/compile-fail/match-static-const-lc.rs index a5dce6ecc6f..af7938948a7 100644 --- a/src/test/compile-fail/match-static-const-lc.rs +++ b/src/test/compile-fail/match-static-const-lc.rs @@ -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() { diff --git a/src/test/compile-fail/static-mut-not-constant.rs b/src/test/compile-fail/static-mut-not-constant.rs index 927006adc9e..84c72de5548 100644 --- a/src/test/compile-fail/static-mut-not-constant.rs +++ b/src/test/compile-fail/static-mut-not-constant.rs @@ -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() {} diff --git a/src/test/compile-fail/static-mut-not-pat.rs b/src/test/compile-fail/static-mut-not-pat.rs index b3e93daccab..b3ffcb0b989 100644 --- a/src/test/compile-fail/static-mut-not-pat.rs +++ b/src/test/compile-fail/static-mut-not-pat.rs @@ -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) } => (), diff --git a/src/test/compile-fail/std-uncopyable-atomics.rs b/src/test/compile-fail/std-uncopyable-atomics.rs index 0e8c2f38afb..c0122b8a2a9 100644 --- a/src/test/compile-fail/std-uncopyable-atomics.rs +++ b/src/test/compile-fail/std-uncopyable-atomics.rs @@ -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 diff --git a/src/test/pretty/issue-4264.pp b/src/test/pretty/issue-4264.pp index 2bc09d7e96e..c5229f0f9f9 100644 --- a/src/test/pretty/issue-4264.pp +++ b/src/test/pretty/issue-4264.pp @@ -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]); diff --git a/src/test/pretty/issue-4264.rs b/src/test/pretty/issue-4264.rs index ad407f48a7a..ad0954e6eab 100644 --- a/src/test/pretty/issue-4264.rs +++ b/src/test/pretty/issue-4264.rs @@ -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] = [()]; diff --git a/src/test/run-make/sepcomp-cci-copies/Makefile b/src/test/run-make/sepcomp-cci-copies/Makefile index fdb39f85197..65db841b0c0 100644 --- a/src/test/run-make/sepcomp-cci-copies/Makefile +++ b/src/test/run-make/sepcomp-cci-copies/Makefile @@ -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" ] diff --git a/src/test/run-make/sepcomp-cci-copies/cci_lib.rs b/src/test/run-make/sepcomp-cci-copies/cci_lib.rs index 099101d6f26..a7cd85db4a2 100644 --- a/src/test/run-make/sepcomp-cci-copies/cci_lib.rs +++ b/src/test/run-make/sepcomp-cci-copies/cci_lib.rs @@ -14,6 +14,3 @@ pub fn cci_fn() -> uint { 1234 } - -#[inline] -pub static CCI_STATIC: uint = 2345; diff --git a/src/test/run-make/sepcomp-cci-copies/foo.rs b/src/test/run-make/sepcomp-cci-copies/foo.rs index c702e578c09..b0642b64cda 100644 --- a/src/test/run-make/sepcomp-cci-copies/foo.rs +++ b/src/test/run-make/sepcomp-cci-copies/foo.rs @@ -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 } } diff --git a/src/test/run-pass/bytes-macro-static.rs b/src/test/run-pass/bytes-macro-static.rs index 7f4bbda8e30..2ce8c40c771 100644 --- a/src/test/run-pass/bytes-macro-static.rs +++ b/src/test/run-pass/bytes-macro-static.rs @@ -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!() }; diff --git a/src/test/run-pass/cast-in-array-size.rs b/src/test/run-pass/cast-in-array-size.rs index 13e5b89b84e..aaffb013ad8 100644 --- a/src/test/run-pass/cast-in-array-size.rs +++ b/src/test/run-pass/cast-in-array-size.rs @@ -10,7 +10,7 @@ // issues #10618 and #16382 -static SIZE: int = 25; +const SIZE: int = 25; fn main() { let _a: [bool, ..1 as uint]; diff --git a/src/test/run-pass/check-static-slice.rs b/src/test/run-pass/check-static-slice.rs index 17957dbcc13..60daedec4c7 100644 --- a/src/test/run-pass/check-static-slice.rs +++ b/src/test/run-pass/check-static-slice.rs @@ -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]; diff --git a/src/test/run-pass/const-cast.rs b/src/test/run-pass/const-cast.rs index 87a4fd1153f..5d8e31f9344 100644 --- a/src/test/run-pass/const-cast.rs +++ b/src/test/run-pass/const-cast.rs @@ -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() { diff --git a/src/test/run-pass/const-const.rs b/src/test/run-pass/const-const.rs index bdb2b3d2110..ba2947f7367 100644 --- a/src/test/run-pass/const-const.rs +++ b/src/test/run-pass/const-const.rs @@ -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); diff --git a/src/test/run-pass/const-deref.rs b/src/test/run-pass/const-deref.rs index 7c2771c3544..480fb50a1ff 100644 --- a/src/test/run-pass/const-deref.rs +++ b/src/test/run-pass/const-deref.rs @@ -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() { diff --git a/src/test/run-pass/const-enum-vec-index.rs b/src/test/run-pass/const-enum-vec-index.rs index 5be21696bd1..2a00daa3c03 100644 --- a/src/test/run-pass/const-enum-vec-index.rs +++ b/src/test/run-pass/const-enum-vec-index.rs @@ -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]; diff --git a/src/test/run-pass/const-expr-in-fixed-length-vec.rs b/src/test/run-pass/const-expr-in-fixed-length-vec.rs index 0440a771e98..317a54e927f 100644 --- a/src/test/run-pass/const-expr-in-fixed-length-vec.rs +++ b/src/test/run-pass/const-expr-in-fixed-length-vec.rs @@ -13,7 +13,7 @@ pub fn main() { - static FOO: uint = 2; + const FOO: uint = 2; let _v: [int, ..FOO*3]; } diff --git a/src/test/run-pass/const-expr-in-vec-repeat.rs b/src/test/run-pass/const-expr-in-vec-repeat.rs index 5dd9f829d0a..54386b33dd9 100644 --- a/src/test/run-pass/const-expr-in-vec-repeat.rs +++ b/src/test/run-pass/const-expr-in-vec-repeat.rs @@ -12,7 +12,7 @@ pub fn main() { - static FOO: uint = 2; + const FOO: uint = 2; let _v = [0i, ..FOO*3*2/2]; } diff --git a/src/test/run-pass/const-fields-and-indexing.rs b/src/test/run-pass/const-fields-and-indexing.rs index ff44c76048f..fc098ff9357 100644 --- a/src/test/run-pass/const-fields-and-indexing.rs +++ b/src/test/run-pass/const-fields-and-indexing.rs @@ -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() { diff --git a/src/test/run-pass/const-region-ptrs-noncopy.rs b/src/test/run-pass/const-region-ptrs-noncopy.rs index 36fe021b97e..5e417efb4b5 100644 --- a/src/test/run-pass/const-region-ptrs-noncopy.rs +++ b/src/test/run-pass/const-region-ptrs-noncopy.rs @@ -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); diff --git a/src/test/run-pass/const-region-ptrs.rs b/src/test/run-pass/const-region-ptrs.rs index 113f13dc4bf..e5d3f0ece0c 100644 --- a/src/test/run-pass/const-region-ptrs.rs +++ b/src/test/run-pass/const-region-ptrs.rs @@ -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); diff --git a/src/test/run-pass/const-str-ptr.rs b/src/test/run-pass/const-str-ptr.rs index 0fef3dd4aac..7395a997a05 100644 --- a/src/test/run-pass/const-str-ptr.rs +++ b/src/test/run-pass/const-str-ptr.rs @@ -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 { diff --git a/src/test/run-pass/const-struct.rs b/src/test/run-pass/const-struct.rs index 0a83d007a06..f2db1191569 100644 --- a/src/test/run-pass/const-struct.rs +++ b/src/test/run-pass/const-struct.rs @@ -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); diff --git a/src/test/run-pass/consts-in-patterns.rs b/src/test/run-pass/consts-in-patterns.rs index 2a15774fb17..87b7fcad385 100644 --- a/src/test/run-pass/consts-in-patterns.rs +++ b/src/test/run-pass/consts-in-patterns.rs @@ -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; diff --git a/src/test/run-pass/enum-vec-initializer.rs b/src/test/run-pass/enum-vec-initializer.rs index b04f5e11042..d51562d2490 100644 --- a/src/test/run-pass/enum-vec-initializer.rs +++ b/src/test/run-pass/enum-vec-initializer.rs @@ -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]; } diff --git a/src/test/run-pass/issue-11940.rs b/src/test/run-pass/issue-11940.rs index bbe7eff229b..1540679b099 100644 --- a/src/test/run-pass/issue-11940.rs +++ b/src/test/run-pass/issue-11940.rs @@ -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"; diff --git a/src/test/run-pass/issue-13763.rs b/src/test/run-pass/issue-13763.rs index 242836dbe02..8b2b732415e 100644 --- a/src/test/run-pass/issue-13763.rs +++ b/src/test/run-pass/issue-13763.rs @@ -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] } diff --git a/src/test/run-pass/issue-17074.rs b/src/test/run-pass/issue-17074.rs index e346148691d..d35c3a587c5 100644 --- a/src/test/run-pass/issue-17074.rs +++ b/src/test/run-pass/issue-17074.rs @@ -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 { diff --git a/src/test/compile-fail/borrowck-forbid-static-unsafe-interior.rs b/src/test/run-pass/issue-17718-static-unsafe-interior.rs index 01a6e33467e..8f76d95c548 100644 --- a/src/test/compile-fail/borrowck-forbid-static-unsafe-interior.rs +++ b/src/test/run-pass/issue-17718-static-unsafe-interior.rs @@ -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 } diff --git a/src/test/run-pass/issue-17718.rs b/src/test/run-pass/issue-17718.rs new file mode 100644 index 00000000000..90a102222ba --- /dev/null +++ b/src/test/run-pass/issue-17718.rs @@ -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!(), + } +} diff --git a/src/test/run-pass/issue-2428.rs b/src/test/run-pass/issue-2428.rs index 8c8b9d5df13..b2ebbf3b148 100644 --- a/src/test/run-pass/issue-2428.rs +++ b/src/test/run-pass/issue-2428.rs @@ -10,7 +10,7 @@ pub fn main() { let _foo = 100i; - static quux: int = 5; + const quux: int = 5; enum Stuff { Bar = quux diff --git a/src/test/run-pass/issue-5353.rs b/src/test/run-pass/issue-5353.rs index 2d729f8ced8..1f6493d961c 100644 --- a/src/test/run-pass/issue-5353.rs +++ b/src/test/run-pass/issue-5353.rs @@ -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 { diff --git a/src/test/run-pass/issue-7222.rs b/src/test/run-pass/issue-7222.rs index b86b9a83e35..65ea895c2c8 100644 --- a/src/test/run-pass/issue-7222.rs +++ b/src/test/run-pass/issue-7222.rs @@ -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 => (), diff --git a/src/test/run-pass/issue-9942.rs b/src/test/run-pass/issue-9942.rs index aa86f488906..b9410ffdb43 100644 --- a/src/test/run-pass/issue-9942.rs +++ b/src/test/run-pass/issue-9942.rs @@ -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]; () } diff --git a/src/test/run-pass/match-arm-statics.rs b/src/test/run-pass/match-arm-statics.rs index 6eb0a4dad1b..29972c0efd0 100644 --- a/src/test/run-pass/match-arm-statics.rs +++ b/src/test/run-pass/match-arm-statics.rs @@ -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 => (), diff --git a/src/test/run-pass/match-range-static.rs b/src/test/run-pass/match-range-static.rs index 08875699245..0feeea70221 100644 --- a/src/test/run-pass/match-range-static.rs +++ b/src/test/run-pass/match-range-static.rs @@ -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 { diff --git a/src/test/run-pass/match-static-const-rename.rs b/src/test/run-pass/match-static-const-rename.rs index 9028e68da1f..f3fe93650af 100644 --- a/src/test/run-pass/match-static-const-rename.rs +++ b/src/test/run-pass/match-static-const-rename.rs @@ -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() { diff --git a/src/test/run-pass/resolve-issue-2428.rs b/src/test/run-pass/resolve-issue-2428.rs index 57f6596d1d7..8aa12aa3e98 100644 --- a/src/test/run-pass/resolve-issue-2428.rs +++ b/src/test/run-pass/resolve-issue-2428.rs @@ -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)); } diff --git a/src/test/run-pass/sepcomp-statics.rs b/src/test/run-pass/sepcomp-statics.rs index 26a652ae0ea..26a5c4d1c50 100644 --- a/src/test/run-pass/sepcomp-statics.rs +++ b/src/test/run-pass/sepcomp-statics.rs @@ -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() { diff --git a/src/test/run-pass/syntax-extension-bytes.rs b/src/test/run-pass/syntax-extension-bytes.rs index 8d5333e5b3f..1f92677fb6f 100644 --- a/src/test/run-pass/syntax-extension-bytes.rs +++ b/src/test/run-pass/syntax-extension-bytes.rs @@ -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); diff --git a/src/test/run-pass/vector-sort-failure-safe.rs b/src/test/run-pass/vector-sort-failure-safe.rs index 542f4dbdf23..a8ab0e48ccf 100644 --- a/src/test/run-pass/vector-sort-failure-safe.rs +++ b/src/test/run-pass/vector-sort-failure-safe.rs @@ -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; diff --git a/src/test/run-pass/xcrate-unit-struct.rs b/src/test/run-pass/xcrate-unit-struct.rs index f66caa5fbfc..7eb73968db5 100644 --- a/src/test/run-pass/xcrate-unit-struct.rs +++ b/src/test/run-pass/xcrate-unit-struct.rs @@ -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); |
