@@ -255,6 +255,13 @@ enum Emit {
255255 LinkArgsAsm ,
256256}
257257
258+ /// Indicates whether we are using `rustc` or `rustdoc` to compile an input file.
259+ #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
260+ enum CompilerKind {
261+ Rustc ,
262+ Rustdoc ,
263+ }
264+
258265impl < ' test > TestCx < ' test > {
259266 /// Code executed for each revision in turn (or, if there are no
260267 /// revisions, exactly once, with revision == None).
@@ -958,6 +965,8 @@ impl<'test> TestCx<'test> {
958965 local_pm : Option < PassMode > ,
959966 passes : Vec < String > ,
960967 ) -> ProcRes {
968+ let compiler_kind = self . compiler_kind_for_non_aux ( ) ;
969+
961970 // Only use `make_exe_name` when the test ends up being executed.
962971 let output_file = match will_execute {
963972 WillExecute :: Yes => TargetLocation :: ThisFile ( self . make_exe_name ( ) ) ,
@@ -973,7 +982,7 @@ impl<'test> TestCx<'test> {
973982 // want to actually assert warnings about all this code. Instead
974983 // let's just ignore unused code warnings by defaults and tests
975984 // can turn it back on if needed.
976- if ! self . is_rustdoc ( )
985+ if compiler_kind == CompilerKind :: Rustc
977986 // Note that we use the local pass mode here as we don't want
978987 // to set unused to allow if we've overridden the pass mode
979988 // via command line flags.
@@ -988,6 +997,7 @@ impl<'test> TestCx<'test> {
988997 } ;
989998
990999 let rustc = self . make_compile_args (
1000+ compiler_kind,
9911001 & self . testpaths . file ,
9921002 output_file,
9931003 emit,
@@ -1347,6 +1357,7 @@ impl<'test> TestCx<'test> {
13471357 fn build_minicore ( & self ) -> Utf8PathBuf {
13481358 let output_file_path = self . output_base_dir ( ) . join ( "libminicore.rlib" ) ;
13491359 let mut rustc = self . make_compile_args (
1360+ CompilerKind :: Rustc ,
13501361 & self . config . minicore_path ,
13511362 TargetLocation :: ThisFile ( output_file_path. clone ( ) ) ,
13521363 Emit :: None ,
@@ -1404,6 +1415,8 @@ impl<'test> TestCx<'test> {
14041415 // Create the directory for the stdout/stderr files.
14051416 create_dir_all ( aux_cx. output_base_dir ( ) ) . unwrap ( ) ;
14061417 let mut aux_rustc = aux_cx. make_compile_args (
1418+ // Always use `rustc` for aux crates, even in rustdoc tests.
1419+ CompilerKind :: Rustc ,
14071420 & aux_path,
14081421 aux_output,
14091422 Emit :: None ,
@@ -1554,28 +1567,54 @@ impl<'test> TestCx<'test> {
15541567 result
15551568 }
15561569
1557- fn is_rustdoc ( & self ) -> bool {
1558- matches ! (
1559- self . config. suite,
1560- TestSuite :: RustdocUi | TestSuite :: RustdocJs | TestSuite :: RustdocJson
1561- )
1570+ /// Choose a compiler kind (rustc or rustdoc) for compiling test files,
1571+ /// based on the test suite being tested.
1572+ fn compiler_kind_for_non_aux ( & self ) -> CompilerKind {
1573+ match self . config . suite {
1574+ TestSuite :: RustdocJs | TestSuite :: RustdocJson | TestSuite :: RustdocUi => {
1575+ CompilerKind :: Rustdoc
1576+ }
1577+
1578+ // Exhaustively match all other suites.
1579+ // Note that some suites never actually use this method, so the
1580+ // return value for those suites is not necessarily meaningful.
1581+ TestSuite :: AssemblyLlvm
1582+ | TestSuite :: BuildStd
1583+ | TestSuite :: CodegenLlvm
1584+ | TestSuite :: CodegenUnits
1585+ | TestSuite :: Coverage
1586+ | TestSuite :: CoverageRunRustdoc
1587+ | TestSuite :: Crashes
1588+ | TestSuite :: Debuginfo
1589+ | TestSuite :: Incremental
1590+ | TestSuite :: MirOpt
1591+ | TestSuite :: Pretty
1592+ | TestSuite :: RunMake
1593+ | TestSuite :: RunMakeCargo
1594+ | TestSuite :: RustdocGui
1595+ | TestSuite :: RustdocHtml
1596+ | TestSuite :: RustdocJsStd
1597+ | TestSuite :: Ui
1598+ | TestSuite :: UiFullDeps => CompilerKind :: Rustc ,
1599+ }
15621600 }
15631601
15641602 fn make_compile_args (
15651603 & self ,
1604+ compiler_kind : CompilerKind ,
15661605 input_file : & Utf8Path ,
15671606 output_file : TargetLocation ,
15681607 emit : Emit ,
15691608 allow_unused : AllowUnused ,
15701609 link_to_aux : LinkToAux ,
15711610 passes : Vec < String > , // Vec of passes under mir-opt test to be dumped
15721611 ) -> Command {
1573- let is_aux = input_file . components ( ) . map ( |c| c . as_os_str ( ) ) . any ( |c| c == "auxiliary" ) ;
1574- let is_rustdoc = self . is_rustdoc ( ) && !is_aux ;
1575- let mut rustc = if !is_rustdoc {
1576- Command :: new ( & self . config . rustc_path )
1577- } else {
1578- Command :: new ( & self . config . rustdoc_path . clone ( ) . expect ( "no rustdoc built yet" ) )
1612+ let is_rustdoc = compiler_kind == CompilerKind :: Rustdoc ;
1613+ let mut rustc = match compiler_kind {
1614+ CompilerKind :: Rustc => Command :: new ( & self . config . rustc_path ) ,
1615+ CompilerKind :: Rustdoc => {
1616+ Command :: new ( & self . config . rustdoc_path . clone ( ) . expect ( "no rustdoc built yet" ) )
1617+ }
15791618 } ;
15801619 rustc. arg ( input_file) ;
15811620
@@ -2127,6 +2166,7 @@ impl<'test> TestCx<'test> {
21272166 let output_path = self . output_base_name ( ) . with_extension ( "ll" ) ;
21282167 let input_file = & self . testpaths . file ;
21292168 let rustc = self . make_compile_args (
2169+ CompilerKind :: Rustc ,
21302170 input_file,
21312171 TargetLocation :: ThisFile ( output_path. clone ( ) ) ,
21322172 Emit :: LlvmIr ,
0 commit comments