diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 12eadcc145d52..4ee500faa22c4 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -81,7 +81,7 @@ use core::raw::{TraitObject}; #[lang = "exchange_heap"] #[unstable(feature = "alloc", reason = "may be renamed; uncertain about custom allocator design")] -pub static HEAP: () = (); +pub const HEAP: () = (); /// A pointer type for heap allocation. /// diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index c06cbdb4179d5..afcdb3efe8ea0 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -125,8 +125,8 @@ fn match_words <'a,'b>(a: &'a BitVec, b: &'b BitVec) -> (MatchWords<'a>, MatchWo } } -static TRUE: bool = true; -static FALSE: bool = false; +const TRUE: &'static bool = &true; +const FALSE: &'static bool = &false; /// The bitvector type. /// @@ -172,9 +172,9 @@ impl Index for BitVec { #[inline] fn index(&self, i: usize) -> &bool { if self.get(i).expect("index out of bounds") { - &TRUE + TRUE } else { - &FALSE + FALSE } } } diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 8dacfa53bc980..d4fecbfec9c71 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -83,7 +83,7 @@ use borrow::{Cow, IntoCow}; use super::range::RangeArgument; // 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` but pronounced 'vector.' /// diff --git a/src/libcore/num/flt2dec/strategy/dragon.rs b/src/libcore/num/flt2dec/strategy/dragon.rs index a819932525bd1..a11377893713d 100644 --- a/src/libcore/num/flt2dec/strategy/dragon.rs +++ b/src/libcore/num/flt2dec/strategy/dragon.rs @@ -24,7 +24,6 @@ use num::flt2dec::estimator::estimate_scaling_factor; use num::flt2dec::bignum::Digit32 as Digit; 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, 1000000, 10000000, 100000000, 1000000000]; 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) } - diff --git a/src/libcore/num/flt2dec/strategy/grisu.rs b/src/libcore/num/flt2dec/strategy/grisu.rs index 220811e9985c3..54d3c92eca466 100644 --- a/src/libcore/num/flt2dec/strategy/grisu.rs +++ b/src/libcore/num/flt2dec/strategy/grisu.rs @@ -87,7 +87,7 @@ for i in xrange(-308, 333, 8): f = ((f << 64 >> (l-1)) + 1) >> 1; e += l - 64 print ' (%#018x, %5d, %4d),' % (f, e, i) */ -// FIXME(#22540) const ref to static array seems to ICE + #[doc(hidden)] pub static CACHED_POW10: [(u64, i16, i16); 81] = [ // (f, e, k) (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), } } - diff --git a/src/liblog/directive.rs b/src/liblog/directive.rs index 9ea680c7efe76..5d38a381e6b7e 100644 --- a/src/liblog/directive.rs +++ b/src/liblog/directive.rs @@ -17,7 +17,7 @@ pub struct LogDirective { 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"]; /// Parse an individual log level that is either a number or a symbolic log level diff --git a/src/librand/distributions/ziggurat_tables.rs b/src/librand/distributions/ziggurat_tables.rs index a108fd70d1ca9..b6de4bf892cdf 100644 --- a/src/librand/distributions/ziggurat_tables.rs +++ b/src/librand/distributions/ziggurat_tables.rs @@ -12,7 +12,7 @@ // algorithm. Autogenerated by `ziggurat_tables.py`. 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] = [3.910757959537090045, 3.654152885361008796, 3.449278298560964462, 3.320244733839166074, 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.932060075968990209, 0.945198953453078028, 0.959879091812415930, 0.977101701282731328, 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] = [8.697117470131052741, 7.697117470131050077, 6.941033629377212577, 6.478378493832569696, 6.144164665772472667, 5.882144315795399869, 5.666410167454033697, 5.482890627526062488, diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 498b2ce518c16..62dc8f7769398 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -101,9 +101,8 @@ macro_rules! declare_lint { #[macro_export] macro_rules! lint_array { ($( $lint:expr ),*) => ( { - #[allow(non_upper_case_globals)] - static array: LintArray = &[ $( &$lint ),* ]; - array + static ARRAY: LintArray = &[ $( &$lint ),* ]; + ARRAY } ) } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 0be8570f90483..b6ef9c88e156f 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -55,7 +55,7 @@ use visit_ast; /// A stable identifier to the particular version of JSON output. /// 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 simplify; diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index cffccab7e09d0..36854db63a303 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -483,7 +483,7 @@ mod tests { #[test] fn multiple_connect_interleaved_greedy_schedule() { - static MAX: usize = 10; + const MAX: usize = 10; each_ip(&mut |addr| { let acceptor = t!(TcpListener::bind(&addr)); @@ -890,7 +890,7 @@ mod tests { socket_addr, name, listener_inner); assert_eq!(format!("{:?}", listener), compare); - let mut stream = t!(TcpStream::connect(&("localhost", + let stream = t!(TcpStream::connect(&("localhost", socket_addr.port()))); let stream_inner = stream.0.socket().as_inner(); let compare = format!("TcpStream {{ addr: {:?}, \ diff --git a/src/libstd/sys/common/remutex.rs b/src/libstd/sys/common/remutex.rs index 72f8453233a41..8f41646417367 100644 --- a/src/libstd/sys/common/remutex.rs +++ b/src/libstd/sys/common/remutex.rs @@ -187,7 +187,7 @@ mod tests { assert_eq!(*lock.borrow(), 4950); }); for i in 0..100 { - let mut lock = m.lock().unwrap(); + let lock = m.lock().unwrap(); *lock.borrow_mut() += i; } drop(lock); diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 620ac1280f48c..54b09d863a33a 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -200,9 +200,8 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, ident: name.clone(), attrs: Vec::new(), id: ast::DUMMY_NODE_ID, - node: ast::ItemStatic( + node: ast::ItemConst( ty, - ast::MutImmutable, expr, ), vis: ast::Public, diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 4fe5ab1554500..86e72d4ef03de 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -452,6 +452,7 @@ impl<'a, 'b> Context<'a, 'b> { Some(ecx.lifetime(sp, special_idents::static_lifetime.name)), ast::MutImmutable); 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 name = ecx.ident_of(name);