Skip to content

change some statics to constants #25823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
8 changes: 4 additions & 4 deletions src/libcollections/bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -172,9 +172,9 @@ impl Index<usize> for BitVec {
#[inline]
fn index(&self, i: usize) -> &bool {
if self.get(i).expect("index out of bounds") {
&TRUE
TRUE
} else {
&FALSE
FALSE
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>` but pronounced 'vector.'
///
Expand Down
2 changes: 0 additions & 2 deletions src/libcore/num/flt2dec/strategy/dragon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -328,4 +327,3 @@ pub fn format_exact(d: &Decoded, buf: &mut [u8], limit: i16) -> (/*#digits*/ usi

(len, k)
}

3 changes: 1 addition & 2 deletions src/libcore/num/flt2dec/strategy/grisu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -746,4 +746,3 @@ pub fn format_exact(d: &Decoded, buf: &mut [u8], limit: i16) -> (/*#digits*/ usi
None => fallback(d, buf, limit),
}
}

2 changes: 1 addition & 1 deletion src/liblog/directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/librand/distributions/ziggurat_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like these are good examples of statics instead of constants, as there's no need to inline this value anywhere and it's large enough to deserve it's own slot in memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought taking the address does give it's own memory slot, it just gives it an anonymous name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but it can still go into the metadata and is also arguably more roundabout (e.g. it's not clear that this is better than a static)

[3.910757959537090045, 3.654152885361008796, 3.449278298560964462, 3.320244733839166074,
3.224575052047029100, 3.147889289517149969, 3.083526132001233044, 3.027837791768635434,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
) }

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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: {:?}, \
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/common/remutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/libsyntax/diagnostics/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/ext/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down