Skip to content

Commit 4e0a100

Browse files
committed
Magic cookies no more
Do not use magic values to forbid the use of unstable values. WIP to fix rust-lang#21230
1 parent f3d71be commit 4e0a100

File tree

5 files changed

+18
-27
lines changed

5 files changed

+18
-27
lines changed

configure

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -603,18 +603,6 @@ then
603603
fi
604604
putvar CFG_RELEASE_CHANNEL
605605

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

620608
probe_need CFG_PERL perl

mk/main.mk

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ endif
157157
# that the snapshot will be generated with a statically linked rustc so we only
158158
# have to worry about the distribution of one file (with its native dynamic
159159
# dependencies)
160-
RUSTFLAGS_STAGE0 += -C prefer-dynamic
161-
RUSTFLAGS_STAGE1 += -C prefer-dynamic
160+
RUSTFLAGS_STAGE0 += -C prefer-dynamic --cfg allow_unstable
161+
RUSTFLAGS_STAGE1 += -C prefer-dynamic --cfg allow_unstable
162+
RUSTFLAGS_STAGE2 += --cfg allow_unstable
162163
RUST_LIB_FLAGS_ST2 += -C prefer-dynamic
163164
RUST_LIB_FLAGS_ST3 += -C prefer-dynamic
164165

@@ -331,9 +332,6 @@ CFG_INFO := $(info cfg: disabling unstable features (CFG_DISABLE_UNSTABLE_FEATUR
331332
# Turn on feature-staging
332333
export CFG_DISABLE_UNSTABLE_FEATURES
333334
endif
334-
# Subvert unstable feature lints to do the self-build
335-
export CFG_BOOTSTRAP_KEY
336-
export RUSTC_BOOTSTRAP_KEY:=$(CFG_BOOTSTRAP_KEY)
337335

338336
######################################################################
339337
# Per-stage targets and runner

src/driver/driver.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ extern crate "rustdoc" as this;
1414
#[cfg(rustc)]
1515
extern crate "rustc_driver" as this;
1616

17-
fn main() { this::main() }
17+
use std::sync::atomic::Ordering;
18+
19+
fn main() {
20+
this::ALLOW_UNSTABLE.store(cfg!(allow_unstable), Ordering::Relaxed);
21+
this::main()
22+
}

src/librustc_driver/lib.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ use std::io;
6767
use std::iter::repeat;
6868
use std::os;
6969
use std::sync::mpsc::channel;
70+
use std::sync::atomic;
7071
use std::thread;
7172

7273
use rustc::session::early_error;
@@ -87,6 +88,8 @@ pub fn run(args: Vec<String>) -> int {
8788
0
8889
}
8990

91+
pub static ALLOW_UNSTABLE: atomic::AtomicBool = atomic::ATOMIC_BOOL_INIT;
92+
9093
static BUG_REPORT_URL: &'static str =
9194
"http://doc.rust-lang.org/complement-bugreport.html";
9295

@@ -235,15 +238,10 @@ fn build_controller<'a>(sess: &Session) -> CompileController<'a> {
235238
pub fn get_unstable_features_setting() -> UnstableFeatures {
236239
// Whether this is a feature-staged build, i.e. on the beta or stable channel
237240
let disable_unstable_features = option_env!("CFG_DISABLE_UNSTABLE_FEATURES").is_some();
238-
// The secret key needed to get through the rustc build itself by
239-
// subverting the unstable features lints
240-
let bootstrap_secret_key = option_env!("CFG_BOOTSTRAP_KEY");
241-
// The matching key to the above, only known by the build system
242-
let bootstrap_provided_key = os::getenv("RUSTC_BOOTSTRAP_KEY");
243-
match (disable_unstable_features, bootstrap_secret_key, bootstrap_provided_key) {
244-
(_, Some(ref s), Some(ref p)) if s == p => UnstableFeatures::Cheat,
245-
(true, _, _) => UnstableFeatures::Disallow,
246-
(false, _, _) => UnstableFeatures::Default
241+
match (disable_unstable_features, ALLOW_UNSTABLE.load(atomic::Ordering::Relaxed)) {
242+
(_, true) => UnstableFeatures::Cheat,
243+
(true, _) => UnstableFeatures::Disallow,
244+
(false, _) => UnstableFeatures::Default
247245
}
248246
}
249247

src/librustdoc/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ use rustc::session::search_paths::SearchPaths;
4747

4848
// reexported from `clean` so it can be easily updated with the mod itself
4949
pub use clean::SCHEMA_VERSION;
50+
// reexported since driver/driver.rs needs it
51+
pub use rustc_driver::ALLOW_UNSTABLE;
5052

5153
#[macro_use]
5254
pub mod externalfiles;

0 commit comments

Comments
 (0)