Skip to content

Commit 1376cbd

Browse files
author
Oliver Schneider
committed
lint on statics that could be replaced by constants
1 parent 2c8d75d commit 1376cbd

File tree

34 files changed

+108
-76
lines changed

34 files changed

+108
-76
lines changed

src/etc/ziggurat_tables.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ def exp_f_inv(y):
8585

8686
# Output the tables/constants/types
8787

88-
def render_static(name, type, value):
88+
def render_static(name, value):
8989
# no space or
90-
return 'pub static %s: %s =%s;\n' % (name, type, value)
90+
return 'pub const %s: ZigTable = &%s;\n' % (name, value)
9191

92-
# static `name`: [`type`, .. `len(values)`] =
92+
# const `name`: ZigTable = &
9393
# [values[0], ..., values[3],
9494
# values[4], ..., values[7],
9595
# ... ];
@@ -101,7 +101,7 @@ def render_table(name, values):
101101
rows.append(', '.join('%.18f' % f for f in row))
102102

103103
rendered = '\n [%s]' % ',\n '.join(rows)
104-
return render_static(name, '[f64, .. %d]' % len(values), rendered)
104+
return render_static(name, rendered)
105105

106106

107107
with open('ziggurat_tables.rs', 'w') as f:

src/liballoc/boxed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ use core::raw::{TraitObject};
8181
#[lang = "exchange_heap"]
8282
#[unstable(feature = "alloc",
8383
reason = "may be renamed; uncertain about custom allocator design")]
84-
pub static HEAP: () = ();
84+
pub const HEAP: () = ();
8585

8686
/// A pointer type for heap allocation.
8787
///

src/libcollections/bit.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ fn match_words <'a,'b>(a: &'a BitVec, b: &'b BitVec) -> (MatchWords<'a>, MatchWo
125125
}
126126
}
127127

128-
static TRUE: bool = true;
129-
static FALSE: bool = false;
128+
const TRUE: &'static bool = &true;
129+
const FALSE: &'static bool = &false;
130130

131131
/// The bitvector type.
132132
///
@@ -172,9 +172,9 @@ impl Index<usize> for BitVec {
172172
#[inline]
173173
fn index(&self, i: usize) -> &bool {
174174
if self.get(i).expect("index out of bounds") {
175-
&TRUE
175+
TRUE
176176
} else {
177-
&FALSE
177+
FALSE
178178
}
179179
}
180180
}

src/libcollections/vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ use borrow::{Cow, IntoCow};
8383
use super::range::RangeArgument;
8484

8585
// FIXME- fix places which assume the max vector allowed has memory usize::MAX.
86-
static MAX_MEMORY_SIZE: usize = isize::MAX as usize;
86+
const MAX_MEMORY_SIZE: usize = isize::MAX as usize;
8787

8888
/// A growable list type, written `Vec<T>` but pronounced 'vector.'
8989
///

