Skip to content

Commit 3f287ef

Browse files
committed
refactor away get_unstable_features_setting
1 parent ba838dc commit 3f287ef

File tree

5 files changed

+12
-30
lines changed

5 files changed

+12
-30
lines changed

src/librustc/session/config.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use std::collections::btree_map::Iter as BTreeMapIter;
3737
use std::collections::btree_map::Keys as BTreeMapKeysIter;
3838
use std::collections::btree_map::Values as BTreeMapValuesIter;
3939

40-
use std::env;
4140
use std::fmt;
4241
use std::hash::{Hasher, SipHasher};
4342
use std::iter::FromIterator;
@@ -1525,27 +1524,12 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
15251524
crate_name: crate_name,
15261525
alt_std_name: None,
15271526
libs: libs,
1528-
unstable_features: get_unstable_features_setting(),
1527+
unstable_features: UnstableFeatures::from_environment(),
15291528
debug_assertions: debug_assertions,
15301529
},
15311530
cfg)
15321531
}
15331532

1534-
pub fn get_unstable_features_setting() -> UnstableFeatures {
1535-
// Whether this is a feature-staged build, i.e. on the beta or stable channel
1536-
let disable_unstable_features = option_env!("CFG_DISABLE_UNSTABLE_FEATURES").is_some();
1537-
// The secret key needed to get through the rustc build itself by
1538-
// subverting the unstable features lints
1539-
let bootstrap_secret_key = option_env!("CFG_BOOTSTRAP_KEY");
1540-
// The matching key to the above, only known by the build system
1541-
let bootstrap_provided_key = env::var("RUSTC_BOOTSTRAP_KEY").ok();
1542-
match (disable_unstable_features, bootstrap_secret_key, bootstrap_provided_key) {
1543-
(_, Some(ref s), Some(ref p)) if s == p => UnstableFeatures::Cheat,
1544-
(true, ..) => UnstableFeatures::Disallow,
1545-
(false, ..) => UnstableFeatures::Allow
1546-
}
1547-
}
1548-
15491533
pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateType>, String> {
15501534
let mut crate_types: Vec<CrateType> = Vec::new();
15511535
for unparsed_crate_type in &list_list {
@@ -1575,7 +1559,7 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
15751559
pub mod nightly_options {
15761560
use getopts;
15771561
use syntax::feature_gate::UnstableFeatures;
1578-
use super::{ErrorOutputType, OptionStability, RustcOptGroup, get_unstable_features_setting};
1562+
use super::{ErrorOutputType, OptionStability, RustcOptGroup};
15791563
use session::{early_error, early_warn};
15801564

15811565
pub fn is_unstable_enabled(matches: &getopts::Matches) -> bool {
@@ -1588,7 +1572,7 @@ pub mod nightly_options {
15881572

15891573
pub fn check_nightly_options(matches: &getopts::Matches, flags: &[RustcOptGroup]) {
15901574
let has_z_unstable_option = matches.opt_strs("Z").iter().any(|x| *x == "unstable-options");
1591-
let really_allows_unstable_options = match get_unstable_features_setting() {
1575+
let really_allows_unstable_options = match UnstableFeatures::from_environment() {
15921576
UnstableFeatures::Disallow => false,
15931577
_ => true,
15941578
};

src/librustc_driver/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ use rustc_trans::back::write::{create_target_machine, RELOC_MODEL_ARGS, CODE_GEN
7373
use rustc::dep_graph::DepGraph;
7474
use rustc::session::{self, config, Session, build_session, CompileResult};
7575
use rustc::session::config::{Input, PrintRequest, OutputType, ErrorOutputType};
76-
use rustc::session::config::{get_unstable_features_setting, nightly_options};
76+
use rustc::session::config::nightly_options;
7777
use rustc::lint::Lint;
7878
use rustc::lint;
7979
use rustc_metadata::loader;
@@ -649,7 +649,7 @@ impl RustcDefaultCalls {
649649
}
650650
}
651651
PrintRequest::Cfg => {
652-
let allow_unstable_cfg = match get_unstable_features_setting() {
652+
let allow_unstable_cfg = match UnstableFeatures::from_environment() {
653653
UnstableFeatures::Disallow => false,
654654
_ => true,
655655
};

src/librustdoc/html/markdown.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#![allow(non_camel_case_types)]
2828

2929
use libc;
30-
use rustc::session::config::get_unstable_features_setting;
3130
use std::ascii::AsciiExt;
3231
use std::cell::RefCell;
3332
use std::default::Default;
@@ -478,7 +477,7 @@ impl LangString {
478477
let mut data = LangString::all_false();
479478
let mut allow_compile_fail = false;
480479
let mut allow_error_code_check = false;
481-
match get_unstable_features_setting() {
480+
match UnstableFeatures::from_environment() {
482481
UnstableFeatures::Allow | UnstableFeatures::Cheat => {
483482
allow_compile_fail = true;
484483
allow_error_code_check = true;

src/librustdoc/html/render.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ use syntax::feature_gate::UnstableFeatures;
5858
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
5959
use rustc::middle::privacy::AccessLevels;
6060
use rustc::middle::stability;
61-
use rustc::session::config::get_unstable_features_setting;
6261
use rustc::hir;
6362
use rustc::util::nodemap::{FnvHashMap, FnvHashSet};
6463
use rustc_data_structures::flock;
@@ -1971,7 +1970,7 @@ fn item_static(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
19711970
fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
19721971
f: &clean::Function) -> fmt::Result {
19731972
// FIXME(#24111): remove when `const_fn` is stabilized
1974-
let vis_constness = match get_unstable_features_setting() {
1973+
let vis_constness = match UnstableFeatures::from_environment() {
19751974
UnstableFeatures::Allow => f.constness,
19761975
_ => hir::Constness::NotConst
19771976
};
@@ -2250,7 +2249,7 @@ fn render_assoc_item(w: &mut fmt::Formatter,
22502249
}
22512250
};
22522251
// FIXME(#24111): remove when `const_fn` is stabilized
2253-
let vis_constness = match get_unstable_features_setting() {
2252+
let vis_constness = match UnstableFeatures::from_environment() {
22542253
UnstableFeatures::Allow => constness,
22552254
_ => hir::Constness::NotConst
22562255
};

src/librustdoc/test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ use rustc_lint;
2525
use rustc::dep_graph::DepGraph;
2626
use rustc::hir::map as hir_map;
2727
use rustc::session::{self, config};
28-
use rustc::session::config::{get_unstable_features_setting, OutputType,
29-
OutputTypes, Externs};
28+
use rustc::session::config::{OutputType, OutputTypes, Externs};
3029
use rustc::session::search_paths::{SearchPaths, PathKind};
3130
use rustc_back::dynamic_lib::DynamicLibrary;
3231
use rustc_back::tempdir::TempDir;
@@ -35,6 +34,7 @@ use rustc_driver::driver::phase_2_configure_and_expand;
3534
use rustc_metadata::cstore::CStore;
3635
use rustc_resolve::MakeGlobMap;
3736
use syntax::codemap::CodeMap;
37+
use syntax::feature_gate::UnstableFeatures;
3838
use errors;
3939
use errors::emitter::ColorConfig;
4040

@@ -68,7 +68,7 @@ pub fn run(input: &str,
6868
search_paths: libs.clone(),
6969
crate_types: vec!(config::CrateTypeDylib),
7070
externs: externs.clone(),
71-
unstable_features: get_unstable_features_setting(),
71+
unstable_features: UnstableFeatures::from_environment(),
7272
..config::basic_options().clone()
7373
};
7474

@@ -197,7 +197,7 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
197197
.. config::basic_codegen_options()
198198
},
199199
test: as_test_harness,
200-
unstable_features: get_unstable_features_setting(),
200+
unstable_features: UnstableFeatures::from_environment(),
201201
..config::basic_options().clone()
202202
};
203203

0 commit comments

Comments
 (0)