1
Fork 0

change some statics to constants

This commit is contained in:
Oliver 'ker' Schneider 2015-06-07 19:50:13 +02:00
parent 2c8d75d655
commit ec078a033b
13 changed files with 18 additions and 22 deletions

View file

@ -81,7 +81,7 @@ use core::raw::{TraitObject};
#[lang = "exchange_heap"] #[lang = "exchange_heap"]
#[unstable(feature = "alloc", #[unstable(feature = "alloc",
reason = "may be renamed; uncertain about custom allocator design")] reason = "may be renamed; uncertain about custom allocator design")]
pub static HEAP: () = (); pub const HEAP: () = ();
/// A pointer type for heap allocation. /// A pointer type for heap allocation.
/// ///

View file

@ -125,8 +125,8 @@ fn match_words <'a,'b>(a: &'a BitVec, b: &'b BitVec) -> (MatchWords<'a>, MatchWo
} }
} }
static TRUE: bool = true; const TRUE: &'static bool = &true;
static FALSE: bool = false; const FALSE: &'static bool = &false;
/// The bitvector type. /// The bitvector type.
/// ///
@ -172,9 +172,9 @@ impl Index<usize> for BitVec {
#[inline] #[inline]
fn index(&self, i: usize) -> &bool { fn index(&self, i: usize) -> &bool {
if self.get(i).expect("index out of bounds") { if self.get(i).expect("index out of bounds") {
&TRUE TRUE
} else { } else {
&FALSE FALSE
} }
} }
} }

View file

@ -83,7 +83,7 @@ use borrow::{Cow, IntoCow};
use super::range::RangeArgument; use super::range::RangeArgument;
// FIXME- fix places which assume the max vector allowed has memory usize::MAX. // FIXME- fix places which assume the max vector allowed has memory usize::MAX.
static MAX_MEMORY_SIZE: usize = isize::MAX as usize; const MAX_MEMORY_SIZE: usize = isize::MAX as usize;
/// A growable list type, written `Vec<T>` but pronounced 'vector.' /// A growable list type, written `Vec<T>` but pronounced 'vector.'
/// ///

View file

@ -24,7 +24,6 @@ use num::flt2dec::estimator::estimate_scaling_factor;
use num::flt2dec::bignum::Digit32 as Digit; use num::flt2dec::bignum::Digit32 as Digit;
use num::flt2dec::bignum::Big32x36 as Big; use num::flt2dec::bignum::Big32x36 as Big;
// FIXME(#22540) const ref to static array seems to ICE
static POW10: [Digit; 10] = [1, 10, 100, 1000, 10000, 100000, static POW10: [Digit; 10] = [1, 10, 100, 1000, 10000, 100000,
1000000, 10000000, 100000000, 1000000000]; 1000000, 10000000, 100000000, 1000000000];
static TWOPOW10: [Digit; 10] = [2, 20, 200, 2000, 20000, 200000, static TWOPOW10: [Digit; 10] = [2, 20, 200, 2000, 20000, 200000,
@ -328,4 +327,3 @@ pub fn format_exact(d: &Decoded, buf: &mut [u8], limit: i16) -> (/*#digits*/ usi
(len, k) (len, k)
} }

View file

@ -87,7 +87,7 @@ for i in xrange(-308, 333, 8):
f = ((f << 64 >> (l-1)) + 1) >> 1; e += l - 64 f = ((f << 64 >> (l-1)) + 1) >> 1; e += l - 64
print ' (%#018x, %5d, %4d),' % (f, e, i) print ' (%#018x, %5d, %4d),' % (f, e, i)
*/ */
// FIXME(#22540) const ref to static array seems to ICE
#[doc(hidden)] #[doc(hidden)]
pub static CACHED_POW10: [(u64, i16, i16); 81] = [ // (f, e, k) pub static CACHED_POW10: [(u64, i16, i16); 81] = [ // (f, e, k)
(0xe61acf033d1a45df, -1087, -308), (0xe61acf033d1a45df, -1087, -308),
@ -746,4 +746,3 @@ pub fn format_exact(d: &Decoded, buf: &mut [u8], limit: i16) -> (/*#digits*/ usi
None => fallback(d, buf, limit), None => fallback(d, buf, limit),
} }
} }

View file

@ -17,7 +17,7 @@ pub struct LogDirective {
pub level: u32, pub level: u32,
} }
pub static LOG_LEVEL_NAMES: [&'static str; 4] = ["ERROR", "WARN", "INFO", pub const LOG_LEVEL_NAMES: [&'static str; 4] = ["ERROR", "WARN", "INFO",
"DEBUG"]; "DEBUG"];
/// Parse an individual log level that is either a number or a symbolic log level /// Parse an individual log level that is either a number or a symbolic log level

View file

