Skip to content

Commit d03a4b0

Browse files
committed
test: Convert statics to constants
Additionally, add lots of tests for new functionality around statics and `static mut`.
1 parent 9c09c94 commit d03a4b0

File tree

74 files changed

+535
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+535
-172
lines changed

src/test/auxiliary/cci_const.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
pub extern fn bar() {
1212
}
1313

14-
pub static foopy: &'static str = "hi there";
15-
pub static uint_val: uint = 12;
16-
pub static uint_expr: uint = (1 << uint_val) - 1;
14+
pub const foopy: &'static str = "hi there";
15+
pub const uint_val: uint = 12;
16+
pub const uint_expr: uint = (1 << uint_val) - 1;

src/test/auxiliary/iss.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct C<'a> {
1717
}
1818

1919
fn no_op() { }
20-
pub static D : C<'static> = C {
20+
pub const D : C<'static> = C {
2121
k: no_op
2222
};
2323

src/test/auxiliary/issue-13620-1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ pub struct Foo {
1414

1515
extern fn the_foo() {}
1616

17-
pub static FOO: Foo = Foo {
17+
pub const FOO: Foo = Foo {
1818
foo: the_foo
1919
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub use foo::FOO2;
12+
13+
pub const FOO: uint = 3;
14+
const BAR: uint = 3;
15+
16+
mod foo {
17+
pub const FOO2: uint = 3;
18+
}

src/test/auxiliary/issue-17718.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::sync::atomic;
12+
13+
pub const C1: uint = 1;
14+
pub const C2: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
15+
pub const C3: fn() = foo;
16+
pub const C4: uint = C1 * C1 + C1 / C1;
17+
pub const C5: &'static uint = &C4;
18+
19+
pub static S1: uint = 3;
20+
pub static S2: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
21+
22+
fn foo() {}

src/test/auxiliary/issue13213aux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod private {
2121
pub struct P {
2222
p: i32,
2323
}
24-
pub static THREE: P = P { p: 3 };
24+
pub const THREE: P = P { p: 3 };
2525
}
2626

2727
pub static A: S = S { p: private::THREE };

src/test/bench/shootout-fasta-redux.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,24 @@ use std::io::{stdout, IoResult};
4545
use std::os;
4646
use std::slice::bytes::copy_memory;
4747

48-
static LINE_LEN: uint = 60;
49-
static LOOKUP_SIZE: uint = 4 * 1024;
50-
static LOOKUP_SCALE: f32 = (LOOKUP_SIZE - 1) as f32;
48+
const LINE_LEN: uint = 60;
49+
const LOOKUP_SIZE: uint = 4 * 1024;
50+
const LOOKUP_SCALE: f32 = (LOOKUP_SIZE - 1) as f32;
5151

5252
// Random number generator constants
53-
static IM: u32 = 139968;
54-
static IA: u32 = 3877;
55-
static IC: u32 = 29573;
53+
const IM: u32 = 139968;
54+
const IA: u32 = 3877;
55+
const IC: u32 = 29573;
5656

57-
static ALU: &'static str = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTG\
57+
const ALU: &'static str = "GGCCGGGCGCGGTGGCTCACGCCTGTAATCCCAGCACTTTG\
5858
GGAGGCCGAGGCGGGCGGATCACCTGAGGTCAGGAGTTCGA\
5959
GACCAGCCTGGCCAACATGGTGAAACCCCGTCTCTACTAAA\
6060
AATACAAAAATTAGCCGGGCGTGGTGGCGCGCGCCTGTAAT\
6161
CCCAGCTACTCGGGAGGCTGAGGCAGGAGAATCGCTTGAAC\
6262
CCGGGAGGCGGAGGTTGCAGTGAGCCGAGATCGCGCCACTG\
6363
CACTCCAGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA";
6464

65-
static NULL_AMINO_ACID: AminoAcid = AminoAcid { c: ' ' as u8, p: 0.0 };
65+
const NULL_AMINO_ACID: AminoAcid = AminoAcid { c: ' ' as u8, p: 0.0 };
6666

6767
static IUB: [AminoAcid, ..15] = [
6868
AminoAcid { c: 'a' as u8, p: 0.27 },

src/test/bench/shootout-fasta.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ use std::io::{BufferedWriter, File};
4545
use std::cmp::min;
4646
use std::os;
4747

48-
static LINE_LENGTH: uint = 60;
49-
static IM: u32 = 139968;
48+
const LINE_LENGTH: uint = 60;
49+
const IM: u32 = 139968;
5050

5151
struct MyRandom {
5252
last: u32

src/test/bench/shootout-mandelbrot.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ use std::os;
4949
use std::simd::f64x2;
5050
use std::sync::{Arc, Future};
5151

52-
static ITER: int = 50;
53-
static LIMIT: f64 = 2.0;
54-
static WORKERS: uint = 16;
52+
const ITER: int = 50;
53+
const LIMIT: f64 = 2.0;
54+
const WORKERS: uint = 16;
5555

5656
#[inline(always)]
5757
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<()> {
144144
fn write_line(init_i: f64, vec_init_r: &[f64], res: &mut Vec<u8>) {
145145
let v_init_i : f64x2 = f64x2(init_i, init_i);
146146
let v_2 : f64x2 = f64x2(2.0, 2.0);
147-
static LIMIT_SQUARED: f64 = LIMIT * LIMIT;
147+
const LIMIT_SQUARED: f64 = LIMIT * LIMIT;
148148

149149
for chunk_init_r in vec_init_r.chunks(8) {
150150
let mut cur_byte = 0xff;

src/test/bench/shootout-nbody.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
3939
// OF THE POSSIBILITY OF SUCH DAMAGE.
4040

41-
static PI: f64 = 3.141592653589793;
42-
static SOLAR_MASS: f64 = 4.0 * PI * PI;
43-
static YEAR: f64 = 365.24;
44-
static N_BODIES: uint = 5;
41+
const PI: f64 = 3.141592653589793;
42+
const SOLAR_MASS: f64 = 4.0 * PI * PI;
43+
const YEAR: f64 = 365.24;
44+
const N_BODIES: uint = 5;
4545

4646
static BODIES: [Planet, ..N_BODIES] = [
4747
// Sun

0 commit comments

Comments
 (0)