You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -337,41 +373,6 @@ If the predicate is true, the thing is rewritten to not have the `cfg` attribute
337
373
r[cfg.attr.crate-level-attrs]
338
374
When a crate-level `cfg` has a false predicate, the behavior is slightly different: any crate attributes preceding the `cfg` are kept, and any crate attributes following the `cfg` are removed. This allows `#![no_std]` and `#![no_core]` crates to avoid linking `std`/`core` even if a `#![cfg(...)]` has removed the entire crate.
339
375
340
-
Some examples on functions:
341
-
342
-
```rust
343
-
// The function is only included in the build when compiling for macOS
344
-
#[cfg(target_os ="macos")]
345
-
fnmacos_only() {
346
-
// ...
347
-
}
348
-
349
-
// This function is only included when either foo or bar is defined
350
-
#[cfg(any(foo, bar))]
351
-
fnneeds_foo_or_bar() {
352
-
// ...
353
-
}
354
-
355
-
// This function is only included when compiling for a unixish OS with a 32-bit
356
-
// architecture
357
-
#[cfg(all(unix, target_pointer_width ="32"))]
358
-
fnon_32bit_unix() {
359
-
// ...
360
-
}
361
-
362
-
// This function is only included when foo is not defined
363
-
#[cfg(not(foo))]
364
-
fnneeds_not_foo() {
365
-
// ...
366
-
}
367
-
368
-
// This function is only included when the panic strategy is set to unwind
369
-
#[cfg(panic ="unwind")]
370
-
fnwhen_unwinding() {
371
-
// ...
372
-
}
373
-
374
-
```
375
376
376
377
r[cfg.attr.restriction]
377
378
The `cfg` attribute is allowed anywhere attributes are allowed.
0 commit comments