Skip to content

Commit 39a9675

Browse files
committed
Move example to the intro
1 parent 62279d1 commit 39a9675

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/conditional-compilation.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,16 @@ r[cfg.cfg_attr]
388388
r[cfg.cfg_attr.intro]
389389
The *`cfg_attr` [attribute]* conditionally includes attributes based on a configuration predicate.
390390

391+
> [!EXAMPLE]
392+
> The following module will either be found at `linux.rs` or `windows.rs` based on the target.
393+
>
394+
> <!-- ignore: `mod` needs multiple files -->
395+
> ```rust,ignore
396+
> #[cfg_attr(target_os = "linux", path = "linux.rs")]
397+
> #[cfg_attr(windows, path = "windows.rs")]
398+
> mod os;
399+
> ```
400+
391401
r[cfg.cfg_attr.syntax]
392402
```grammar,configuration
393403
@root CfgAttrAttribute -> `cfg_attr` `(` ConfigurationPredicate `,` CfgAttrs? `)`
@@ -399,12 +409,6 @@ CfgAttrs -> Attr (`,` Attr)* `,`?
399409
r[cfg.cfg_attr.behaviour]
400410
When the configuration predicate is true, this attribute expands out to the attributes listed after the predicate. For example, the following module will either be found at `linux.rs` or `windows.rs` based on the target.
401411

402-
<!-- ignore: `mod` needs multiple files -->
403-
```rust,ignore
404-
#[cfg_attr(target_os = "linux", path = "linux.rs")]
405-
#[cfg_attr(windows, path = "windows.rs")]
406-
mod os;
407-
```
408412

409413
r[cfg.cfg_attr.attribute-list]
410414
Zero, one, or more attributes may be listed. Multiple attributes will each be expanded into separate attributes. For example:

0 commit comments

Comments
 (0)