Skip to content

Commit e0de3bb

Browse files
committed
rfc, cfg-path-version: highlight the risks of unstable.
1 parent 3333882 commit e0de3bb

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

text/0000-cfg-path-version.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,12 @@ is documented in [rust-lang-nursery/error-chain#101].
7575

7676
## `#[cfg(accessible($path))]`
7777

78-
Consider for a moment that we would like to use the `Iterator::flatten`
79-
method of the standard library if it exists, but otherwise fall back to
80-
`Itertools::flatten`. We can do that with the following snippet:
78+
Consider for a moment that we would like to use the `Iterator::flatten` method
79+
of the standard library if it exists (because it has become soon in a certain
80+
Rust version), but otherwise fall back to `Itertools::flatten`.
81+
We can do that with the following snippet:
8182

8283
```rust
83-
#![cfg_attr(feature = "unstable", feature(iterator_flatten))]
84-
8584
#[cfg(accessible(::std::iter::Flatten))]
8685
fn make_iter(limit: u8) -> impl Iterator<Item = u8> {
8786
(0..limit).map(move |x| (x..limit)).flatten()
@@ -100,33 +99,33 @@ fn main() {
10099

101100
What this snippet does is the following:
102101

103-
1. If the cargo feature `unstable` is enabled and assuming the compiler is
104-
capable of feature gates, but not otherwise, the feature `iterator_flatten`
105-
will be enabled.
106-
107-
2. If the path `::std::iter::Flatten` exists, the compiler will compile
102+
1. If the path `::std::iter::Flatten` exists, the compiler will compile
108103
the first version of `make_iter`. If the path does not exist,
109104
the compiler will instead compile the second version of `make_iter`.
110105

111-
The result of 1. and 2. is that your crate can opt into using
112-
`Iterator::flatten` when `feature = "unstable"` is enabled,
113-
but use `Itertools::flatten` on stable compilers meanwhile.
114-
Once the standard library has stabilized `iter::Flatten`,
115-
future stable compilers will start using the first version of the function.
116-
As a crate author, you don't have to publish any new versions of your crate for
117-
the compiler to switch to the libstd version when it is available in the future.
106+
The result of 1. is that your crate will use `Iterator::flatten` on newer
107+
versions of Rust and `Itertools::flatten` on older compilers.
108+
The result of this is that as a crate author, you don't have to publish any
109+
new versions of your crate for the compiler to switch to the libstd version
110+
when people use a newer version of Rust.
118111

119112
[`proptest`]: https://github.com/altsysrq/proptest
120113
[adding support]: https://github.com/AltSysrq/proptest/blob/67945c89e09f8223ae945cc8da029181822ce27e/src/num.rs#L66-L76
121114

122-
In this case we used the `feature = "unstable"` and `accessible` flags
123-
to handle a problem that the addition of `Iterator::flatten` caused for us
124-
if we had used `Itertools::flatten`. We can also use these mechanisms for
125-
strictly additive cases as well. Consider for example the [`proptest`] crate
126-
[adding support] for `RangeInclusive`:
115+
Once the standard library has stabilized `iter::Flatten`,
116+
future stable compilers will start using the first version of the function.
117+
118+
In this case we used the `accessible` flag to handle a problem that the addition
119+
of `Iterator::flatten` caused for us if we had used `Itertools::flatten`.
120+
We can also use these mechanisms for strictly additive cases as well.
121+
Consider for example the [`proptest`] crate [adding support] for `RangeInclusive`:
127122

128123
```rust
129-
#[cfg_attr(feature = "unstable", feature(inclusive_range))]
124+
// #[cfg_attr(feature = "unstable", feature(inclusive_range))]
125+
// ^-- If you include this line; then `cargo build --features unstable`
126+
// would cause nightly compilers to activate the feature gate.
127+
// Note that this has some inherent risks similar to those for
128+
// `#[cfg(nightly)]` (as discussed later in this RFC).
130129

131130
macro_rules! numeric_api {
132131
($typ:ident) => {

0 commit comments

Comments
 (0)