diff options
Diffstat (limited to 'src/doc')
| -rw-r--r-- | src/doc/guide-ffi.md | 2 | ||||
| -rw-r--r-- | src/doc/guide-unsafe.md | 16 | ||||
| -rw-r--r-- | src/doc/reference.md | 18 |
3 files changed, 18 insertions, 18 deletions
diff --git a/src/doc/guide-ffi.md b/src/doc/guide-ffi.md index 14e60b5ba08..abd2cd7b33e 100644 --- a/src/doc/guide-ffi.md +++ b/src/doc/guide-ffi.md @@ -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" { diff --git a/src/doc/guide-unsafe.md b/src/doc/guide-unsafe.md index fe6664bd848..7756abc8020 100644 --- a/src/doc/guide-unsafe.md +++ b/src/doc/guide-unsafe.md @@ -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"); diff --git a/src/doc/reference.md b/src/doc/reference.md index c34a136a68e..cf9504736eb 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -2066,26 +2066,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: |
