Skip to content

Commit

Permalink
Rollup merge of rust-lang#22876 - Florob:const, r=nikomatsakis
Browse files Browse the repository at this point in the history
 This changes the type of some public constants/statics in libunicode.
Notably some `&'static &'static [(char, char)]` have changed
to `&'static [(char, char)]`. The regexp crate seems to be the
sole user of these, yet this is technically a [breaking-change]
  • Loading branch information
Manishearth committed Mar 3, 2015
2 parents d0fcb1f + f35f973 commit 393ce18
Show file tree
Hide file tree
Showing 52 changed files with 417 additions and 422 deletions.
4 changes: 2 additions & 2 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn run_rfail_test(config: &Config, props: &TestProps, testfile: &Path) {
};

// The value our Makefile configures valgrind to return on failure
static VALGRIND_ERR: int = 100;
const VALGRIND_ERR: int = 100;
if proc_res.status.matches_exit_status(VALGRIND_ERR) {
fatal_proc_rec("run-fail test isn't valgrind-clean!", &proc_res);
}
Expand All @@ -139,7 +139,7 @@ fn run_rfail_test(config: &Config, props: &TestProps, testfile: &Path) {

fn check_correct_failure_status(proc_res: &ProcRes) {
// The value the rust runtime returns on failure
static RUST_ERR: int = 101;
const RUST_ERR: int = 101;
if !proc_res.status.matches_exit_status(RUST_ERR) {
fatal_proc_rec(
&format!("failure produced the wrong error: {:?}",
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use common::Config;
use std::env;

/// Conversion table from triple OS name to Rust SYSNAME
static OS_TABLE: &'static [(&'static str, &'static str)] = &[
const OS_TABLE: &'static [(&'static str, &'static str)] = &[
("mingw32", "windows"),
("win32", "windows"),
("windows", "windows"),
Expand Down
49 changes: 24 additions & 25 deletions src/etc/unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,11 @@ def emit_bsearch_range_table(f):
fn bsearch_range_table(c: char, r: &'static [(char,char)]) -> bool {
use core::cmp::Ordering::{Equal, Less, Greater};
use core::slice::SliceExt;
r.binary_search(|&(lo,hi)| {
r.binary_search_by(|&(lo,hi)| {
if lo <= c && c <= hi { Equal }
else if hi < c { Less }
else { Greater }
}).found().is_some()
}).is_ok()
}\n
""")

Expand All @@ -303,7 +303,7 @@ def emit_table(f, name, t_data, t_type = "&'static [(char, char)]", is_pub=True,
pub_string = ""
if is_pub:
pub_string = "pub "
f.write(" %sstatic %s: %s = &[\n" % (pub_string, name, t_type))
f.write(" %sconst %s: %s = &[\n" % (pub_string, name, t_type))
data = ""
first = True
for dat in t_data:
Expand All @@ -329,14 +329,14 @@ def emit_property_module(f, mod, tbl, emit_fn):
def emit_regex_module(f, cats, w_data):
f.write("pub mod regex {\n")
regex_class = "&'static [(char, char)]"
class_table = "&'static [(&'static str, &'static %s)]" % regex_class
class_table = "&'static [(&'static str, %s)]" % regex_class

emit_table(f, "UNICODE_CLASSES", cats, class_table,
pfun=lambda x: "(\"%s\",&super::%s::%s_table)" % (x[0], x[1], x[0]))
pfun=lambda x: "(\"%s\",super::%s::%s_table)" % (x[0], x[1], x[0]))

f.write(" pub static PERLD: &'static %s = &super::general_category::Nd_table;\n\n"
f.write(" pub const PERLD: %s = super::general_category::Nd_table;\n\n"
% regex_class)
f.write(" pub static PERLS: &'static %s = &super::property::White_Space_table;\n\n"
f.write(" pub const PERLS: %s = super::property::White_Space_table;\n\n"
% regex_class)

emit_table(f, "PERLW", w_data, regex_class)
Expand All @@ -350,7 +350,7 @@ def emit_conversions_module(f, lowerupper, upperlower):
use core::slice::SliceExt;
use core::option::Option;
use core::option::Option::{Some, None};
use core::slice;
use core::result::Result::{Ok, Err};
pub fn to_lower(c: char) -> char {
match bsearch_case_table(c, LuLl_table) {
Expand All @@ -367,13 +367,13 @@ def emit_conversions_module(f, lowerupper, upperlower):
}
fn bsearch_case_table(c: char, table: &'static [(char, char)]) -> Option<usize> {
match table.binary_search(|&(key, _)| {
match table.binary_search_by(|&(key, _)| {
if c == key { Equal }
else if key < c { Less }
else { Greater }
}) {
slice::BinarySearchResult::Found(i) => Some(i),
slice::BinarySearchResult::NotFound(_) => None,
Ok(i) => Some(i),
Err(_) => None,
}
}
Expand All @@ -386,10 +386,9 @@ def emit_conversions_module(f, lowerupper, upperlower):

def emit_grapheme_module(f, grapheme_table, grapheme_cats):
f.write("""pub mod grapheme {
use core::kinds::Copy;
use core::slice::SliceExt;
pub use self::GraphemeCat::*;
use core::slice;
use core::result::Result::{Ok, Err};
#[allow(non_camel_case_types)]
#[derive(Clone, Copy)]
Expand All @@ -401,16 +400,16 @@ def emit_grapheme_module(f, grapheme_table, grapheme_cats):
fn bsearch_range_value_table(c: char, r: &'static [(char, char, GraphemeCat)]) -> GraphemeCat {
use core::cmp::Ordering::{Equal, Less, Greater};
match r.binary_search(|&(lo, hi, _)| {
match r.binary_search_by(|&(lo, hi, _)| {
if lo <= c && c <= hi { Equal }
else if hi < c { Less }
else { Greater }
}) {
slice::BinarySearchResult::Found(idx) => {
Ok(idx) => {
let (_, _, cat) = r[idx];
cat
}
slice::BinarySearchResult::NotFound(_) => GC_Any
Err(_) => GC_Any
}
}
Expand All @@ -430,20 +429,20 @@ def emit_charwidth_module(f, width_table):
f.write(" use core::option::Option;\n")
f.write(" use core::option::Option::{Some, None};\n")
f.write(" use core::slice::SliceExt;\n")
f.write(" use core::slice;\n")
f.write(" use core::result::Result::{Ok, Err};\n")
f.write("""
fn bsearch_range_value_table(c: char, is_cjk: bool, r: &'static [(char, char, u8, u8)]) -> u8 {
use core::cmp::Ordering::{Equal, Less, Greater};
match r.binary_search(|&(lo, hi, _, _)| {
match r.binary_search_by(|&(lo, hi, _, _)| {
if lo <= c && c <= hi { Equal }
else if hi < c { Less }
else { Greater }
}) {
slice::BinarySearchResult::Found(idx) => {
Ok(idx) => {
let (_, _, r_ncjk, r_cjk) = r[idx];
if is_cjk { r_cjk } else { r_ncjk }
}
slice::BinarySearchResult::NotFound(_) => 1
Err(_) => 1
}
}
""")
Expand Down Expand Up @@ -530,17 +529,17 @@ def comp_pfun(char):
fn bsearch_range_value_table(c: char, r: &'static [(char, char, u8)]) -> u8 {
use core::cmp::Ordering::{Equal, Less, Greater};
use core::slice::SliceExt;
use core::slice;
match r.binary_search(|&(lo, hi, _)| {
use core::result::Result::{Ok, Err};
match r.binary_search_by(|&(lo, hi, _)| {
if lo <= c && c <= hi { Equal }
else if hi < c { Less }
else { Greater }
}) {
slice::BinarySearchResult::Found(idx) => {
Ok(idx) => {
let (_, _, result) = r[idx];
result
}
slice::BinarySearchResult::NotFound(_) => 0
Err(_) => 0
}
}\n
""")
Expand Down Expand Up @@ -609,7 +608,7 @@ def optimize_width_table(wtable):
unicode_version = re.search(pattern, readme.read()).groups()
rf.write("""
/// The version of [Unicode](http://www.unicode.org/)
/// that the `UnicodeChar` and `UnicodeStrPrelude` traits are based on.
/// that the unicode parts of `CharExt` and `UnicodeStrPrelude` traits are based on.
pub const UNICODE_VERSION: (u64, u64, u64) = (%s, %s, %s);
""" % unicode_version)
(canon_decomp, compat_decomp, gencats, combines,
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2544,7 +2544,7 @@ mod bit_vec_bench {

use super::BitVec;

static BENCH_BITS : usize = 1 << 14;
const BENCH_BITS : usize = 1 << 14;

fn rng() -> rand::IsaacRng {
let seed: &[_] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
Expand Down Expand Up @@ -3039,7 +3039,7 @@ mod bit_set_bench {

use super::{BitVec, BitSet};

static BENCH_BITS : usize = 1 << 14;
const BENCH_BITS : usize = 1 << 14;

fn rng() -> rand::IsaacRng {
let seed: &[_] = &[1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,8 +1343,8 @@ fn insertion_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> O

fn merge_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Ordering {
// warning: this wildly uses unsafe.
static BASE_INSERTION: usize = 32;
static LARGE_INSERTION: usize = 16;
const BASE_INSERTION: usize = 32;
const LARGE_INSERTION: usize = 16;

// FIXME #12092: smaller insertion runs seems to make sorting
// vectors of large elements a little faster on some platforms,
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ impl String {
}
}

static TAG_CONT_U8: u8 = 128u8;
static REPLACEMENT: &'static [u8] = b"\xEF\xBF\xBD"; // U+FFFD in UTF-8
const TAG_CONT_U8: u8 = 128u8;
const REPLACEMENT: &'static [u8] = b"\xEF\xBF\xBD"; // U+FFFD in UTF-8
let total = v.len();
fn unsafe_get(xs: &[u8], i: usize) -> u8 {
unsafe { *xs.get_unchecked(i) }
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ use alloc::heap;
#[unstable(feature = "collections")]
pub use VecDeque as RingBuf;

static INITIAL_CAPACITY: usize = 7; // 2^3 - 1
static MINIMUM_CAPACITY: usize = 1; // 2 - 1
const INITIAL_CAPACITY: usize = 7; // 2^3 - 1
const MINIMUM_CAPACITY: usize = 1; // 2 - 1

/// `VecDeque` is a growable ring buffer, which can be used as a
/// double-ended queue efficiently.
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub enum SignFormat {
SignNeg
}

static DIGIT_E_RADIX: u32 = ('e' as u32) - ('a' as u32) + 11;
const DIGIT_E_RADIX: u32 = ('e' as u32) - ('a' as u32) + 11;

/// Converts a number to its string representation as a byte vector.
/// This is meant to be a common base implementation for all numeric string
Expand Down
10 changes: 5 additions & 5 deletions src/libcoretest/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ mod tests {
assert!(-(0b11 as $T) - (1 as $T) == (0b11 as $T).not());
}

static A: $T = 0b0101100;
static B: $T = 0b0100001;
static C: $T = 0b1111001;
const A: $T = 0b0101100;
const B: $T = 0b0100001;
const C: $T = 0b1111001;

static _0: $T = 0;
static _1: $T = !0;
const _0: $T = 0;
const _1: $T = !0;

#[test]
fn test_count_ones() {
Expand Down
10 changes: 5 additions & 5 deletions src/libcoretest/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ mod tests {
assert!(MAX - (0b1011 as $T) == (0b1011 as $T).not());
}

static A: $T = 0b0101100;
static B: $T = 0b0100001;
static C: $T = 0b1111001;
const A: $T = 0b0101100;
const B: $T = 0b0100001;
const C: $T = 0b1111001;

static _0: $T = 0;
static _1: $T = !0;
const _0: $T = 0;
const _1: $T = !0;

#[test]
fn test_count_ones() {
Expand Down
6 changes: 3 additions & 3 deletions src/libflate/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ extern {
-> *mut c_void;
}

static LZ_NORM : c_int = 0x80; // LZ with 128 probes, "normal"
static TINFL_FLAG_PARSE_ZLIB_HEADER : c_int = 0x1; // parse zlib header and adler32 checksum
static TDEFL_WRITE_ZLIB_HEADER : c_int = 0x01000; // write zlib header and adler32 checksum
const LZ_NORM: c_int = 0x80; // LZ with 128 probes, "normal"
const TINFL_FLAG_PARSE_ZLIB_HEADER: c_int = 0x1; // parse zlib header and adler32 checksum
const TDEFL_WRITE_ZLIB_HEADER: c_int = 0x01000; // write zlib header and adler32 checksum

fn deflate_bytes_internal(bytes: &[u8], flags: c_int) -> Option<Bytes> {
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion src/librand/distributions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ fn ziggurat<R: Rng, P, Z>(
mut pdf: P,
mut zero_case: Z)
-> f64 where P: FnMut(f64) -> f64, Z: FnMut(&mut R, f64) -> f64 {
static SCALE: f64 = (1u64 << 53) as f64;
const SCALE: f64 = (1u64 << 53) as f64;
loop {
// reimplement the f64 generation as an optimisation suggested
// by the Doornik paper: we have a lot of precision-space
Expand Down
2 changes: 1 addition & 1 deletion src/librand/isaac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl IsaacRng {
let mut a = self.a;
let mut b = self.b + self.c;

static MIDPOINT: uint = (RAND_SIZE / 2) as uint;
const MIDPOINT: uint = (RAND_SIZE / 2) as uint;

macro_rules! ind {
($x:expr) => ( self.mem[(($x >> 2) as uint & ((RAND_SIZE - 1) as uint))] )
Expand Down
4 changes: 2 additions & 2 deletions src/librand/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ use distributions::{Range, IndependentSample};
use distributions::range::SampleRange;

#[cfg(test)]
static RAND_BENCH_N: u64 = 100;
const RAND_BENCH_N: u64 = 100;

pub mod distributions;
pub mod isaac;
Expand Down Expand Up @@ -342,7 +342,7 @@ impl<'a, R: Rng> Iterator for AsciiGenerator<'a, R> {
type Item = char;

fn next(&mut self) -> Option<char> {
static GEN_ASCII_STR_CHARSET: &'static [u8] =
const GEN_ASCII_STR_CHARSET: &'static [u8] =
b"ABCDEFGHIJKLMNOPQRSTUVWXYZ\
abcdefghijklmnopqrstuvwxyz\
0123456789";
Expand Down
2 changes: 1 addition & 1 deletion src/librand/rand_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl Rand for char {
#[inline]
fn rand<R: Rng>(rng: &mut R) -> char {
// a char is 21 bits
static CHAR_MASK: u32 = 0x001f_ffff;
const CHAR_MASK: u32 = 0x001f_ffff;
loop {
// Rejection sampling. About 0.2% of numbers with at most
// 21-bits are invalid codepoints (surrogates), so this
Expand Down
4 changes: 2 additions & 2 deletions src/librand/reseeding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use core::default::Default;

/// How many bytes of entropy the underling RNG is allowed to generate
/// before it is reseeded.
static DEFAULT_GENERATION_THRESHOLD: uint = 32 * 1024;
const DEFAULT_GENERATION_THRESHOLD: uint = 32 * 1024;

/// A wrapper around any RNG which reseeds the underlying RNG after it
/// has generated a certain number of random bytes.
Expand Down Expand Up @@ -212,7 +212,7 @@ mod test {
assert_eq!(string1, string2);
}

static FILL_BYTES_V_LEN: uint = 13579;
const FILL_BYTES_V_LEN: uint = 13579;
#[test]
fn test_rng_fill_bytes() {
let mut v = repeat(0u8).take(FILL_BYTES_V_LEN).collect::<Vec<_>>();
Expand Down
2 changes: 1 addition & 1 deletion src/librbml/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::old_io;
use std::slice;
use std::iter::repeat;

static BUF_CAPACITY: uint = 128;
const BUF_CAPACITY: uint = 128;

fn combine(seek: SeekStyle, cur: uint, end: uint, offset: i64) -> IoResult<u64> {
// compute offset as signed and clamp to prevent overflow
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ pub fn get_or_default_sysroot() -> Path {
}

#[cfg(windows)]
static PATH_ENTRY_SEPARATOR: &'static str = ";";
const PATH_ENTRY_SEPARATOR: char = ';';
#[cfg(not(windows))]
static PATH_ENTRY_SEPARATOR: &'static str = ":";
const PATH_ENTRY_SEPARATOR: char = ':';

/// Returns RUST_PATH as a string, without default paths added
pub fn get_rust_path() -> Option<String> {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,9 @@ struct Specials {
clean_exit_var: Variable
}

static ACC_READ: u32 = 1;
static ACC_WRITE: u32 = 2;
static ACC_USE: u32 = 4;
const ACC_READ: u32 = 1;
const ACC_WRITE: u32 = 2;
const ACC_USE: u32 = 4;

struct Liveness<'a, 'tcx: 'a> {
ir: &'a mut IrMaps<'a, 'tcx>,
Expand Down
Loading

0 comments on commit 393ce18

Please sign in to comment.