@@ -1381,18 +1381,29 @@ impl<'a> Builder<'a> {
13811381 // this), as well as #63012 which is the tracking issue for this
13821382 // feature on the rustc side.
13831383 cargo. arg ( "-Zbinary-dep-depinfo" ) ;
1384- match mode {
1385- Mode :: ToolBootstrap => {
1386- // Restrict the allowed features to those passed by rustbuild, so we don't depend on nightly accidentally.
1387- rustflags. arg ( "-Zallow-features=binary-dep-depinfo" ) ;
1388- }
1389- Mode :: ToolStd => {
1390- // Right now this is just compiletest and a few other tools that build on stable.
1391- // Allow them to use `feature(test)`, but nothing else.
1392- rustflags. arg ( "-Zallow-features=binary-dep-depinfo,test,proc_macro_internals,proc_macro_diagnostic,proc_macro_span" ) ;
1384+ let allow_features = match mode {
1385+ Mode :: ToolBootstrap | Mode :: ToolStd => {
1386+ // Restrict the allowed features so we don't depend on nightly
1387+ // accidentally.
1388+ //
1389+ // binary-dep-depinfo is used by rustbuild itself for all
1390+ // compilations.
1391+ //
1392+ // Lots of tools depend on proc_macro2 and proc-macro-error.
1393+ // Those have build scripts which assume nightly features are
1394+ // available if the `rustc` version is "nighty" or "dev". See
1395+ // bin/rustc.rs for why that is a problem. Instead of labeling
1396+ // those features for each individual tool that needs them,
1397+ // just blanket allow them here.
1398+ //
1399+ // If this is ever removed, be sure to add something else in
1400+ // its place to keep the restrictions in place (or make a way
1401+ // to unset RUSTC_BOOTSTRAP).
1402+ "binary-dep-depinfo,proc_macro_span,proc_macro_span_shrink,proc_macro_diagnostic"
1403+ . to_string ( )
13931404 }
1394- Mode :: Std | Mode :: Rustc | Mode :: Codegen | Mode :: ToolRustc => { }
1395- }
1405+ Mode :: Std | Mode :: Rustc | Mode :: Codegen | Mode :: ToolRustc => String :: new ( ) ,
1406+ } ;
13961407
13971408 cargo. arg ( "-j" ) . arg ( self . jobs ( ) . to_string ( ) ) ;
13981409
@@ -1915,7 +1926,7 @@ impl<'a> Builder<'a> {
19151926 }
19161927 }
19171928
1918- Cargo { command : cargo, rustflags, rustdocflags }
1929+ Cargo { command : cargo, rustflags, rustdocflags, allow_features }
19191930 }
19201931
19211932 /// Ensure that a given step is built, returning its output. This will
@@ -2094,6 +2105,7 @@ pub struct Cargo {
20942105 command : Command ,
20952106 rustflags : Rustflags ,
20962107 rustdocflags : Rustflags ,
2108+ allow_features : String ,
20972109}
20982110
20992111impl Cargo {
@@ -2138,6 +2150,18 @@ impl Cargo {
21382150 self . command . current_dir ( dir) ;
21392151 self
21402152 }
2153+
2154+ /// Adds nightly-only features that this invocation is allowed to use.
2155+ ///
2156+ /// By default, all nightly features are allowed. Once this is called, it
2157+ /// will be restricted to the given set.
2158+ pub fn allow_features ( & mut self , features : & str ) -> & mut Cargo {
2159+ if !self . allow_features . is_empty ( ) {
2160+ self . allow_features . push ( ',' ) ;
2161+ }
2162+ self . allow_features . push_str ( features) ;
2163+ self
2164+ }
21412165}
21422166
21432167impl From < Cargo > for Command {
@@ -2152,6 +2176,10 @@ impl From<Cargo> for Command {
21522176 cargo. command . env ( "RUSTDOCFLAGS" , rustdocflags) ;
21532177 }
21542178
2179+ if !cargo. allow_features . is_empty ( ) {
2180+ cargo. command . env ( "RUSTC_ALLOW_FEATURES" , cargo. allow_features ) ;
2181+ }
2182+
21552183 cargo. command
21562184 }
21572185}
0 commit comments