diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs index 7966040ed7b..adb55f2cc8c 100644 --- a/src/libstd/bitflags.rs +++ b/src/libstd/bitflags.rs @@ -24,12 +24,12 @@ /// ```{.rust} /// bitflags! { /// flags Flags: u32 { -/// static FLAG_A = 0x00000001, -/// static FLAG_B = 0x00000010, -/// static FLAG_C = 0x00000100, -/// static FLAG_ABC = FLAG_A.bits -/// | FLAG_B.bits -/// | FLAG_C.bits, +/// const FLAG_A = 0x00000001, +/// const FLAG_B = 0x00000010, +/// const FLAG_C = 0x00000100, +/// const FLAG_ABC = FLAG_A.bits +/// | FLAG_B.bits +/// | FLAG_C.bits, /// } /// } /// @@ -50,8 +50,8 @@ /// /// bitflags! { /// flags Flags: u32 { -/// static FLAG_A = 0x00000001, -/// static FLAG_B = 0x00000010, +/// const FLAG_A = 0x00000001, +/// const FLAG_B = 0x00000010, /// } /// } /// @@ -115,7 +115,7 @@ #[macro_export] macro_rules! bitflags { ($(#[$attr:meta])* flags $BitFlags:ident: $T:ty { - $($(#[$Flag_attr:meta])* static $Flag:ident = $value:expr),+ + $($(#[$Flag_attr:meta])* const $Flag:ident = $value:expr),+ }) => { #[deriving(PartialEq, Eq, Clone, PartialOrd, Ord, Hash)] $(#[$attr])* @@ -123,7 +123,7 @@ macro_rules! bitflags { bits: $T, } - $($(#[$Flag_attr])* pub static $Flag: $BitFlags = $BitFlags { bits: $value };)+ + $($(#[$Flag_attr])* pub const $Flag: $BitFlags = $BitFlags { bits: $value };)+ impl $BitFlags { /// Returns an empty set of flags. @@ -235,12 +235,12 @@ macro_rules! bitflags { } }; ($(#[$attr:meta])* flags $BitFlags:ident: $T:ty { - $($(#[$Flag_attr:meta])* static $Flag:ident = $value:expr),+, + $($(#[$Flag_attr:meta])* const $Flag:ident = $value:expr),+, }) => { bitflags! { $(#[$attr])* flags $BitFlags: $T { - $($(#[$Flag_attr])* static $Flag = $value),+ + $($(#[$Flag_attr])* const $Flag = $value),+ } } }; @@ -259,14 +259,14 @@ mod tests { #[doc = "> "] #[doc = "> - Richard Feynman"] flags Flags: u32 { - static FlagA = 0x00000001, + const FlagA = 0x00000001, #[doc = "<pcwalton> macros are way better at generating code than trans is"] - static FlagB = 0x00000010, - static FlagC = 0x00000100, + const FlagB = 0x00000010, + const FlagC = 0x00000100, #[doc = "* cmr bed"] #[doc = "* strcat table"] #[doc = "<strcat> wait what?"] - static FlagABC = FlagA.bits + const FlagABC = FlagA.bits | FlagB.bits | FlagC.bits, } @@ -274,7 +274,7 @@ mod tests { bitflags! { flags AnotherSetOfFlags: uint { - static AnotherFlag = 1u, + const AnotherFlag = 1u, } } diff --git a/src/libstd/collections/hashmap/map.rs b/src/libstd/collections/hashmap/map.rs index 6b9c76e1568..ef40402105b 100644 --- a/src/libstd/collections/hashmap/map.rs +++ b/src/libstd/collections/hashmap/map.rs @@ -41,8 +41,8 @@ use super::table::{ SafeHash }; -static INITIAL_LOG2_CAP: uint = 5; -pub static INITIAL_CAPACITY: uint = 1 << INITIAL_LOG2_CAP; // 2^5 +const INITIAL_LOG2_CAP: uint = 5; +pub const INITIAL_CAPACITY: uint = 1 << INITIAL_LOG2_CAP; // 2^5 /// The default behavior of HashMap implements a load factor of 90.9%. /// This behavior is characterized by the following conditions: diff --git a/src/libstd/collections/hashmap/table.rs b/src/libstd/collections/hashmap/table.rs index bad5ce3e475..ee64a7931c0 100644 --- a/src/libstd/collections/hashmap/table.rs +++ b/src/libstd/collections/hashmap/table.rs @@ -24,7 +24,7 @@ use ptr::{RawPtr, copy_nonoverlapping_memory, zero_memory}; use ptr; use rt::heap::{allocate, deallocate}; -static EMPTY_BUCKET: u64 = 0u64; +const EMPTY_BUCKET: u64 = 0u64; /// The raw hashtable, providing safe-ish access to the unzipped and highly /// optimized arrays of hashes, keys, and values. diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 280aff71e23..d18b3cdf2e7 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -283,7 +283,7 @@ pub mod util; /// The default buffer size for various I/O operations // libuv recommends 64k buffers to maximize throughput // https://groups.google.com/forum/#!topic/libuv/oQO1HJAIDdA -static DEFAULT_BUF_SIZE: uint = 1024 * 64; +const DEFAULT_BUF_SIZE: uint = 1024 * 64; /// A convenient typedef of the return value of any I/O action. pub type IoResult<T> = Result<T, IoError>; @@ -1803,93 +1803,93 @@ bitflags! { #[doc = "A set of permissions for a file or directory is represented"] #[doc = "by a set of flags which are or'd together."] flags FilePermission: u32 { - static USER_READ = 0o400, - static USER_WRITE = 0o200, - static USER_EXECUTE = 0o100, - static GROUP_READ = 0o040, - static GROUP_WRITE = 0o020, - static GROUP_EXECUTE = 0o010, - static OTHER_READ = 0o004, - static OTHER_WRITE = 0o002, - static OTHER_EXECUTE = 0o001, + const USER_READ = 0o400, + const USER_WRITE = 0o200, + const USER_EXECUTE = 0o100, + const GROUP_READ = 0o040, + const GROUP_WRITE = 0o020, + const GROUP_EXECUTE = 0o010, + const OTHER_READ = 0o004, + const OTHER_WRITE = 0o002, + const OTHER_EXECUTE = 0o001, - static USER_RWX = USER_READ.bits | USER_WRITE.bits | USER_EXECUTE.bits, - static GROUP_RWX = GROUP_READ.bits | GROUP_WRITE.bits | GROUP_EXECUTE.bits, - static OTHER_RWX = OTHER_READ.bits | OTHER_WRITE.bits | OTHER_EXECUTE.bits, + const USER_RWX = USER_READ.bits | USER_WRITE.bits | USER_EXECUTE.bits, + const GROUP_RWX = GROUP_READ.bits | GROUP_WRITE.bits | GROUP_EXECUTE.bits, + const OTHER_RWX = OTHER_READ.bits | OTHER_WRITE.bits | OTHER_EXECUTE.bits, #[doc = "Permissions for user owned files, equivalent to 0644 on"] #[doc = "unix-like systems."] - static USER_FILE = USER_READ.bits | USER_WRITE.bits | GROUP_READ.bits | OTHER_READ.bits, + const USER_FILE = USER_READ.bits | USER_WRITE.bits | GROUP_READ.bits | OTHER_READ.bits, #[doc = "Permissions for user owned directories, equivalent to 0755 on"] #[doc = "unix-like systems."] - static USER_DIR = USER_RWX.bits | GROUP_READ.bits | GROUP_EXECUTE.bits | + const USER_DIR = USER_RWX.bits | GROUP_READ.bits | GROUP_EXECUTE.bits | OTHER_READ.bits | OTHER_EXECUTE.bits, #[doc = "Permissions for user owned executables, equivalent to 0755"] #[doc = "on unix-like systems."] - static USER_EXEC = USER_DIR.bits, + const USER_EXEC = USER_DIR.bits, #[doc = "All possible permissions enabled."] - static ALL_PERMISSIONS = USER_RWX.bits | GROUP_RWX.bits | OTHER_RWX.bits, + const ALL_PERMISSIONS = USER_RWX.bits | GROUP_RWX.bits | OTHER_RWX.bits, // Deprecated names #[allow(non_uppercase_statics)] #[deprecated = "use USER_READ instead"] - static UserRead = USER_READ.bits, + const UserRead = USER_READ.bits, #[allow(non_uppercase_statics)] #[deprecated = "use USER_WRITE instead"] - static UserWrite = USER_WRITE.bits, + const UserWrite = USER_WRITE.bits, #[allow(non_uppercase_statics)] #[deprecated = "use USER_EXECUTE instead"] - static UserExecute = USER_EXECUTE.bits, + const UserExecute = USER_EXECUTE.bits, #[allow(non_uppercase_statics)] #[deprecated = "use GROUP_READ instead"] - static GroupRead = GROUP_READ.bits, + const GroupRead = GROUP_READ.bits, #[allow(non_uppercase_statics)] #[deprecated = "use GROUP_WRITE instead"] - static GroupWrite = GROUP_WRITE.bits, + const GroupWrite = GROUP_WRITE.bits, #[allow(non_uppercase_statics)] #[deprecated = "use GROUP_EXECUTE instead"] - static GroupExecute = GROUP_EXECUTE.bits, + const GroupExecute = GROUP_EXECUTE.bits, #[allow(non_uppercase_statics)] #[deprecated = "use OTHER_READ instead"] - static OtherRead = OTHER_READ.bits, + const OtherRead = OTHER_READ.bits, #[allow(non_uppercase_statics)] #[deprecated = "use OTHER_WRITE instead"] - static OtherWrite = OTHER_WRITE.bits, + const OtherWrite = OTHER_WRITE.bits, #[allow(non_uppercase_statics)] #[deprecated = "use OTHER_EXECUTE instead"] - static OtherExecute = OTHER_EXECUTE.bits, + const OtherExecute = OTHER_EXECUTE.bits, #[allow(non_uppercase_statics)] #[deprecated = "use USER_RWX instead"] - static UserRWX = USER_RWX.bits, + const UserRWX = USER_RWX.bits, #[allow(non_uppercase_statics)] #[deprecated = "use GROUP_RWX instead"] - static GroupRWX = GROUP_RWX.bits, + const GroupRWX = GROUP_RWX.bits, #[allow(non_uppercase_statics)] #[deprecated = "use OTHER_RWX instead"] - static OtherRWX = OTHER_RWX.bits, + const OtherRWX = OTHER_RWX.bits, #[doc = "Deprecated: use `USER_FILE` instead."] #[allow(non_uppercase_statics)] #[deprecated = "use USER_FILE instead"] - static UserFile = USER_FILE.bits, + const UserFile = USER_FILE.bits, #[doc = "Deprecated: use `USER_DIR` instead."] #[allow(non_uppercase_statics)] #[deprecated = "use USER_DIR instead"] - static UserDir = USER_DIR.bits, + const UserDir = USER_DIR.bits, #[doc = "Deprecated: use `USER_EXEC` instead."] #[allow(non_uppercase_statics)] #[deprecated = "use USER_EXEC instead"] - static UserExec = USER_EXEC.bits, + const UserExec = USER_EXEC.bits, #[doc = "Deprecated: use `ALL_PERMISSIONS` instead"] #[allow(non_uppercase_statics)] #[deprecated = "use ALL_PERMISSIONS instead"] - static AllPermissions = ALL_PERMISSIONS.bits, + const AllPermissions = ALL_PERMISSIONS.bits, } } diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index ef336bc7b4f..5de4bc10e1a 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -32,16 +32,16 @@ use std::hash::sip::SipState; /// Signal a process to exit, without forcibly killing it. Corresponds to /// SIGTERM on unix platforms. -#[cfg(windows)] pub static PleaseExitSignal: int = 15; +#[cfg(windows)] pub const PleaseExitSignal: int = 15; /// Signal a process to exit immediately, forcibly killing it. Corresponds to /// SIGKILL on unix platforms. -#[cfg(windows)] pub static MustDieSignal: int = 9; +#[cfg(windows)] pub const MustDieSignal: int = 9; /// Signal a process to exit, without forcibly killing it. Corresponds to /// SIGTERM on unix platforms. -#[cfg(not(windows))] pub static PleaseExitSignal: int = libc::SIGTERM as int; +#[cfg(not(windows))] pub const PleaseExitSignal: int = libc::SIGTERM as int; /// Signal a process to exit immediately, forcibly killing it. Corresponds to /// SIGKILL on unix platforms. -#[cfg(not(windows))] pub static MustDieSignal: int = libc::SIGKILL as int; +#[cfg(not(windows))] pub const MustDieSignal: int = libc::SIGKILL as int; /// Representation of a running or exited child process. /// diff --git a/src/libstd/os.rs b/src/libstd/os.rs index bb642f1e48f..60386ec0631 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -66,8 +66,8 @@ pub fn num_cpus() -> uint { } } -pub static TMPBUF_SZ : uint = 1000u; -static BUF_BYTES : uint = 2048u; +pub const TMPBUF_SZ : uint = 1000u; +const BUF_BYTES : uint = 2048u; /// Returns the current working directory as a Path. /// @@ -1672,230 +1672,230 @@ impl MemoryMap { pub mod consts { pub use os::arch_consts::ARCH; - pub static FAMILY: &'static str = "unix"; + pub const FAMILY: &'static str = "unix"; /// A string describing the specific operating system in use: in this /// case, `linux`. - pub static SYSNAME: &'static str = "linux"; + pub const SYSNAME: &'static str = "linux"; /// Specifies the filename prefix used for shared libraries on this /// platform: in this case, `lib`. - pub static DLL_PREFIX: &'static str = "lib"; + pub const DLL_PREFIX: &'static str = "lib"; /// Specifies the filename suffix used for shared libraries on this /// platform: in this case, `.so`. - pub static DLL_SUFFIX: &'static str = ".so"; + pub const DLL_SUFFIX: &'static str = ".so"; /// Specifies the file extension used for shared libraries on this /// platform that goes after the dot: in this case, `so`. - pub static DLL_EXTENSION: &'static str = "so"; + pub const DLL_EXTENSION: &'static str = "so"; /// Specifies the filename suffix used for executable binaries on this /// platform: in this case, the empty string. - pub static EXE_SUFFIX: &'static str = ""; + pub const EXE_SUFFIX: &'static str = ""; /// Specifies the file extension, if any, used for executable binaries /// on this platform: in this case, the empty string. - pub static EXE_EXTENSION: &'static str = ""; + pub const EXE_EXTENSION: &'static str = ""; } #[cfg(target_os = "macos")] pub mod consts { pub use os::arch_consts::ARCH; - pub static FAMILY: &'static str = "unix"; + pub const FAMILY: &'static str = "unix"; /// A string describing the specific operating system in use: in this /// case, `macos`. - pub static SYSNAME: &'static str = "macos"; + pub const SYSNAME: &'static str = "macos"; /// Specifies the filename prefix used for shared libraries on this /// platform: in this case, `lib`. - pub static DLL_PREFIX: &'static str = "lib"; + pub const DLL_PREFIX: &'static str = "lib"; /// Specifies the filename suffix used for shared libraries on this /// platform: in this case, `.dylib`. - pub static DLL_SUFFIX: &'static str = ".dylib"; + pub const DLL_SUFFIX: &'static str = ".dylib"; /// Specifies the file extension used for shared libraries on this /// platform that goes after the dot: in this case, `dylib`. - pub static DLL_EXTENSION: &'static str = "dylib"; + pub const DLL_EXTENSION: &'static str = "dylib"; /// Specifies the filename suffix used for executable binaries on this /// platform: in this case, the empty string. - pub static EXE_SUFFIX: &'static str = ""; + pub const EXE_SUFFIX: &'static str = ""; /// Specifies the file extension, if any, used for executable binaries /// on this platform: in this case, the empty string. - pub static EXE_EXTENSION: &'static str = ""; + pub const EXE_EXTENSION: &'static str = ""; } #[cfg(target_os = "ios")] pub mod consts { pub use os::arch_consts::ARCH; - pub static FAMILY: &'static str = "unix"; + pub const FAMILY: &'static str = "unix"; /// A string describing the specific operating system in use: in this /// case, `ios`. - pub static SYSNAME: &'static str = "ios"; + pub const SYSNAME: &'static str = "ios"; /// Specifies the filename suffix used for executable binaries on this /// platform: in this case, the empty string. - pub static EXE_SUFFIX: &'static str = ""; + pub const EXE_SUFFIX: &'static str = ""; /// Specifies the file extension, if any, used for executable binaries /// on this platform: in this case, the empty string. - pub static EXE_EXTENSION: &'static str = ""; + pub const EXE_EXTENSION: &'static str = ""; } #[cfg(target_os = "freebsd")] pub mod consts { pub use os::arch_consts::ARCH; - pub static FAMILY: &'static str = "unix"; + pub const FAMILY: &'static str = "unix"; /// A string describing the specific operating system in use: in this /// case, `freebsd`. - pub static SYSNAME: &'static str = "freebsd"; + pub const SYSNAME: &'static str = "freebsd"; /// Specifies the filename prefix used for shared libraries on this /// platform: in this case, `lib`. - pub static DLL_PREFIX: &'static str = "lib"; + pub const DLL_PREFIX: &'static str = "lib"; /// Specifies the filename suffix used for shared libraries on this /// platform: in this case, `.so`. - pub static DLL_SUFFIX: &'static str = ".so"; + pub const DLL_SUFFIX: &'static str = ".so"; /// Specifies the file extension used for shared libraries on this /// platform that goes after the dot: in this case, `so`. - pub static DLL_EXTENSION: &'static str = "so"; + pub const DLL_EXTENSION: &'static str = "so"; /// Specifies the filename suffix used for executable binaries on this /// platform: in this case, the empty string. - pub static EXE_SUFFIX: &'static str = ""; + pub const EXE_SUFFIX: &'static str = ""; /// Specifies the file extension, if any, used for executable binaries /// on this platform: in this case, the empty string. - pub static EXE_EXTENSION: &'static str = ""; + pub const EXE_EXTENSION: &'static str = ""; } #[cfg(target_os = "dragonfly")] pub mod consts { pub use os::arch_consts::ARCH; - pub static FAMILY: &'static str = "unix"; + pub const FAMILY: &'static str = "unix"; /// A string describing the specific operating system in use: in this /// case, `dragonfly`. - pub static SYSNAME: &'static str = "dragonfly"; + pub const SYSNAME: &'static str = "dragonfly"; /// Specifies the filename prefix used for shared libraries on this /// platform: in this case, `lib`. - pub static DLL_PREFIX: &'static str = "lib"; + pub const DLL_PREFIX: &'static str = "lib"; /// Specifies the filename suffix used for shared libraries on this /// platform: in this case, `.so`. - pub static DLL_SUFFIX: &'static str = ".so"; + pub const DLL_SUFFIX: &'static str = ".so"; /// Specifies the file extension used for shared libraries on this /// platform that goes after the dot: in this case, `so`. - pub static DLL_EXTENSION: &'static str = "so"; + pub const DLL_EXTENSION: &'static str = "so"; /// Specifies the filename suffix used for executable binaries on this /// platform: in this case, the empty string. - pub static EXE_SUFFIX: &'static str = ""; + pub const EXE_SUFFIX: &'static str = ""; /// Specifies the file extension, if any, used for executable binaries /// on this platform: in this case, the empty string. - pub static EXE_EXTENSION: &'static str = ""; + pub const EXE_EXTENSION: &'static str = ""; } #[cfg(target_os = "android")] pub mod consts { pub use os::arch_consts::ARCH; - pub static FAMILY: &'static str = "unix"; + pub const FAMILY: &'static str = "unix"; /// A string describing the specific operating system in use: in this /// case, `android`. - pub static SYSNAME: &'static str = "android"; + pub const SYSNAME: &'static str = "android"; /// Specifies the filename prefix used for shared libraries on this /// platform: in this case, `lib`. - pub static DLL_PREFIX: &'static str = "lib"; + pub const DLL_PREFIX: &'static str = "lib"; /// Specifies the filename suffix used for shared libraries on this /// platform: in this case, `.so`. - pub static DLL_SUFFIX: &'static str = ".so"; + pub const DLL_SUFFIX: &'static str = ".so"; /// Specifies the file extension used for shared libraries on this /// platform that goes after the dot: in this case, `so`. - pub static DLL_EXTENSION: &'static str = "so"; + pub const DLL_EXTENSION: &'static str = "so"; /// Specifies the filename suffix used for executable binaries on this /// platform: in this case, the empty string. - pub static EXE_SUFFIX: &'static str = ""; + pub const EXE_SUFFIX: &'static str = ""; /// Specifies the file extension, if any, used for executable binaries /// on this platform: in this case, the empty string. - pub static EXE_EXTENSION: &'static str = ""; + pub const EXE_EXTENSION: &'static str = ""; } #[cfg(target_os = "windows")] pub mod consts { pub use os::arch_consts::ARCH; - pub static FAMILY: &'static str = "windows"; + pub const FAMILY: &'static str = "windows"; /// A string describing the specific operating system in use: in this /// case, `windows`. - pub static SYSNAME: &'static str = "windows"; + pub const SYSNAME: &'static str = "windows"; /// Specifies the filename prefix used for shared libraries on this /// platform: in this case, the empty string. - pub static DLL_PREFIX: &'static str = ""; + pub const DLL_PREFIX: &'static str = ""; /// Specifies the filename suffix used for shared libraries on this /// platform: in this case, `.dll`. - pub static DLL_SUFFIX: &'static str = ".dll"; + pub const DLL_SUFFIX: &'static str = ".dll"; /// Specifies the file extension used for shared libraries on this /// platform that goes after the dot: in this case, `dll`. - pub static DLL_EXTENSION: &'static str = "dll"; + pub const DLL_EXTENSION: &'static str = "dll"; /// Specifies the filename suffix used for executable binaries on this /// platform: in this case, `.exe`. - pub static EXE_SUFFIX: &'static str = ".exe"; + pub const EXE_SUFFIX: &'static str = ".exe"; /// Specifies the file extension, if any, used for executable binaries /// on this platform: in this case, `exe`. - pub static EXE_EXTENSION: &'static str = "exe"; + pub const EXE_EXTENSION: &'static str = "exe"; } #[cfg(target_arch = "x86")] mod arch_consts { - pub static ARCH: &'static str = "x86"; + pub const ARCH: &'static str = "x86"; } #[cfg(target_arch = "x86_64")] mod arch_consts { - pub static ARCH: &'static str = "x86_64"; + pub const ARCH: &'static str = "x86_64"; } #[cfg(target_arch = "arm")] mod arch_consts { - pub static ARCH: &'static str = "arm"; + pub const ARCH: &'static str = "arm"; } #[cfg(target_arch = "mips")] mod arch_consts { - pub static ARCH: &'static str = "mips"; + pub const ARCH: &'static str = "mips"; } #[cfg(target_arch = "mipsel")] mod arch_consts { - pub static ARCH: &'static str = "mipsel"; + pub const ARCH: &'static str = "mipsel"; } #[cfg(test)] diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index 196ac7507ea..f7fb9adb1fb 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -42,10 +42,10 @@ pub struct Path { } /// The standard path separator character -pub static SEP: char = '/'; +pub const SEP: char = '/'; /// The standard path separator byte -pub static SEP_BYTE: u8 = SEP as u8; +pub const SEP_BYTE: u8 = SEP as u8; /// Returns whether the given byte is a path separator #[inline] diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index ec3f87bc45a..5bd738ed58b 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -958,14 +958,14 @@ pub fn make_non_verbatim(path: &Path) -> Option<Path> { } /// The standard path separator character -pub static SEP: char = '\\'; +pub const SEP: char = '\\'; /// The standard path separator byte -pub static SEP_BYTE: u8 = SEP as u8; +pub const SEP_BYTE: u8 = SEP as u8; /// The alternative path separator character -pub static SEP2: char = '/'; +pub const SEP2: char = '/'; /// The alternative path separator character -pub static SEP2_BYTE: u8 = SEP2 as u8; +pub const SEP2_BYTE: u8 = SEP2 as u8; /// Returns whether the given char is a path separator. /// Allows both the primary separator '\' and the alternative separator '/'. diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 85aed47265f..751eb00bfae 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -20,23 +20,23 @@ use num::{CheckedAdd, CheckedMul}; use result::{Result, Ok, Err}; /// The number of nanoseconds in a microsecond. -static NANOS_PER_MICRO: i32 = 1000; +const NANOS_PER_MICRO: i32 = 1000; /// The number of nanoseconds in a millisecond. -static NANOS_PER_MILLI: i32 = 1000_000; +const NANOS_PER_MILLI: i32 = 1000_000; /// The number of nanoseconds in seconds. -static NANOS_PER_SEC: i32 = 1_000_000_000; +const NANOS_PER_SEC: i32 = 1_000_000_000; /// The number of microseconds per second. -static MICROS_PER_SEC: i64 = 1000_000; +const MICROS_PER_SEC: i64 = 1000_000; /// The number of milliseconds per second. -static MILLIS_PER_SEC: i64 = 1000; +const MILLIS_PER_SEC: i64 = 1000; /// The number of seconds in a minute. -static SECS_PER_MINUTE: i64 = 60; +const SECS_PER_MINUTE: i64 = 60; /// The number of seconds in an hour. -static SECS_PER_HOUR: i64 = 3600; +const SECS_PER_HOUR: i64 = 3600; /// The number of (non-leap) seconds in days. -static SECS_PER_DAY: i64 = 86400; +const SECS_PER_DAY: i64 = 86400; /// The number of (non-leap) seconds in a week. -static SECS_PER_WEEK: i64 = 604800; +const SECS_PER_WEEK: i64 = 604800; macro_rules! try_opt( ($e:expr) => (match $e { Some(v) => v, None => return None }) @@ -52,13 +52,13 @@ pub struct Duration { } /// The minimum possible `Duration`: `i64::MIN` milliseconds. -pub static MIN: Duration = Duration { +pub const MIN: Duration = Duration { secs: i64::MIN / MILLIS_PER_SEC - 1, nanos: NANOS_PER_SEC + (i64::MIN % MILLIS_PER_SEC) as i32 * NANOS_PER_MILLI }; /// The maximum possible `Duration`: `i64::MAX` milliseconds. -pub static MAX: Duration = Duration { +pub const MAX: Duration = Duration { secs: i64::MAX / MILLIS_PER_SEC, nanos: (i64::MAX % MILLIS_PER_SEC) as i32 * NANOS_PER_MILLI }; @@ -456,7 +456,7 @@ mod tests { assert_eq!(MIN.num_microseconds(), None); // overflow checks - static MICROS_PER_DAY: i64 = 86400_000_000; + const MICROS_PER_DAY: i64 = 86400_000_000; assert_eq!(Duration::days(i64::MAX / MICROS_PER_DAY).num_microseconds(), Some(i64::MAX / MICROS_PER_DAY * MICROS_PER_DAY)); assert_eq!(Duration::days(i64::MIN / MICROS_PER_DAY).num_microseconds(), @@ -477,7 +477,7 @@ mod tests { assert_eq!(MIN.num_nanoseconds(), None); // overflow checks - static NANOS_PER_DAY: i64 = 86400_000_000_000; + const NANOS_PER_DAY: i64 = 86400_000_000_000; assert_eq!(Duration::days(i64::MAX / NANOS_PER_DAY).num_nanoseconds(), Some(i64::MAX / NANOS_PER_DAY * NANOS_PER_DAY)); assert_eq!(Duration::days(i64::MIN / NANOS_PER_DAY).num_nanoseconds(),