Skip to content

Commit 823a990

Browse files
committed
Document that nightly features should be opt-in using a cargo feature
1 parent 385ba00 commit 823a990

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/checklist.md

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
- [ ] Structs have private fields ([C-STRUCT-PRIVATE])
6969
- [ ] Newtypes encapsulate implementation details ([C-NEWTYPE-HIDE])
7070
- [ ] Data structures do not duplicate derived trait bounds ([C-STRUCT-BOUNDS])
71+
- [ ] Nightly features use an explicit opt-in ([C-NIGHTLY-OPTIN])
7172
- **Necessities** *(to whom they matter, they really matter)*
7273
- [ ] Public dependencies of a stable crate are stable ([C-STABLE])
7374
- [ ] Crate and its dependencies have a permissive license ([C-PERMISSIVE])
@@ -135,6 +136,7 @@
135136
[C-STRUCT-PRIVATE]: future-proofing.html#c-struct-private
136137
[C-NEWTYPE-HIDE]: future-proofing.html#c-newtype-hide
137138
[C-STRUCT-BOUNDS]: future-proofing.html#c-struct-bounds
139+
[C-NIGHTLY-OPTIN]: future-proofing.html#c-nightly-optin
138140

139141
[C-STABLE]: necessities.html#c-stable
140142
[C-PERMISSIVE]: necessities.html#c-permissive

src/future-proofing.md

+16
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,19 @@ on the data structure.
202202
[`std::borrow::Cow`]: https://doc.rust-lang.org/std/borrow/enum.Cow.html
203203
[`std::boxed::Box`]: https://doc.rust-lang.org/std/boxed/struct.Box.html
204204
[`std::io::BufWriter`]: https://doc.rust-lang.org/std/io/struct.BufWriter.html
205+
206+
<a id="c-nightly-optin"></a>
207+
## Nightly features use an explicit opt-in (C-NIGHTLY-OPTIN)
208+
209+
Some libraries need to use, or want to experiment with, the [nightly channel].
210+
To avoid accidental breakage, libraries should either:
211+
- 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.
213+
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`.
216+
217+
When doing feature detection, we recommend *against* simply checking whether the compiler is a nightly channel, as nightly features frequently change between compiler versions.
218+
Feature detection should compile a sample rust program and verify that it works.
219+
220+
[nightly channel]: https://rust-lang.github.io/rustup/concepts/channels.html

0 commit comments

Comments
 (0)