Skip to content

Commit 2a03f36

Browse files
committed
Recommend --cfg, not cargo features
1 parent 823a990 commit 2a03f36

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/future-proofing.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,14 @@ on the data structure.
209209
Some libraries need to use, or want to experiment with, the [nightly channel].
210210
To avoid accidental breakage, libraries should either:
211211
- Use nightly features unconditionally, so that people depending on the library must always use a nightly toolchain to build
212-
- Add a cargo feature which opts-in to the nightly features (optionally, with feature detection to verify the features are present in the current compiler version). This allows people to avoid opting-in if they do not want to be exposed to possible breakage.
212+
- Add a `--cfg` flag which opts-in to the nightly features (optionally, with feature detection to verify the features are present in the current compiler version). This allows people to avoid opting-in if they do not want to be exposed to possible breakage.
213213

214-
Each nightly feature should be under a separate cargo feature so that breakage to one feature does not cause breakage for others.
215-
For example, if you depend on two different nightly features, `std::intrinsics::black_box` and `std::intrinsics::catch_unwind`, create two cargo features named `nightly-black-box` and `nightly-catch-unwind`.
214+
Each nightly feature should be under a separate flag so that breakage to one feature does not cause breakage for others.
215+
Each flag should be prefixed with the crate name to avoid accidentally triggering features in other crates.
216+
For example, if your crate is named `awesome-lib` and depends on two different nightly features, `std::intrinsics::black_box` and `std::intrinsics::catch_unwind`, create two cfgs named `awesome_lib_black_box` and `awesome_lib_catch_unwind`.
216217

217218
When doing feature detection, we recommend *against* simply checking whether the compiler is a nightly channel, as nightly features frequently change between compiler versions.
218219
Feature detection should compile a sample rust program and verify that it works.
220+
Note that flags like `-Z allow-features` may affect whether features are allowed.
219221

220222
[nightly channel]: https://rust-lang.github.io/rustup/concepts/channels.html

0 commit comments

Comments
 (0)