@@ -36,6 +36,7 @@ use parse::ParseSess;
36
36
use parse:: token:: InternedString ;
37
37
38
38
use std:: ascii:: AsciiExt ;
39
+ use std:: env;
39
40
40
41
macro_rules! setter {
41
42
( $field: ident) => { {
@@ -1296,6 +1297,23 @@ pub enum UnstableFeatures {
1296
1297
Cheat
1297
1298
}
1298
1299
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
+
1299
1317
fn maybe_stage_features ( span_handler : & Handler , krate : & ast:: Crate ,
1300
1318
unstable : UnstableFeatures ) {
1301
1319
let allow_features = match unstable {
0 commit comments