refactor away get_unstable_features_setting
This commit is contained in:
parent
ba838dc4e9
commit
3f287efc82
5 changed files with 12 additions and 30 deletions
|
@ -37,7 +37,6 @@ use std::collections::btree_map::Iter as BTreeMapIter;
|
|||
use std::collections::btree_map::Keys as BTreeMapKeysIter;
|
||||
use std::collections::btree_map::Values as BTreeMapValuesIter;
|
||||
|
||||
use std::env;
|
||||
use std::fmt;
|
||||
use std::hash::{Hasher, SipHasher};
|
||||
use std::iter::FromIterator;
|
||||
|
@ -1525,27 +1524,12 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches)
|
|||
crate_name: crate_name,
|
||||
alt_std_name: None,
|
||||
libs: libs,
|
||||
unstable_features: get_unstable_features_setting(),
|
||||
unstable_features: UnstableFeatures::from_environment(),
|
||||
debug_assertions: debug_assertions,
|
||||
},
|
||||
cfg)
|
||||
}
|
||||
|
||||
pub fn get_unstable_features_setting() -> UnstableFeatures {
|
||||
// Whether this is a feature-staged build, i.e. on the beta or stable channel
|
||||
let disable_unstable_features = option_env!("CFG_DISABLE_UNSTABLE_FEATURES").is_some();
|
||||
// The secret key needed to get through the rustc build itself by
|
||||
// subverting the unstable features lints
|
||||
let bootstrap_secret_key = option_env!("CFG_BOOTSTRAP_KEY");
|
||||
// The matching key to the above, only known by the build system
|
||||
let bootstrap_provided_key = env::var("RUSTC_BOOTSTRAP_KEY").ok();
|
||||
match (disable_unstable_features, bootstrap_secret_key, bootstrap_provided_key) {
|
||||
(_, Some(ref s), Some(ref p)) if s == p => UnstableFeatures::Cheat,
|
||||
(true, ..) => UnstableFeatures::Disallow,
|
||||
(false, ..) => UnstableFeatures::Allow
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateType>, String> {
|
||||
let mut crate_types: Vec<CrateType> = Vec::new();
|
||||
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
|
|||
pub mod nightly_options {
|
||||
use getopts;
|
||||
use syntax::feature_gate::UnstableFeatures;
|
||||
use super::{ErrorOutputType, OptionStability, RustcOptGroup, get_unstable_features_setting};
|
||||
use super::{ErrorOutputType, OptionStability, RustcOptGroup};
|
||||
use session::{early_error, early_warn};
|
||||
|
||||
pub fn is_unstable_enabled(matches: &getopts::Matches) -> bool {
|
||||
|
@ -1588,7 +1572,7 @@ pub mod nightly_options {
|
|||
|
||||
pub fn check_nightly_options(matches: &getopts::Matches, flags: &[RustcOptGroup]) {
|
||||
let has_z_unstable_option = matches.opt_strs("Z").iter().any(|x| *x == "unstable-options");
|
||||
let really_allows_unstable_options = match get_unstable_features_setting() {
|
||||
let really_allows_unstable_options = match UnstableFeatures::from_environment() {
|
||||
UnstableFeatures::Disallow => false,
|
||||
_ => true,
|
||||
};
|
||||
|
|
|
@ -73,7 +73,7 @@ use rustc_trans::back::write::{create_target_machine, RELOC_MODEL_ARGS, CODE_GEN
|
|||
use rustc::dep_graph::DepGraph;
|
||||
use rustc::session::{self, config, Session, build_session, CompileResult};
|
||||
use rustc::session::config::{Input, PrintRequest, OutputType, ErrorOutputType};
|
||||
use rustc::session::config::{get_unstable_features_setting, nightly_options};
|
||||
use rustc::session::config::nightly_options;
|
||||
use rustc::lint::Lint;
|
||||
use rustc::lint;
|
||||
use rustc_metadata::loader;
|
||||
|
@ -649,7 +649,7 @@ impl RustcDefaultCalls {
|
|||
}
|
||||
}
|
||||
PrintRequest::Cfg => {
|
||||
let allow_unstable_cfg = match get_unstable_features_setting() {
|
||||
let allow_unstable_cfg = match UnstableFeatures::from_environment() {
|
||||
UnstableFeatures::Disallow => false,
|
||||
_ => true,
|
||||
};
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#![allow(non_camel_case_types)]
|
||||
|
||||
use libc;
|
||||
use rustc::session::config::get_unstable_features_setting;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::cell::RefCell;
|
||||
use std::default::Default;
|
||||
|
@ -478,7 +477,7 @@ impl LangString {
|
|||
let mut data = LangString::all_false();
|
||||
let mut allow_compile_fail = false;
|
||||
let mut allow_error_code_check = false;
|
||||
match get_unstable_features_setting() {
|
||||
match UnstableFeatures::from_environment() {
|
||||
UnstableFeatures::Allow | UnstableFeatures::Cheat => {
|
||||
allow_compile_fail = true;
|
||||
allow_error_code_check = true;
|
||||
|
|
|
@ -58,7 +58,6 @@ use syntax::feature_gate::UnstableFeatures;
|
|||
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
|
||||
use rustc::middle::privacy::AccessLevels;
|
||||
use rustc::middle::stability;
|
||||
use rustc::session::config::get_unstable_features_setting;
|
||||
use rustc::hir;
|
||||
use rustc::util::nodemap::{FnvHashMap, FnvHashSet};
|
||||
use rustc_data_structures::flock;
|
||||
|
@ -1971,7 +1970,7 @@ fn item_static(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
|||
fn item_function(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
|
||||
f: &clean::Function) -> fmt::Result {
|
||||
// FIXME(#24111): remove when `const_fn` is stabilized
|
||||
let vis_constness = match get_unstable_features_setting() {
|
||||
let vis_constness = match UnstableFeatures::from_environment() {
|
||||
UnstableFeatures::Allow => f.constness,
|
||||
_ => hir::Constness::NotConst
|
||||
};
|
||||
|
@ -2250,7 +2249,7 @@ fn render_assoc_item(w: &mut fmt::Formatter,
|
|||
}
|
||||
};
|
||||
// FIXME(#24111): remove when `const_fn` is stabilized
|
||||
let vis_constness = match get_unstable_features_setting() {
|
||||
let vis_constness = match UnstableFeatures::from_environment() {
|
||||
UnstableFeatures::Allow => constness,
|
||||
_ => hir::Constness::NotConst
|
||||
};
|
||||
|
|
|
@ -25,8 +25,7 @@ use rustc_lint;
|
|||
use rustc::dep_graph::DepGraph;
|
||||
use rustc::hir::map as hir_map;
|
||||
use rustc::session::{self, config};
|
||||
use rustc::session::config::{get_unstable_features_setting, OutputType,
|
||||
OutputTypes, Externs};
|
||||
use rustc::session::config::{OutputType, OutputTypes, Externs};
|
||||
use rustc::session::search_paths::{SearchPaths, PathKind};
|
||||
use rustc_back::dynamic_lib::DynamicLibrary;
|
||||
use rustc_back::tempdir::TempDir;
|
||||
|
@ -35,6 +34,7 @@ use rustc_driver::driver::phase_2_configure_and_expand;
|
|||
use rustc_metadata::cstore::CStore;
|
||||
use rustc_resolve::MakeGlobMap;
|
||||
use syntax::codemap::CodeMap;
|
||||
use syntax::feature_gate::UnstableFeatures;
|
||||
use errors;
|
||||
use errors::emitter::ColorConfig;
|
||||
|
||||
|
@ -68,7 +68,7 @@ pub fn run(input: &str,
|
|||
search_paths: libs.clone(),
|
||||
crate_types: vec!(config::CrateTypeDylib),
|
||||
externs: externs.clone(),
|
||||
unstable_features: get_unstable_features_setting(),
|
||||
unstable_features: UnstableFeatures::from_environment(),
|
||||
..config::basic_options().clone()
|
||||
};
|
||||
|
||||
|
@ -197,7 +197,7 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
|
|||
.. config::basic_codegen_options()
|
||||
},
|
||||
test: as_test_harness,
|
||||
unstable_features: get_unstable_features_setting(),
|
||||
unstable_features: UnstableFeatures::from_environment(),
|
||||
..config::basic_options().clone()
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue