Skip to content

Commit c27133e

Browse files
committed
Preliminary feature staging
This partially implements the feature staging described in the [release channel RFC][rc]. It does not yet fully conform to the RFC as written, but does accomplish its goals sufficiently for the 1.0 alpha release. It has three primary user-visible effects: * On the nightly channel, use of unstable APIs generates a warning. * On the beta channel, use of unstable APIs generates a warning. * On the beta channel, use of feature gates generates a warning. Code that does not trigger these warnings is considered 'stable', modulo pre-1.0 bugs. Disabling the warnings for unstable APIs continues to be done in the existing (i.e. old) style, via `#[allow(...)]`, not that specified in the RFC. I deem this marginally acceptable since any code that must do this is not using the stable dialect of Rust. Use of feature gates is itself gated with the new 'unstable_features' lint, on nightly set to 'allow', and on beta 'warn'. The attribute scheme used here corresponds to an older version of the RFC, with the `#[staged_api]` crate attribute toggling the staging behavior of the stability attributes, but the user impact is only in-tree so I'm not concerned about having to make design changes later (and I may ultimately prefer the scheme here after all, with the `#[staged_api]` crate attribute). Since the Rust codebase itself makes use of unstable features the compiler and build system to a midly elaborate dance to allow it to bootstrap while disobeying these lints (which would otherwise be errors because Rust builds with `-D warnings`). This patch includes one significant hack that causes a regression. Because the `format_args!` macro emits calls to unstable APIs it would trigger the lint. I added a hack to the lint to make it not trigger, but this in turn causes arguments to `println!` not to be checked for feature gates. I don't presently understand macro expansion well enough to fix. This is bug #20661. Closes #16678 [rc]: https://github.com/rust-lang/rfcs/blob/master/text/0507-release-channels.md
1 parent 9f1ead8 commit c27133e

File tree

43 files changed

+272
-34
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+272
-34
lines changed

configure

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,18 @@ then
599599
fi
600600
putvar CFG_RELEASE_CHANNEL
601601

602+
# A magic value that allows the compiler to use unstable features
603+
# during the bootstrap even when doing so would normally be an error
604+
# because of feature staging or because the build turns on
605+
# warnings-as-errors and unstable features default to warnings. The
606+
# build has to match this key in an env var. Meant to be a mild
607+
# deterrent from users just turning on unstable features on the stable
608+
# channel.
609+
# Basing CFG_BOOTSTRAP_KEY on CFG_BOOTSTRAP_KEY lets it get picked up
610+
# during a Makefile reconfig.
611+
CFG_BOOTSTRAP_KEY="${CFG_BOOTSTRAP_KEY-`date +%N`}"
612+
putvar CFG_BOOTSTRAP_KEY
613+
602614
step_msg "looking for build programs"
603615

604616
probe_need CFG_PERL perl

mk/main.mk

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ ifeq ($(CFG_RELEASE_CHANNEL),stable)
2525
CFG_RELEASE=$(CFG_RELEASE_NUM)
2626
# This is the string used in dist artifact file names, e.g. "0.12.0", "nightly"
2727
CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)
28+
CFG_DISABLE_UNSTABLE_FEATURES=1
2829
endif
2930
ifeq ($(CFG_RELEASE_CHANNEL),beta)
3031
# The beta channel is temporarily called 'alpha'
3132
CFG_RELEASE=$(CFG_RELEASE_NUM)-alpha$(CFG_BETA_CYCLE)
3233
CFG_PACKAGE_VERS=$(CFG_RELEASE_NUM)-alpha$(CFG_BETA_CYCLE)
34+
CFG_DISABLE_UNSTABLE_FEATURES=1
3335
endif
3436
ifeq ($(CFG_RELEASE_CHANNEL),nightly)
3537
CFG_RELEASE=$(CFG_RELEASE_NUM)-nightly
@@ -319,11 +321,20 @@ export CFG_VERSION_WIN
319321
export CFG_RELEASE
320322
export CFG_PACKAGE_NAME
321323
export CFG_BUILD
324+
export CFG_RELEASE_CHANNEL
322325
export CFG_LLVM_ROOT
323326
export CFG_PREFIX
324327
export CFG_LIBDIR
325328
export CFG_LIBDIR_RELATIVE
326329
export CFG_DISABLE_INJECT_STD_VERSION
330+
ifdef CFG_DISABLE_UNSTABLE_FEATURES
331+
CFG_INFO := $(info cfg: disabling unstable features (CFG_DISABLE_UNSTABLE_FEATURES))
332+
# Turn on feature-staging
333+
export CFG_DISABLE_UNSTABLE_FEATURES
334+
endif
335+
# Subvert unstable feature lints to do the self-build
336+
export CFG_BOOTSTRAP_KEY
337+
export RUSTC_BOOTSTRAP_KEY:=$(CFG_BOOTSTRAP_KEY)
327338

328339
######################################################################
329340
# Per-stage targets and runner

src/liballoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
5959
#![crate_name = "alloc"]
6060
#![experimental]
61+
#![staged_api]
6162
#![crate_type = "rlib"]
6263
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
6364
html_favicon_url = "http://www.rust-lang.org/favicon.ico",

src/libarena/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
2222
#![crate_name = "arena"]
2323
#![experimental]
24+
#![staged_api]
2425
#![crate_type = "rlib"]
2526
#![crate_type = "dylib"]
2627
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",

src/libcollections/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#![crate_name = "collections"]
1717
#![experimental]
18+
#![staged_api]
1819
#![crate_type = "rlib"]
1920
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
2021
html_favicon_url = "http://www.rust-lang.org/favicon.ico",

src/libcore/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
#![crate_name = "core"]
5151
#![experimental]
52+
#![staged_api]
5253
#![crate_type = "rlib"]
5354
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
5455
html_favicon_url = "http://www.rust-lang.org/favicon.ico",

src/libflate/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
1717
#![crate_name = "flate"]
1818
#![experimental]
19+
#![staged_api]
1920
#![crate_type = "rlib"]
2021
#![crate_type = "dylib"]
2122
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",

src/libfmt_macros/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
1717
#![crate_name = "fmt_macros"]
1818
#![experimental]
19+
#![staged_api]
1920
#![crate_type = "rlib"]
2021
#![crate_type = "dylib"]
2122
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",

src/libgetopts/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
8080
#![crate_name = "getopts"]
8181
#![experimental = "use the crates.io `getopts` library instead"]
82+
#![staged_api]
8283
#![crate_type = "rlib"]
8384
#![crate_type = "dylib"]
8485
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",

src/libgraphviz/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@
266266
267267
#![crate_name = "graphviz"]
268268
#![experimental]
269+
#![staged_api]
269270
#![crate_type = "rlib"]
270271
#![crate_type = "dylib"]
271272
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",

0 commit comments

Comments
 (0)