1
Fork 0

core: Convert statics to constants

This commit is contained in:
Alex Crichton 2014-10-06 16:14:00 -07:00
parent 90d03d7926
commit 4d87af9dce
8 changed files with 83 additions and 83 deletions

View file

@ -77,19 +77,19 @@ pub enum Ordering {
/// An `AtomicBool` initialized to `false`
#[unstable = "may be renamed, pending conventions for static initalizers"]
pub static INIT_ATOMIC_BOOL: AtomicBool =
pub const INIT_ATOMIC_BOOL: AtomicBool =
AtomicBool { v: UnsafeCell { value: 0 }, nocopy: marker::NoCopy };
/// An `AtomicInt` initialized to `0`
#[unstable = "may be renamed, pending conventions for static initalizers"]
pub static INIT_ATOMIC_INT: AtomicInt =
pub const INIT_ATOMIC_INT: AtomicInt =
AtomicInt { v: UnsafeCell { value: 0 }, nocopy: marker::NoCopy };
/// An `AtomicUint` initialized to `0`
#[unstable = "may be renamed, pending conventions for static initalizers"]
pub static INIT_ATOMIC_UINT: AtomicUint =
pub const INIT_ATOMIC_UINT: AtomicUint =
AtomicUint { v: UnsafeCell { value: 0, }, nocopy: marker::NoCopy };
// NB: Needs to be -1 (0b11111111...) to make fetch_nand work correctly
static UINT_TRUE: uint = -1;
const UINT_TRUE: uint = -1;
#[stable]
impl AtomicBool {

View file

@ -219,8 +219,8 @@ pub struct RefCell<T> {
// Values [1, MAX-1] represent the number of `Ref` active
// (will not outgrow its range since `uint` is the size of the address space)
type BorrowFlag = uint;
static UNUSED: BorrowFlag = 0;
static WRITING: BorrowFlag = -1;
const UNUSED: BorrowFlag = 0;
const WRITING: BorrowFlag = -1;
impl<T> RefCell<T> {
/// Create a new `RefCell` containing `value`

View file

@ -63,7 +63,7 @@ static MAX_THREE_B: u32 = 0x10000u32;
*/
/// The highest valid code point
pub static MAX: char = '\U0010ffff';
pub const MAX: char = '\U0010ffff';
/// Converts from `u32` to a `char`
#[inline]

View file

@ -20,29 +20,29 @@ use num::{FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
use num::Float;
use option::Option;
pub static RADIX: uint = 2u;
pub const RADIX: uint = 2u;
pub static MANTISSA_DIGITS: uint = 24u;
pub static DIGITS: uint = 6u;
pub const MANTISSA_DIGITS: uint = 24u;
pub const DIGITS: uint = 6u;
pub static EPSILON: f32 = 1.19209290e-07_f32;
pub const EPSILON: f32 = 1.19209290e-07_f32;
/// Smallest finite f32 value
pub static MIN_VALUE: f32 = -3.40282347e+38_f32;
pub const MIN_VALUE: f32 = -3.40282347e+38_f32;
/// Smallest positive, normalized f32 value
pub static MIN_POS_VALUE: f32 = 1.17549435e-38_f32;
pub const MIN_POS_VALUE: f32 = 1.17549435e-38_f32;
/// Largest finite f32 value
pub static MAX_VALUE: f32 = 3.40282347e+38_f32;
pub const MAX_VALUE: f32 = 3.40282347e+38_f32;
pub static MIN_EXP: int = -125;
pub static MAX_EXP: int = 128;
pub const MIN_EXP: int = -125;
pub const MAX_EXP: int = 128;
pub static MIN_10_EXP: int = -37;
pub static MAX_10_EXP: int = 38;
pub const MIN_10_EXP: int = -37;
pub const MAX_10_EXP: int = 38;
pub static NAN: f32 = 0.0_f32/0.0_f32;
pub static INFINITY: f32 = 1.0_f32/0.0_f32;
pub static NEG_INFINITY: f32 = -1.0_f32/0.0_f32;
pub const NAN: f32 = 0.0_f32/0.0_f32;
pub const INFINITY: f32 = 1.0_f32/0.0_f32;
pub const NEG_INFINITY: f32 = -1.0_f32/0.0_f32;
/// Various useful constants.
pub mod consts {
@ -53,55 +53,55 @@ pub mod consts {
// of `Float`.
/// Archimedes' constant
pub static PI: f32 = 3.14159265358979323846264338327950288_f32;
pub const PI: f32 = 3.14159265358979323846264338327950288_f32;
/// pi * 2.0
pub static PI_2: f32 = 6.28318530717958647692528676655900576_f32;
pub const PI_2: f32 = 6.28318530717958647692528676655900576_f32;
/// pi/2.0
pub static FRAC_PI_2: f32 = 1.57079632679489661923132169163975144_f32;
pub const FRAC_PI_2: f32 = 1.57079632679489661923132169163975144_f32;
/// pi/3.0
pub static FRAC_PI_3: f32 = 1.04719755119659774615421446109316763_f32;
pub const FRAC_PI_3: f32 = 1.04719755119659774615421446109316763_f32;
/// pi/4.0
pub static FRAC_PI_4: f32 = 0.785398163397448309615660845819875721_f32;
pub const FRAC_PI_4: f32 = 0.785398163397448309615660845819875721_f32;
/// pi/6.0
pub static FRAC_PI_6: f32 = 0.52359877559829887307710723054658381_f32;
pub const FRAC_PI_6: f32 = 0.52359877559829887307710723054658381_f32;
/// pi/8.0
pub static FRAC_PI_8: f32 = 0.39269908169872415480783042290993786_f32;
pub const FRAC_PI_8: f32 = 0.39269908169872415480783042290993786_f32;
/// 1.0/pi
pub static FRAC_1_PI: f32 = 0.318309886183790671537767526745028724_f32;
pub const FRAC_1_PI: f32 = 0.318309886183790671537767526745028724_f32;
/// 2.0/pi
pub static FRAC_2_PI: f32 = 0.636619772367581343075535053490057448_f32;
pub const FRAC_2_PI: f32 = 0.636619772367581343075535053490057448_f32;
/// 2.0/sqrt(pi)
pub static FRAC_2_SQRTPI: f32 = 1.12837916709551257389615890312154517_f32;
pub const FRAC_2_SQRTPI: f32 = 1.12837916709551257389615890312154517_f32;
/// sqrt(2.0)
pub static SQRT2: f32 = 1.41421356237309504880168872420969808_f32;
pub const SQRT2: f32 = 1.41421356237309504880168872420969808_f32;
/// 1.0/sqrt(2.0)
pub static FRAC_1_SQRT2: f32 = 0.707106781186547524400844362104849039_f32;
pub const FRAC_1_SQRT2: f32 = 0.707106781186547524400844362104849039_f32;
/// Euler's number
pub static E: f32 = 2.71828182845904523536028747135266250_f32;
pub const E: f32 = 2.71828182845904523536028747135266250_f32;
/// log2(e)
pub static LOG2_E: f32 = 1.44269504088896340735992468100189214_f32;
pub const LOG2_E: f32 = 1.44269504088896340735992468100189214_f32;
/// log10(e)
pub static LOG10_E: f32 = 0.434294481903251827651128918916605082_f32;
pub const LOG10_E: f32 = 0.434294481903251827651128918916605082_f32;
/// ln(2.0)
pub static LN_2: f32 = 0.693147180559945309417232121458176568_f32;
pub const LN_2: f32 = 0.693147180559945309417232121458176568_f32;
/// ln(10.0)
pub static LN_10: f32 = 2.30258509299404568401799145468436421_f32;
pub const LN_10: f32 = 2.30258509299404568401799145468436421_f32;
}
impl Float for f32 {
@ -143,8 +143,8 @@ impl Float for f32 {
/// is going to be tested, it is generally faster to use the specific
/// predicate instead.
fn classify(self) -> FPCategory {
static EXP_MASK: u32 = 0x7f800000;
static MAN_MASK: u32 = 0x007fffff;
const EXP_MASK: u32 = 0x7f800000;
const MAN_MASK: u32 = 0x007fffff;
let bits: u32 = unsafe { mem::transmute(self) };
match (bits & MAN_MASK, bits & EXP_MASK) {

View file

@ -24,31 +24,31 @@ use option::Option;
// constants are implemented in favour of referencing the respective
// members of `Bounded` and `Float`.
pub static RADIX: uint = 2u;
pub const RADIX: uint = 2u;
pub static MANTISSA_DIGITS: uint = 53u;
pub static DIGITS: uint = 15u;
pub const MANTISSA_DIGITS: uint = 53u;
pub const DIGITS: uint = 15u;
pub static EPSILON: f64 = 2.2204460492503131e-16_f64;
pub const EPSILON: f64 = 2.2204460492503131e-16_f64;
/// Smallest finite f64 value
pub static MIN_VALUE: f64 = -1.7976931348623157e+308_f64;
pub const MIN_VALUE: f64 = -1.7976931348623157e+308_f64;
/// Smallest positive, normalized f64 value
pub static MIN_POS_VALUE: f64 = 2.2250738585072014e-308_f64;
pub const MIN_POS_VALUE: f64 = 2.2250738585072014e-308_f64;
/// Largest finite f64 value
pub static MAX_VALUE: f64 = 1.7976931348623157e+308_f64;
pub const MAX_VALUE: f64 = 1.7976931348623157e+308_f64;
pub static MIN_EXP: int = -1021;
pub static MAX_EXP: int = 1024;
pub const MIN_EXP: int = -1021;
pub const MAX_EXP: int = 1024;
pub static MIN_10_EXP: int = -307;
pub static MAX_10_EXP: int = 308;
pub const MIN_10_EXP: int = -307;
pub const MAX_10_EXP: int = 308;
pub static NAN: f64 = 0.0_f64/0.0_f64;
pub const NAN: f64 = 0.0_f64/0.0_f64;
pub static INFINITY: f64 = 1.0_f64/0.0_f64;
pub const INFINITY: f64 = 1.0_f64/0.0_f64;
pub static NEG_INFINITY: f64 = -1.0_f64/0.0_f64;
pub const NEG_INFINITY: f64 = -1.0_f64/0.0_f64;
/// Various useful constants.
pub mod consts {
@ -59,55 +59,55 @@ pub mod consts {
// of `Float`.
/// Archimedes' constant
pub static PI: f64 = 3.14159265358979323846264338327950288_f64;
pub const PI: f64 = 3.14159265358979323846264338327950288_f64;
/// pi * 2.0
pub static PI_2: f64 = 6.28318530717958647692528676655900576_f64;
pub const PI_2: f64 = 6.28318530717958647692528676655900576_f64;
/// pi/2.0
pub static FRAC_PI_2: f64 = 1.57079632679489661923132169163975144_f64;
pub const FRAC_PI_2: f64 = 1.57079632679489661923132169163975144_f64;
/// pi/3.0
pub static FRAC_PI_3: f64 = 1.04719755119659774615421446109316763_f64;
pub const FRAC_PI_3: f64 = 1.04719755119659774615421446109316763_f64;
/// pi/4.0
pub static FRAC_PI_4: f64 = 0.785398163397448309615660845819875721_f64;
pub const FRAC_PI_4: f64 = 0.785398163397448309615660845819875721_f64;
/// pi/6.0
pub static FRAC_PI_6: f64 = 0.52359877559829887307710723054658381_f64;
pub const FRAC_PI_6: f64 = 0.52359877559829887307710723054658381_f64;
/// pi/8.0
pub static FRAC_PI_8: f64 = 0.39269908169872415480783042290993786_f64;
pub const FRAC_PI_8: f64 = 0.39269908169872415480783042290993786_f64;
/// 1.0/pi
pub static FRAC_1_PI: f64 = 0.318309886183790671537767526745028724_f64;
pub const FRAC_1_PI: f64 = 0.318309886183790671537767526745028724_f64;
/// 2.0/pi
pub static FRAC_2_PI: f64 = 0.636619772367581343075535053490057448_f64;
pub const FRAC_2_PI: f64 = 0.636619772367581343075535053490057448_f64;
/// 2.0/sqrt(pi)
pub static FRAC_2_SQRTPI: f64 = 1.12837916709551257389615890312154517_f64;
pub const FRAC_2_SQRTPI: f64 = 1.12837916709551257389615890312154517_f64;
/// sqrt(2.0)
pub static SQRT2: f64 = 1.41421356237309504880168872420969808_f64;
pub const SQRT2: f64 = 1.41421356237309504880168872420969808_f64;
/// 1.0/sqrt(2.0)
pub static FRAC_1_SQRT2: f64 = 0.707106781186547524400844362104849039_f64;
pub const FRAC_1_SQRT2: f64 = 0.707106781186547524400844362104849039_f64;
/// Euler's number
pub static E: f64 = 2.71828182845904523536028747135266250_f64;
pub const E: f64 = 2.71828182845904523536028747135266250_f64;
/// log2(e)
pub static LOG2_E: f64 = 1.44269504088896340735992468100189214_f64;
pub const LOG2_E: f64 = 1.44269504088896340735992468100189214_f64;
/// log10(e)
pub static LOG10_E: f64 = 0.434294481903251827651128918916605082_f64;
pub const LOG10_E: f64 = 0.434294481903251827651128918916605082_f64;
/// ln(2.0)
pub static LN_2: f64 = 0.693147180559945309417232121458176568_f64;
pub const LN_2: f64 = 0.693147180559945309417232121458176568_f64;
/// ln(10.0)
pub static LN_10: f64 = 2.30258509299404568401799145468436421_f64;
pub const LN_10: f64 = 2.30258509299404568401799145468436421_f64;
}
impl Float for f64 {
@ -149,8 +149,8 @@ impl Float for f64 {
/// is going to be tested, it is generally faster to use the specific
/// predicate instead.
fn classify(self) -> FPCategory {
static EXP_MASK: u64 = 0x7ff0000000000000;
static MAN_MASK: u64 = 0x000fffffffffffff;
const EXP_MASK: u64 = 0x7ff0000000000000;
const MAN_MASK: u64 = 0x000fffffffffffff;
let bits: u64 = unsafe { mem::transmute(self) };
match (bits & MAN_MASK, bits & EXP_MASK) {

View file

@ -16,20 +16,20 @@ macro_rules! int_module (($T:ty, $bits:expr) => (
// FIXME(#11621): Should be deprecated once CTFE is implemented in favour of
// calling the `mem::size_of` function.
#[unstable]
pub static BITS : uint = $bits;
pub const BITS : uint = $bits;
// FIXME(#11621): Should be deprecated once CTFE is implemented in favour of
// calling the `mem::size_of` function.
#[unstable]
pub static BYTES : uint = ($bits / 8);
pub const BYTES : uint = ($bits / 8);
// FIXME(#11621): Should be deprecated once CTFE is implemented in favour of
// calling the `Bounded::min_value` function.
#[unstable]
pub static MIN: $T = (-1 as $T) << (BITS - 1);
pub const MIN: $T = (-1 as $T) << (BITS - 1);
// FIXME(#9837): Compute MIN like this so the high bits that shouldn't exist are 0.
// FIXME(#11621): Should be deprecated once CTFE is implemented in favour of
// calling the `Bounded::max_value` function.
#[unstable]
pub static MAX: $T = !MIN;
pub const MAX: $T = !MIN;
))

View file

@ -14,13 +14,13 @@
macro_rules! uint_module (($T:ty, $T_SIGNED:ty, $bits:expr) => (
#[unstable]
pub static BITS : uint = $bits;
pub const BITS : uint = $bits;
#[unstable]
pub static BYTES : uint = ($bits / 8);
pub const BYTES : uint = ($bits / 8);
#[unstable]
pub static MIN: $T = 0 as $T;
pub const MIN: $T = 0 as $T;
#[unstable]
pub static MAX: $T = 0 as $T - 1 as $T;
pub const MAX: $T = 0 as $T - 1 as $T;
))

View file

@ -1049,9 +1049,9 @@ pub struct CharRange {
}
/// Mask of the value bits of a continuation byte
static CONT_MASK: u8 = 0b0011_1111u8;
const CONT_MASK: u8 = 0b0011_1111u8;
/// Value of the tag bits (tag mask is !CONT_MASK) of a continuation byte
static TAG_CONT_U8: u8 = 0b1000_0000u8;
const TAG_CONT_U8: u8 = 0b1000_0000u8;
/// Unsafe operations
pub mod raw {