@ -12,7 +12,7 @@
// algorithm. Autogenerated by `ziggurat_tables.py`. // algorithm. Autogenerated by `ziggurat_tables.py`.
pub type ZigTable = &'static [f64; 257]; pub type ZigTable = &'static [f64; 257];
pub static ZIG_NORM_R: f64 = 3.654152885361008796; pub const ZIG_NORM_R: f64 = 3.654152885361008796;
pub static ZIG_NORM_X: [f64; 257] = pub static ZIG_NORM_X: [f64; 257] =
[3.910757959537090045, 3.654152885361008796, 3.449278298560964462, 3.320244733839166074, [3.910757959537090045, 3.654152885361008796, 3.449278298560964462, 3.320244733839166074,
3.224575052047029100, 3.147889289517149969, 3.083526132001233044, 3.027837791768635434, 3.224575052047029100, 3.147889289517149969, 3.083526132001233044, 3.027837791768635434,
@ -145,7 +145,7 @@ pub static ZIG_NORM_F: [f64; 257] =
0.887984660763399880, 0.898095921906304051, 0.908726440060562912, 0.919991505048360247, 0.887984660763399880, 0.898095921906304051, 0.908726440060562912, 0.919991505048360247,
0.932060075968990209, 0.945198953453078028, 0.959879091812415930, 0.977101701282731328, 0.932060075968990209, 0.945198953453078028, 0.959879091812415930, 0.977101701282731328,
1.000000000000000000]; 1.000000000000000000];
pub static ZIG_EXP_R: f64 = 7.697117470131050077; pub const ZIG_EXP_R: f64 = 7.697117470131050077;
pub static ZIG_EXP_X: [f64; 257] = pub static ZIG_EXP_X: [f64; 257] =
[8.697117470131052741, 7.697117470131050077, 6.941033629377212577, 6.478378493832569696, [8.697117470131052741, 7.697117470131050077, 6.941033629377212577, 6.478378493832569696,
6.144164665772472667, 5.882144315795399869, 5.666410167454033697, 5.482890627526062488, 6.144164665772472667, 5.882144315795399869, 5.666410167454033697, 5.482890627526062488,

View file

@ -101,9 +101,8 @@ macro_rules! declare_lint {
#[macro_export] #[macro_export]
macro_rules! lint_array { ($( $lint:expr ),*) => ( macro_rules! lint_array { ($( $lint:expr ),*) => (
{ {
#[allow(non_upper_case_globals)] static ARRAY: LintArray = &[ $( &$lint ),* ];
static array: LintArray = &[ $( &$lint ),* ]; ARRAY
array
} }
) } ) }

View file

@ -55,7 +55,7 @@ use visit_ast;
/// A stable identifier to the particular version of JSON output. /// A stable identifier to the particular version of JSON output.
/// Increment this when the `Crate` and related structures change. /// Increment this when the `Crate` and related structures change.
pub static SCHEMA_VERSION: &'static str = "0.8.3"; pub const SCHEMA_VERSION: &'static str = "0.8.3";
mod inline; mod inline;
mod simplify; mod simplify;

View file

@ -483,7 +483,7 @@ mod tests {
#[test] #[test]
fn multiple_connect_interleaved_greedy_schedule() { fn multiple_connect_interleaved_greedy_schedule() {
static MAX: usize = 10; const MAX: usize = 10;
each_ip(&mut |addr| { each_ip(&mut |addr| {
let acceptor = t!(TcpListener::bind(&addr)); let acceptor = t!(TcpListener::bind(&addr));
@ -890,7 +890,7 @@ mod tests {
socket_addr, name, listener_inner); socket_addr, name, listener_inner);
assert_eq!(format!("{:?}", listener), compare); assert_eq!(format!("{:?}", listener), compare);
let mut stream = t!(TcpStream::connect(&("localhost", let stream = t!(TcpStream::connect(&("localhost",
socket_addr.port()))); socket_addr.port())));
let stream_inner = stream.0.socket().as_inner(); let stream_inner = stream.0.socket().as_inner();
let compare = format!("TcpStream {{ addr: {:?}, \ let compare = format!("TcpStream {{ addr: {:?}, \

View file

@ -187,7 +187,7 @@ mod tests {
assert_eq!(*lock.borrow(), 4950); assert_eq!(*lock.borrow(), 4950);
}); });
for i in 0..100 { for i in 0..100 {
let mut lock = m.lock().unwrap(); let lock = m.lock().unwrap();
*lock.borrow_mut() += i; *lock.borrow_mut() += i;
} }
drop(lock); drop(lock);

View file

@ -200,9 +200,8 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
ident: name.clone(), ident: name.clone(),
attrs: Vec::new(), attrs: Vec::new(),
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,
node: ast::ItemStatic( node: ast::ItemConst(
ty, ty,
ast::MutImmutable,
expr, expr,
), ),
vis: ast::Public, vis: ast::Public,

View file

@ -452,6 +452,7 @@ impl<'a, 'b> Context<'a, 'b> {
Some(ecx.lifetime(sp, special_idents::static_lifetime.name)), Some(ecx.lifetime(sp, special_idents::static_lifetime.name)),
ast::MutImmutable); ast::MutImmutable);
let slice = ecx.expr_vec_slice(sp, pieces); let slice = ecx.expr_vec_slice(sp, pieces);
// static instead of const to speed up codegen by not requiring this to be inlined
let st = ast::ItemStatic(ty, ast::MutImmutable, slice); let st = ast::ItemStatic(ty, ast::MutImmutable, slice);
let name = ecx.ident_of(name); let name = ecx.ident_of(name);