diff options
| author | bors <bors@rust-lang.org> | 2014-10-10 00:07:08 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-10-10 00:07:08 +0000 |
| commit | f9fc49c06e5c71a8d63d6120e1a92b6445fb501d (patch) | |
| tree | 8a7c52db87b4ff8d5a7fa97dc44fb9ac10b92626 /src/libnative | |
| parent | 8b12fb326b50c40c7b5acadb4403c7021fedb272 (diff) | |
| parent | 0b517117b3ac9c4981bbe00a529e48e4019554d1 (diff) | |
| download | rust-f9fc49c06e5c71a8d63d6120e1a92b6445fb501d.tar.gz rust-f9fc49c06e5c71a8d63d6120e1a92b6445fb501d.zip | |
auto merge of #17853 : alexcrichton/rust/issue-17718, r=pcwalton
This change is an implementation of [RFC 69][rfc] which adds a third kind of
global to the language, `const`. This global is most similar to what the old
`static` was, and if you're unsure about what to use then you should use a
`const`.
The semantics of these three kinds of globals are:
* A `const` does not represent a memory location, but only a value. Constants
are translated as rvalues, which means that their values are directly inlined
at usage location (similar to a #define in C/C++). Constant values are, well,
constant, and can not be modified. Any "modification" is actually a
modification to a local value on the stack rather than the actual constant
itself.
Almost all values are allowed inside constants, whether they have interior
mutability or not. There are a few minor restrictions listed in the RFC, but
they should in general not come up too often.
* A `static` now always represents a memory location (unconditionally). Any
references to the same `static` are actually a reference to the same memory
location. Only values whose types ascribe to `Sync` are allowed in a `static`.
This restriction is in place because many threads may access a `static`
concurrently. Lifting this restriction (and allowing unsafe access) is a
future extension not implemented at this time.
* A `static mut` continues to always represent a memory location. All references
to a `static mut` continue to be `unsafe`.
This is a large breaking change, and many programs will need to be updated
accordingly. A summary of the breaking changes is:
* Statics may no longer be used in patterns. Statics now always represent a
memory location, which can sometimes be modified. To fix code, repurpose the
matched-on-`static` to a `const`.
static FOO: uint = 4;
match n {
FOO => { /* ... */ }
_ => { /* ... */ }
}
change this code to:
const FOO: uint = 4;
match n {
FOO => { /* ... */ }
_ => { /* ... */ }
}
* Statics may no longer refer to other statics by value. Due to statics being
able to change at runtime, allowing them to reference one another could
possibly lead to confusing semantics. If you are in this situation, use a
constant initializer instead. Note, however, that statics may reference other
statics by address, however.
* Statics may no longer be used in constant expressions, such as array lengths.
This is due to the same restrictions as listed above. Use a `const` instead.
[breaking-change]
Closes #17718
[rfc]: https://github.com/rust-lang/rfcs/pull/246
Diffstat (limited to 'src/libnative')
| -rw-r--r-- | src/libnative/io/c_unix.rs | 70 | ||||
| -rw-r--r-- | src/libnative/io/c_windows.rs | 40 |
2 files changed, 55 insertions, 55 deletions
diff --git a/src/libnative/io/c_unix.rs b/src/libnative/io/c_unix.rs index a8ebcda3cdd..c2af9c03c42 100644 --- a/src/libnative/io/c_unix.rs +++ b/src/libnative/io/c_unix.rs @@ -23,41 +23,41 @@ use libc; target_os = "ios", target_os = "freebsd", target_os = "dragonfly"))] -pub static FIONBIO: libc::c_ulong = 0x8004667e; +pub const FIONBIO: libc::c_ulong = 0x8004667e; #[cfg(any(all(target_os = "linux", any(target_arch = "x86", target_arch = "x86_64", target_arch = "arm")), target_os = "android"))] -pub static FIONBIO: libc::c_ulong = 0x5421; +pub const FIONBIO: libc::c_ulong = 0x5421; #[cfg(all(target_os = "linux", any(target_arch = "mips", target_arch = "mipsel")))] -pub static FIONBIO: libc::c_ulong = 0x667e; +pub const FIONBIO: libc::c_ulong = 0x667e; #[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "dragonfly"))] -pub static FIOCLEX: libc::c_ulong = 0x20006601; +pub const FIOCLEX: libc::c_ulong = 0x20006601; #[cfg(any(all(target_os = "linux", any(target_arch = "x86", target_arch = "x86_64", target_arch = "arm")), target_os = "android"))] -pub static FIOCLEX: libc::c_ulong = 0x5451; +pub const FIOCLEX: libc::c_ulong = 0x5451; #[cfg(all(target_os = "linux", any(target_arch = "mips", target_arch = "mipsel")))] -pub static FIOCLEX: libc::c_ulong = 0x6601; +pub const FIOCLEX: libc::c_ulong = 0x6601; #[cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "dragonfly"))] -pub static MSG_DONTWAIT: libc::c_int = 0x80; +pub const MSG_DONTWAIT: libc::c_int = 0x80; #[cfg(any(target_os = "linux", target_os = "android"))] -pub static MSG_DONTWAIT: libc::c_int = 0x40; +pub const MSG_DONTWAIT: libc::c_int = 0x40; -pub static WNOHANG: libc::c_int = 1; +pub const WNOHANG: libc::c_int = 1; extern { pub fn gettimeofday(timeval: *mut libc::timeval, @@ -89,7 +89,7 @@ extern { #[cfg(any(target_os = "macos", target_os = "ios"))] mod select { - pub static FD_SETSIZE: uint = 1024; + pub const FD_SETSIZE: uint = 1024; #[repr(C)] pub struct fd_set { @@ -109,7 +109,7 @@ mod select { use std::uint; use libc; - pub static FD_SETSIZE: uint = 1024; + pub const FD_SETSIZE: uint = 1024; #[repr(C)] pub struct fd_set { @@ -131,14 +131,14 @@ mod select { mod signal { use libc; - pub static SA_NOCLDSTOP: libc::c_ulong = 0x00000001; - pub static SA_NOCLDWAIT: libc::c_ulong = 0x00000002; - pub static SA_NODEFER: libc::c_ulong = 0x40000000; - pub static SA_ONSTACK: libc::c_ulong = 0x08000000; - pub static SA_RESETHAND: libc::c_ulong = 0x80000000; - pub static SA_RESTART: libc::c_ulong = 0x10000000; - pub static SA_SIGINFO: libc::c_ulong = 0x00000004; - pub static SIGCHLD: libc::c_int = 17; + pub const SA_NOCLDSTOP: libc::c_ulong = 0x00000001; + pub const SA_NOCLDWAIT: libc::c_ulong = 0x00000002; + pub const SA_NODEFER: libc::c_ulong = 0x40000000; + pub const SA_ONSTACK: libc::c_ulong = 0x08000000; + pub const SA_RESETHAND: libc::c_ulong = 0x80000000; + pub const SA_RESTART: libc::c_ulong = 0x10000000; + pub const SA_SIGINFO: libc::c_ulong = 0x00000004; + pub const SIGCHLD: libc::c_int = 17; // This definition is not as accurate as it could be, {pid, uid, status} is // actually a giant union. Currently we're only interested in these fields, @@ -179,14 +179,14 @@ mod signal { mod signal { use libc; - pub static SA_NOCLDSTOP: libc::c_ulong = 0x00000001; - pub static SA_NOCLDWAIT: libc::c_ulong = 0x00010000; - pub static SA_NODEFER: libc::c_ulong = 0x40000000; - pub static SA_ONSTACK: libc::c_ulong = 0x08000000; - pub static SA_RESETHAND: libc::c_ulong = 0x80000000; - pub static SA_RESTART: libc::c_ulong = 0x10000000; - pub static SA_SIGINFO: libc::c_ulong = 0x00000008; - pub static SIGCHLD: libc::c_int = 18; + pub const SA_NOCLDSTOP: libc::c_ulong = 0x00000001; + pub const SA_NOCLDWAIT: libc::c_ulong = 0x00010000; + pub const SA_NODEFER: libc::c_ulong = 0x40000000; + pub const SA_ONSTACK: libc::c_ulong = 0x08000000; + pub const SA_RESETHAND: libc::c_ulong = 0x80000000; + pub const SA_RESTART: libc::c_ulong = 0x10000000; + pub const SA_SIGINFO: libc::c_ulong = 0x00000008; + pub const SIGCHLD: libc::c_int = 18; // This definition is not as accurate as it could be, {pid, uid, status} is // actually a giant union. Currently we're only interested in these fields, @@ -223,14 +223,14 @@ mod signal { mod signal { use libc; - pub static SA_ONSTACK: libc::c_int = 0x0001; - pub static SA_RESTART: libc::c_int = 0x0002; - pub static SA_RESETHAND: libc::c_int = 0x0004; - pub static SA_NOCLDSTOP: libc::c_int = 0x0008; - pub static SA_NODEFER: libc::c_int = 0x0010; - pub static SA_NOCLDWAIT: libc::c_int = 0x0020; - pub static SA_SIGINFO: libc::c_int = 0x0040; - pub static SIGCHLD: libc::c_int = 20; + pub const SA_ONSTACK: libc::c_int = 0x0001; + pub const SA_RESTART: libc::c_int = 0x0002; + pub const SA_RESETHAND: libc::c_int = 0x0004; + pub const SA_NOCLDSTOP: libc::c_int = 0x0008; + pub const SA_NODEFER: libc::c_int = 0x0010; + pub const SA_NOCLDWAIT: libc::c_int = 0x0020; + pub const SA_SIGINFO: libc::c_int = 0x0040; + pub const SIGCHLD: libc::c_int = 20; #[cfg(any(target_os = "macos", target_os = "ios"))] pub type sigset_t = u32; diff --git a/src/libnative/io/c_windows.rs b/src/libnative/io/c_windows.rs index 909b37895b7..067a31166a5 100644 --- a/src/libnative/io/c_windows.rs +++ b/src/libnative/io/c_windows.rs @@ -14,26 +14,26 @@ use libc; -pub static WSADESCRIPTION_LEN: uint = 256; -pub static WSASYS_STATUS_LEN: uint = 128; -pub static FIONBIO: libc::c_long = 0x8004667e; -static FD_SETSIZE: uint = 64; -pub static MSG_DONTWAIT: libc::c_int = 0; -pub static ERROR_ILLEGAL_CHARACTER: libc::c_int = 582; -pub static ENABLE_ECHO_INPUT: libc::DWORD = 0x4; -pub static ENABLE_EXTENDED_FLAGS: libc::DWORD = 0x80; -pub static ENABLE_INSERT_MODE: libc::DWORD = 0x20; -pub static ENABLE_LINE_INPUT: libc::DWORD = 0x2; -pub static ENABLE_PROCESSED_INPUT: libc::DWORD = 0x1; -pub static ENABLE_QUICK_EDIT_MODE: libc::DWORD = 0x40; -pub static WSA_INVALID_EVENT: WSAEVENT = 0 as WSAEVENT; - -pub static FD_ACCEPT: libc::c_long = 0x08; -pub static FD_MAX_EVENTS: uint = 10; -pub static WSA_INFINITE: libc::DWORD = libc::INFINITE; -pub static WSA_WAIT_TIMEOUT: libc::DWORD = libc::consts::os::extra::WAIT_TIMEOUT; -pub static WSA_WAIT_EVENT_0: libc::DWORD = libc::consts::os::extra::WAIT_OBJECT_0; -pub static WSA_WAIT_FAILED: libc::DWORD = libc::consts::os::extra::WAIT_FAILED; +pub const WSADESCRIPTION_LEN: uint = 256; +pub const WSASYS_STATUS_LEN: uint = 128; +pub const FIONBIO: libc::c_long = 0x8004667e; +pub const FD_SETSIZE: uint = 64; +pub const MSG_DONTWAIT: libc::c_int = 0; +pub const ERROR_ILLEGAL_CHARACTER: libc::c_int = 582; +pub const ENABLE_ECHO_INPUT: libc::DWORD = 0x4; +pub const ENABLE_EXTENDED_FLAGS: libc::DWORD = 0x80; +pub const ENABLE_INSERT_MODE: libc::DWORD = 0x20; +pub const ENABLE_LINE_INPUT: libc::DWORD = 0x2; +pub const ENABLE_PROCESSED_INPUT: libc::DWORD = 0x1; +pub const ENABLE_QUICK_EDIT_MODE: libc::DWORD = 0x40; +pub const WSA_INVALID_EVENT: WSAEVENT = 0 as WSAEVENT; + +pub const FD_ACCEPT: libc::c_long = 0x08; +pub const FD_MAX_EVENTS: uint = 10; +pub const WSA_INFINITE: libc::DWORD = libc::INFINITE; +pub const WSA_WAIT_TIMEOUT: libc::DWORD = libc::consts::os::extra::WAIT_TIMEOUT; +pub const WSA_WAIT_EVENT_0: libc::DWORD = libc::consts::os::extra::WAIT_OBJECT_0; +pub const WSA_WAIT_FAILED: libc::DWORD = libc::consts::os::extra::WAIT_FAILED; #[repr(C)] #[cfg(target_arch = "x86")] |
