Skip to content

Commit d0623cf

Browse files
authored
Auto merge of #36678 - TimNN:fix-dist, r=alexcrichton
emit feature help in cheat mode (fix nightlies) This should fix the `distcheck` failure in the latest nightly. cc #36539 It's probably not ideal to check the environment that often and the code ist duplicated from `librustc/session/config.rs` but this was the easiest fix I could think of. A cleaner solution would probably be to move the `unstable_features` from `Options` to `ParseSess` and change the `diag` parameter of `emit_feature_err` to take `ParseSess` instead of a `Handler`.
2 parents 388c3f2 + f0e1738 commit d0623cf

File tree

19 files changed

+79
-78
lines changed

19 files changed

+79
-78
lines changed

src/librustc/middle/stability.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,8 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
411411
&feature, &r),
412412
None => format!("use of unstable library feature '{}'", &feature)
413413
};
414-
emit_feature_err(&self.tcx.sess.parse_sess.span_diagnostic,
415-
&feature, span, GateIssue::Library(Some(issue)), &msg);
414+
emit_feature_err(&self.tcx.sess.parse_sess, &feature, span,
415+
GateIssue::Library(Some(issue)), &msg);
416416
}
417417
}
418418
Some(&Stability { ref level, ref feature, .. }) => {

src/librustc/session/config.rs

Lines changed: 5 additions & 26 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,26 +1559,21 @@ 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 {
15821566
is_nightly_build() && matches.opt_strs("Z").iter().any(|x| *x == "unstable-options")
15831567
}
15841568

15851569
pub fn is_nightly_build() -> bool {
1586-
match get_unstable_features_setting() {
1587-
UnstableFeatures::Allow | UnstableFeatures::Cheat => true,
1588-
_ => false,
1589-
}
1570+
UnstableFeatures::from_environment().is_nightly_build()
15901571
}
15911572

15921573
pub fn check_nightly_options(matches: &getopts::Matches, flags: &[RustcOptGroup]) {
15931574
let has_z_unstable_option = matches.opt_strs("Z").iter().any(|x| *x == "unstable-options");
1594-
let really_allows_unstable_options = match get_unstable_features_setting() {
1595-
UnstableFeatures::Disallow => false,
1596-
_ => true,
1597-
};
1575+
let really_allows_unstable_options = UnstableFeatures::from_environment()
1576+
.is_nightly_build();
15981577

15991578
for opt in flags.iter() {
16001579
if opt.stability == OptionStability::Stable {

src/librustc_driver/lib.rs

Lines changed: 3 additions & 5 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,10 +649,8 @@ impl RustcDefaultCalls {
649649
}
650650
}
651651
PrintRequest::Cfg => {
652-
let allow_unstable_cfg = match get_unstable_features_setting() {
653-
UnstableFeatures::Disallow => false,
654-
_ => true,
655-
};
652+
let allow_unstable_cfg = UnstableFeatures::from_environment()
653+
.is_nightly_build();
656654

657655
for cfg in cfg {
658656
if !allow_unstable_cfg && GatedCfg::gate(&*cfg).is_some() {

src/librustc_passes/static_recursion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
143143
});
144144
if any_static {
145145
if !self.sess.features.borrow().static_recursion {
146-
emit_feature_err(&self.sess.parse_sess.span_diagnostic,
146+
emit_feature_err(&self.sess.parse_sess,
147147
"static_recursion",
148148
*self.root_span,
149149
GateIssue::Language,

src/librustc_resolve/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ impl<'a> Resolver<'a> {
149149

150150
fn insert_custom_derive(&mut self, name: &str, ext: Rc<MultiItemModifier>, sp: Span) {
151151
if !self.session.features.borrow().rustc_macro {
152-
let diagnostic = &self.session.parse_sess.span_diagnostic;
152+
let sess = &self.session.parse_sess;
153153
let msg = "loading custom derive macro crates is experimentally supported";
154-
emit_feature_err(diagnostic, "rustc_macro", sp, feature_gate::GateIssue::Language, msg);
154+
emit_feature_err(sess, "rustc_macro", sp, feature_gate::GateIssue::Language, msg);
155155
}
156156
if self.derive_modes.insert(token::intern(name), ext).is_some() {
157157
self.session.span_err(sp, &format!("cannot shadow existing derive mode `{}`", name));

src/librustc_typeck/astconv.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
795795
// For now, require that parenthetical notation be used
796796
// only with `Fn()` etc.
797797
if !self.tcx().sess.features.borrow().unboxed_closures && trait_def.paren_sugar {
798-
emit_feature_err(&self.tcx().sess.parse_sess.span_diagnostic,
798+
emit_feature_err(&self.tcx().sess.parse_sess,
799799
"unboxed_closures", span, GateIssue::Language,
800800
"\
801801
the precise format of `Fn`-family traits' \
@@ -807,7 +807,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
807807
// For now, require that parenthetical notation be used
808808
// only with `Fn()` etc.
809809
if !self.tcx().sess.features.borrow().unboxed_closures && !trait_def.paren_sugar {
810-
emit_feature_err(&self.tcx().sess.parse_sess.span_diagnostic,
810+
emit_feature_err(&self.tcx().sess.parse_sess,
811811
"unboxed_closures", span, GateIssue::Language,
812812
"\
813813
parenthetical notation is only stable when used with `Fn`-family traits");

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3255,7 +3255,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
32553255
if let Some((def_id, variant)) = variant {
32563256
if variant.kind == ty::VariantKind::Tuple &&
32573257
!self.tcx.sess.features.borrow().relaxed_adts {
3258-
emit_feature_err(&self.tcx.sess.parse_sess.span_diagnostic,
3258+
emit_feature_err(&self.tcx.sess.parse_sess,
32593259
"relaxed_adts", span, GateIssue::Language,
32603260
"tuple structs and variants in struct patterns are unstable");
32613261
}

src/librustdoc/html/markdown.rs

Lines changed: 4 additions & 8 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,13 +477,10 @@ 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() {
482-
UnstableFeatures::Allow | UnstableFeatures::Cheat => {
483-
allow_compile_fail = true;
484-
allow_error_code_check = true;
485-
}
486-
_ => {},
487-
};
480+
if UnstableFeatures::from_environment().is_nightly_build() {
481+
allow_compile_fail = true;
482+
allow_error_code_check = true;
483+
}
488484

489485
let tokens = string.split(|c: char|
490486
!(c == '_' || c == '-' || c.is_alphanumeric())

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)