src/libcore/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ macro_rules! panic {
1515
panic!("explicit panic")
1616
);
1717
($msg:expr) => ({
18-
static _MSG_FILE_LINE: (&'static str, &'static str, u32) = ($msg, file!(), line!());
18+
const _MSG_FILE_LINE: (&'static str, &'static str, u32) = ($msg, file!(), line!());
1919
::core::panicking::panic(&_MSG_FILE_LINE)
2020
});
2121
($fmt:expr, $($arg:tt)*) => ({
2222
// The leading _'s are to avoid dead code warnings if this is
2323
// used inside a dead function. Just `#[allow(dead_code)]` is
2424
// insufficient, since the user may have
2525
// `#[forbid(dead_code)]` and which cannot be overridden.
26-
static _FILE_LINE: (&'static str, u32) = (file!(), line!());
26+
const _FILE_LINE: (&'static str, u32) = (file!(), line!());
2727
::core::panicking::panic_fmt(format_args!($fmt, $($arg)*), &_FILE_LINE)
2828
});
2929
}

src/libcore/num/flt2dec/strategy/dragon.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,19 @@ use num::flt2dec::estimator::estimate_scaling_factor;
2424
use num::flt2dec::bignum::Digit32 as Digit;
2525
use num::flt2dec::bignum::Big32x36 as Big;
2626

27-
// FIXME(#22540) const ref to static array seems to ICE
28-
static POW10: [Digit; 10] = [1, 10, 100, 1000, 10000, 100000,
27+
const POW10: [Digit; 10] = [1, 10, 100, 1000, 10000, 100000,
2928
1000000, 10000000, 100000000, 1000000000];
30-
static TWOPOW10: [Digit; 10] = [2, 20, 200, 2000, 20000, 200000,
29+
const TWOPOW10: [Digit; 10] = [2, 20, 200, 2000, 20000, 200000,
3130
2000000, 20000000, 200000000, 2000000000];
3231

3332
// precalculated arrays of `Digit`s for 10^(2^n)
34-
static POW10TO16: [Digit; 2] = [0x6fc10000, 0x2386f2];
35-
static POW10TO32: [Digit; 4] = [0, 0x85acef81, 0x2d6d415b, 0x4ee];
36-
static POW10TO64: [Digit; 7] = [0, 0, 0xbf6a1f01, 0x6e38ed64, 0xdaa797ed, 0xe93ff9f4, 0x184f03];
37-
static POW10TO128: [Digit; 14] =
33+
const POW10TO16: [Digit; 2] = [0x6fc10000, 0x2386f2];
34+
const POW10TO32: [Digit; 4] = [0, 0x85acef81, 0x2d6d415b, 0x4ee];
35+
const POW10TO64: [Digit; 7] = [0, 0, 0xbf6a1f01, 0x6e38ed64, 0xdaa797ed, 0xe93ff9f4, 0x184f03];
36+
const POW10TO128: [Digit; 14] =
3837
[0, 0, 0, 0, 0x2e953e01, 0x3df9909, 0xf1538fd, 0x2374e42f, 0xd3cff5ec, 0xc404dc08,
3938
0xbccdb0da, 0xa6337f19, 0xe91f2603, 0x24e];
40-
static POW10TO256: [Digit; 27] =
39+
const POW10TO256: [Digit; 27] =
4140
[0, 0, 0, 0, 0, 0, 0, 0, 0x982e7c01, 0xbed3875b, 0xd8d99f72, 0x12152f87, 0x6bde50c6,
4241
0xcf4a6e70, 0xd595d80f, 0x26b2716e, 0xadc666b0, 0x1d153624, 0x3c42d35a, 0x63ff540e,
4342
0xcc5573c0, 0x65f9ef17, 0x55bc28f2, 0x80dcc7f7, 0xf46eeddc, 0x5fdcefce, 0x553f7];
@@ -328,4 +327,3 @@ pub fn format_exact(d: &Decoded, buf: &mut [u8], limit: i16) -> (/*#digits*/ usi
328327

329328
(len, k)
330329
}
331-

src/libcore/num/flt2dec/strategy/grisu.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ for i in xrange(-308, 333, 8):
8787
f = ((f << 64 >> (l-1)) + 1) >> 1; e += l - 64
8888
print ' (%#018x, %5d, %4d),' % (f, e, i)
8989
*/
90-
// FIXME(#22540) const ref to static array seems to ICE
90+
9191
#[doc(hidden)]
92-
pub static CACHED_POW10: [(u64, i16, i16); 81] = [ // (f, e, k)
92+
pub const CACHED_POW10: &'static [(u64, i16, i16); 81] = &[ // (f, e, k)
9393
(0xe61acf033d1a45df, -1087, -308),
9494
(0xab70fe17c79ac6ca, -1060, -300),
9595
(0xff77b1fcbebcdc4f, -1034, -292),
@@ -746,4 +746,3 @@ pub fn format_exact(d: &Decoded, buf: &mut [u8], limit: i16) -> (/*#digits*/ usi
746746
None => fallback(d, buf, limit),
747747
}
748748
}
749-

src/libcore/str/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ fn run_utf8_validation_iterator(iter: &mut slice::Iter<u8>)
12821282
}
12831283

12841284
// https://tools.ietf.org/html/rfc3629
1285-
static UTF8_CHAR_WIDTH: [u8; 256] = [
1285+
const UTF8_CHAR_WIDTH: [u8; 256] = [
12861286
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
12871287
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, // 0x1F
12881288
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,

src/liblog/directive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct LogDirective {
1717
pub level: u32,
1818
}
1919

20-
pub static LOG_LEVEL_NAMES: [&'static str; 4] = ["ERROR", "WARN", "INFO",
20+
pub const LOG_LEVEL_NAMES: [&'static str; 4] = ["ERROR", "WARN", "INFO",
2121
"DEBUG"];
2222

2323
/// Parse an individual log level that is either a number or a symbolic log level

src/liblog/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@
5050
#[macro_export]
5151
macro_rules! log {
5252
($lvl:expr, $($arg:tt)+) => ({
53-
static LOC: ::log::LogLocation = ::log::LogLocation {
53+
const LOC: &'static ::log::LogLocation = &::log::LogLocation {
5454
line: line!(),
5555
file: file!(),
5656
module_path: module_path!(),
5757
};
5858
let lvl = $lvl;
5959
if log_enabled!(lvl) {
60-
::log::log(lvl, &LOC, format_args!($($arg)+))
60+
::log::log(lvl, LOC, format_args!($($arg)+))
6161
}
6262
})
6363
}

0 commit comments

Comments
 (0)