auto merge of #17963 : sfackler/rust/cfg-error, r=alexcrichton
All deprecation warnings have been converted to errors. This includes the warning for multiple cfgs on one item. We'll leave that as an error for some period of time to ensure that all uses are updated before the behavior changes from "or" to "and".
This commit is contained in:
commit
d670d76221
22 changed files with 82 additions and 173 deletions
|
|
@ -475,7 +475,7 @@ conventions. Rust provides a way to tell the compiler which convention to use:
|
|||
~~~~
|
||||
extern crate libc;
|
||||
|
||||
#[cfg(target_os = "win32", target_arch = "x86")]
|
||||
#[cfg(all(target_os = "win32", target_arch = "x86"))]
|
||||
#[link(name = "kernel32")]
|
||||
#[allow(non_snake_case)]
|
||||
extern "stdcall" {
|
||||
|
|
|
|||
|
|
@ -313,8 +313,7 @@ literal string (i.e `""`)
|
|||
```
|
||||
#![feature(asm)]
|
||||
|
||||
#[cfg(target_arch = "x86")]
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
fn foo() {
|
||||
unsafe {
|
||||
asm!("NOP");
|
||||
|
|
@ -322,8 +321,7 @@ fn foo() {
|
|||
}
|
||||
|
||||
// other platforms
|
||||
#[cfg(not(target_arch = "x86"),
|
||||
not(target_arch = "x86_64"))]
|
||||
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
|
||||
fn foo() { /* ... */ }
|
||||
|
||||
fn main() {
|
||||
|
|
@ -340,7 +338,7 @@ but you must add the right number of `:` if you skip them:
|
|||
|
||||
```
|
||||
# #![feature(asm)]
|
||||
# #[cfg(target_arch = "x86")] #[cfg(target_arch = "x86_64")]
|
||||
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
# fn main() { unsafe {
|
||||
asm!("xor %eax, %eax"
|
||||
:
|
||||
|
|
@ -354,7 +352,7 @@ Whitespace also doesn't matter:
|
|||
|
||||
```
|
||||
# #![feature(asm)]
|
||||
# #[cfg(target_arch = "x86")] #[cfg(target_arch = "x86_64")]
|
||||
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
# fn main() { unsafe {
|
||||
asm!("xor %eax, %eax" ::: "eax");
|
||||
# } }
|
||||
|
|
@ -368,7 +366,7 @@ expressions must be mutable lvalues:
|
|||
|
||||
```
|
||||
# #![feature(asm)]
|
||||
# #[cfg(target_arch = "x86")] #[cfg(target_arch = "x86_64")]
|
||||
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
fn add(a: int, b: int) -> int {
|
||||
let mut c = 0;
|
||||
unsafe {
|
||||
|
|
@ -379,7 +377,7 @@ fn add(a: int, b: int) -> int {
|
|||
}
|
||||
c
|
||||
}
|
||||
# #[cfg(not(target_arch = "x86"), not(target_arch = "x86_64"))]
|
||||
# #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
|
||||
# fn add(a: int, b: int) -> int { a + b }
|
||||
|
||||
fn main() {
|
||||
|
|
@ -396,7 +394,7 @@ stay valid.
|
|||
|
||||
```
|
||||
# #![feature(asm)]
|
||||
# #[cfg(target_arch = "x86")] #[cfg(target_arch = "x86_64")]
|
||||
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
|
||||
# fn main() { unsafe {
|
||||
// Put the value 0x200 in eax
|
||||
asm!("mov $$0x200, %eax" : /* no outputs */ : /* no inputs */ : "eax");
|
||||
|
|
|
|||
|
|
@ -2049,26 +2049,28 @@ fn macos_only() {
|
|||
}
|
||||
|
||||
// This function is only included when either foo or bar is defined
|
||||
#[cfg(foo)]
|
||||
#[cfg(bar)]
|
||||
#[cfg(any(foo, bar))]
|
||||
fn needs_foo_or_bar() {
|
||||
// ...
|
||||
}
|
||||
|
||||
// This function is only included when compiling for a unixish OS with a 32-bit
|
||||
// architecture
|
||||
#[cfg(unix, target_word_size = "32")]
|
||||
#[cfg(all(unix, target_word_size = "32"))]
|
||||
fn on_32bit_unix() {
|
||||
// ...
|
||||
}
|
||||
|
||||
// This function is only included when foo is not defined
|
||||
#[cfg(not(foo))]
|
||||
fn needs_not_foo() {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
This illustrates some conditional compilation can be achieved using the
|
||||
`#[cfg(...)]` attribute. Note that `#[cfg(foo, bar)]` is a condition that needs
|
||||
both `foo` and `bar` to be defined while `#[cfg(foo)] #[cfg(bar)]` only needs
|
||||
one of `foo` and `bar` to be defined (this resembles in the disjunctive normal
|
||||
form). Additionally, one can reverse a condition by enclosing it in a
|
||||
`not(...)`, like e. g. `#[cfg(not(target_os = "win32"))]`.
|
||||
`#[cfg(...)]` attribute. `any`, `all` and `not` can be used to assemble
|
||||
arbitrarily complex configurations through nesting.
|
||||
|
||||
The following configurations must be defined by the implementation:
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue