@@ -36,6 +36,7 @@ use parse::ParseSess;
3636use parse:: token:: InternedString ;
3737
3838use std:: ascii:: AsciiExt ;
39+ use std:: env;
3940
4041macro_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+
12991317fn maybe_stage_features ( span_handler : & Handler , krate : & ast:: Crate ,
13001318 unstable : UnstableFeatures ) {
13011319 let allow_features = match unstable {
0 commit comments