Skip to content

Commit 6d09d8d

Browse files
committed
add unstable_features to ParseSess
1 parent b0dba74 commit 6d09d8d

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/libsyntax/feature_gate.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use parse::ParseSess;
3636
use parse::token::InternedString;
3737

3838
use std::ascii::AsciiExt;
39+
use std::env;
3940

4041
macro_rules! setter {
4142
($field: ident) => {{
@@ -1296,6 +1297,23 @@ pub enum UnstableFeatures {
12961297
Cheat
12971298
}
12981299

1300+
impl UnstableFeatures {
1301+
pub fn from_environment() -> UnstableFeatures {
1302+
// Whether this is a feature-staged build, i.e. on the beta or stable channel
1303+
let disable_unstable_features = option_env!("CFG_DISABLE_UNSTABLE_FEATURES").is_some();
1304+
// The secret key needed to get through the rustc build itself by
1305+
// subverting the unstable features lints
1306+
let bootstrap_secret_key = option_env!("CFG_BOOTSTRAP_KEY");
1307+
// The matching key to the above, only known by the build system
1308+
let bootstrap_provided_key = env::var("RUSTC_BOOTSTRAP_KEY").ok();
1309+
match (disable_unstable_features, bootstrap_secret_key, bootstrap_provided_key) {
1310+
(_, Some(ref s), Some(ref p)) if s == p => UnstableFeatures::Cheat,
1311+
(true, _, _) => UnstableFeatures::Disallow,
1312+
(false, _, _) => UnstableFeatures::Allow
1313+
}
1314+
}
1315+
}
1316+
12991317
fn maybe_stage_features(span_handler: &Handler, krate: &ast::Crate,
13001318
unstable: UnstableFeatures) {
13011319
let allow_features = match unstable {

src/libsyntax/parse/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use ast;
1414
use codemap::CodeMap;
1515
use syntax_pos::{self, Span, FileMap};
1616
use errors::{Handler, ColorConfig, DiagnosticBuilder};
17+
use feature_gate::UnstableFeatures;
1718
use parse::parser::Parser;
1819
use parse::token::InternedString;
1920
use ptr::P;
@@ -42,6 +43,7 @@ pub mod obsolete;
4243
/// Info about a parsing session.
4344
pub struct ParseSess {
4445
pub span_diagnostic: Handler, // better be the same as the one in the reader!
46+
pub unstable_features: UnstableFeatures,
4547
/// Used to determine and report recursive mod inclusions
4648
included_mod_stack: RefCell<Vec<PathBuf>>,
4749
code_map: Rc<CodeMap>,
@@ -60,6 +62,7 @@ impl ParseSess {
6062
pub fn with_span_handler(handler: Handler, code_map: Rc<CodeMap>) -> ParseSess {
6163
ParseSess {
6264
span_diagnostic: handler,
65+
unstable_features: UnstableFeatures::from_environment(),
6366
included_mod_stack: RefCell::new(vec![]),
6467
code_map: code_map
6568
}

0 commit comments

Comments
 (0)