From 3319e0e1de1b33819456c912bf80ec5bfc7c90ef Mon Sep 17 00:00:00 2001 From: Kane York Date: Tue, 20 Jun 2023 14:23:41 -0700 Subject: [PATCH] Document the ordering behavior of crate cfgs This was changed in rust-lang/rust#110141. --- src/conditional-compilation.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/conditional-compilation.md b/src/conditional-compilation.md index 97840e4f6..c3a36effe 100644 --- a/src/conditional-compilation.md +++ b/src/conditional-compilation.md @@ -254,6 +254,12 @@ It is written as `cfg`, `(`, a configuration predicate, and finally `)`. If the predicate is true, the thing is rewritten to not have the `cfg` attribute on it. If the predicate is false, the thing is removed from the source code. +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. + Some examples on functions: ```rust