@@ -1630,6 +1630,13 @@ struct Compiletest {
16301630 compare_mode : Option < & ' static str > ,
16311631}
16321632
1633+ /// `compiletest` under `--stage 0` causes `compiletest` to be used with the beta compiler which can
1634+ /// cause many tests to fail. This env var is needed to indicate that the user understands the risk
1635+ /// and actually intends to use `compiletest` with `--stage 0`.
1636+ fn compiletest_force_stage0 ( ) -> bool {
1637+ env:: var ( "COMPILETEST_FORCE_STAGE0" ) . is_ok ( )
1638+ }
1639+
16331640impl Step for Compiletest {
16341641 type Output = ( ) ;
16351642
@@ -1647,7 +1654,7 @@ impl Step for Compiletest {
16471654 return ;
16481655 }
16491656
1650- if builder. top_stage == 0 && env :: var ( "COMPILETEST_FORCE_STAGE0" ) . is_err ( ) {
1657+ if builder. top_stage == 0 && ! compiletest_force_stage0 ( ) {
16511658 eprintln ! ( "\
16521659 ERROR: `--stage 0` runs compiletest on the beta compiler, not your local changes, and will almost always cause tests to fail
16531660HELP: to test the compiler, use `--stage 1` instead
@@ -1730,8 +1737,16 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
17301737 let is_rustdoc = suite. ends_with ( "rustdoc-ui" ) || suite. ends_with ( "rustdoc-js" ) ;
17311738
17321739 if mode == "run-make" {
1733- let cargo = builder. ensure ( tool:: Cargo { compiler, target : compiler. host } ) ;
1734- cmd. arg ( "--cargo-path" ) . arg ( cargo) ;
1740+ let cargo_path = if builder. top_stage == 0 && compiletest_force_stage0 ( ) {
1741+ // If we're forcing `--stage 0`, we should provide the bootstrap cargo.
1742+ builder. initial_cargo . clone ( )
1743+ } else {
1744+ // Unless we're forcing `--stage 0`, we need to properly build cargo using the
1745+ // suitable stage compiler.
1746+ builder. ensure ( tool:: Cargo { compiler, target : compiler. host } )
1747+ } ;
1748+
1749+ cmd. arg ( "--cargo-path" ) . arg ( cargo_path) ;
17351750 }
17361751
17371752 // Avoid depending on rustdoc when we don't need it.
@@ -2088,8 +2103,6 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
20882103 cmd. arg ( "--rustfix-coverage" ) ;
20892104 }
20902105
2091- cmd. env ( "BOOTSTRAP_CARGO" , & builder. initial_cargo ) ;
2092-
20932106 cmd. arg ( "--channel" ) . arg ( & builder. config . channel ) ;
20942107
20952108 if !builder. config . omit_git_hash {
0 commit comments