Skip to content

Commit a1780a7

Browse files
committed
Remove unnecessary test_kind field and TestKind struct
1 parent 39c6804 commit a1780a7

File tree

3 files changed

+27
-67
lines changed

3 files changed

+27
-67
lines changed

src/bootstrap/builder.rs

+8
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,14 @@ impl Kind {
634634
Kind::Suggest => "suggest",
635635
}
636636
}
637+
638+
pub fn test_description(&self) -> &'static str {
639+
match self {
640+
Kind::Test => "Testing",
641+
Kind::Bench => "Benchmarking",
642+
_ => panic!("not a test command: {}!", self.as_str()),
643+
}
644+
}
637645
}
638646

639647
impl<'a> Builder<'a> {

src/bootstrap/builder/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,6 @@ mod dist {
578578
compiler: Compiler { host, stage: 0 },
579579
target: host,
580580
mode: Mode::Std,
581-
test_kind: test::TestKind::Test,
582581
crates: vec![INTERNER.intern_str("std")],
583582
},]
584583
);

src/bootstrap/test.rs

+19-66
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
66
use std::env;
77
use std::ffi::OsString;
8-
use std::fmt;
98
use std::fs;
109
use std::iter;
1110
use std::path::{Path, PathBuf};
@@ -28,44 +27,6 @@ use crate::{envify, CLang, DocTests, GitRepo, Mode};
2827

2928
const ADB_TEST_DIR: &str = "/data/local/tmp/work";
3029

31-
/// The two modes of the test runner; tests or benchmarks.
32-
#[derive(Debug, PartialEq, Eq, Hash, Copy, Clone, PartialOrd, Ord)]
33-
pub enum TestKind {
34-
/// Run `cargo test`.
35-
Test,
36-
/// Run `cargo bench`.
37-
Bench,
38-
}
39-
40-
impl From<Kind> for TestKind {
41-
fn from(kind: Kind) -> Self {
42-
match kind {
43-
Kind::Test => TestKind::Test,
44-
Kind::Bench => TestKind::Bench,
45-
_ => panic!("unexpected kind in crate: {:?}", kind),
46-
}
47-
}
48-
}
49-
50-
impl TestKind {
51-
// Return the cargo subcommand for this test kind
52-
fn subcommand(self) -> &'static str {
53-
match self {
54-
TestKind::Test => "test",
55-
TestKind::Bench => "bench",
56-
}
57-
}
58-
}
59-
60-
impl fmt::Display for TestKind {
61-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
62-
f.write_str(match *self {
63-
TestKind::Test => "Testing",
64-
TestKind::Bench => "Benchmarking",
65-
})
66-
}
67-
}
68-
6930
fn try_run(builder: &Builder<'_>, cmd: &mut Command) -> bool {
7031
if !builder.fail_fast {
7132
if !builder.try_run(cmd) {
@@ -2105,7 +2066,6 @@ impl Step for RustcGuide {
21052066
pub struct CrateLibrustc {
21062067
compiler: Compiler,
21072068
target: TargetSelection,
2108-
test_kind: TestKind,
21092069
crates: Vec<Interned<String>>,
21102070
}
21112071

@@ -2127,17 +2087,15 @@ impl Step for CrateLibrustc {
21272087
.iter()
21282088
.map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
21292089
.collect();
2130-
let test_kind = builder.kind.into();
21312090

2132-
builder.ensure(CrateLibrustc { compiler, target: run.target, test_kind, crates });
2091+
builder.ensure(CrateLibrustc { compiler, target: run.target, crates });
21332092
}
21342093

21352094
fn run(self, builder: &Builder<'_>) {
21362095
builder.ensure(Crate {
21372096
compiler: self.compiler,
21382097
target: self.target,
21392098
mode: Mode::Rustc,
2140-
test_kind: self.test_kind,
21412099
crates: self.crates,
21422100
});
21432101
}
@@ -2148,7 +2106,6 @@ pub struct Crate {
21482106
pub compiler: Compiler,
21492107
pub target: TargetSelection,
21502108
pub mode: Mode,
2151-
pub test_kind: TestKind,
21522109
pub crates: Vec<Interned<String>>,
21532110
}
21542111

@@ -2164,14 +2121,13 @@ impl Step for Crate {
21642121
let builder = run.builder;
21652122
let host = run.build_triple();
21662123
let compiler = builder.compiler_for(builder.top_stage, host, host);
2167-
let test_kind = builder.kind.into();
21682124
let crates = run
21692125
.paths
21702126
.iter()
21712127
.map(|p| builder.crate_paths[&p.assert_single_path().path].clone())
21722128
.collect();
21732129

2174-
builder.ensure(Crate { compiler, target: run.target, mode: Mode::Std, test_kind, crates });
2130+
builder.ensure(Crate { compiler, target: run.target, mode: Mode::Std, crates });
21752131
}
21762132

21772133
/// Runs all unit tests plus documentation tests for a given crate defined
@@ -2186,7 +2142,6 @@ impl Step for Crate {
21862142
let compiler = self.compiler;
21872143
let target = self.target;
21882144
let mode = self.mode;
2189-
let test_kind = self.test_kind;
21902145

21912146
builder.ensure(compile::Std::new(compiler, target));
21922147
builder.ensure(RemoteCopyLibs { compiler, target });
@@ -2198,7 +2153,7 @@ impl Step for Crate {
21982153
let compiler = builder.compiler_for(compiler.stage, compiler.host, target);
21992154

22002155
let mut cargo =
2201-
builder.cargo(compiler, mode, SourceType::InTree, target, test_kind.subcommand());
2156+
builder.cargo(compiler, mode, SourceType::InTree, target, builder.kind.as_str());
22022157
match mode {
22032158
Mode::Std => {
22042159
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
@@ -2214,7 +2169,7 @@ impl Step for Crate {
22142169
// Pass in some standard flags then iterate over the graph we've discovered
22152170
// in `cargo metadata` with the maps above and figure out what `-p`
22162171
// arguments need to get passed.
2217-
if test_kind.subcommand() == "test" && !builder.fail_fast {
2172+
if builder.kind == Kind::Test && !builder.fail_fast {
22182173
cargo.arg("--no-fail-fast");
22192174
}
22202175
match builder.doc_tests {
@@ -2265,7 +2220,7 @@ impl Step for Crate {
22652220

22662221
builder.info(&format!(
22672222
"{}{} stage{} ({} -> {})",
2268-
test_kind,
2223+
builder.kind.test_description(),
22692224
crate_description(&self.crates),
22702225
compiler.stage,
22712226
&compiler.host,
@@ -2280,7 +2235,6 @@ impl Step for Crate {
22802235
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
22812236
pub struct CrateRustdoc {
22822237
host: TargetSelection,
2283-
test_kind: TestKind,
22842238
}
22852239

22862240
impl Step for CrateRustdoc {
@@ -2295,13 +2249,10 @@ impl Step for CrateRustdoc {
22952249
fn make_run(run: RunConfig<'_>) {
22962250
let builder = run.builder;
22972251

2298-
let test_kind = builder.kind.into();
2299-
2300-
builder.ensure(CrateRustdoc { host: run.target, test_kind });
2252+
builder.ensure(CrateRustdoc { host: run.target });
23012253
}
23022254

23032255
fn run(self, builder: &Builder<'_>) {
2304-
let test_kind = self.test_kind;
23052256
let target = self.host;
23062257

23072258
let compiler = if builder.download_rustc() {
@@ -2320,12 +2271,12 @@ impl Step for CrateRustdoc {
23202271
compiler,
23212272
Mode::ToolRustc,
23222273
target,
2323-
test_kind.subcommand(),
2274+
builder.kind.as_str(),
23242275
"src/tools/rustdoc",
23252276
SourceType::InTree,
23262277
&[],
23272278
);
2328-
if test_kind.subcommand() == "test" && !builder.fail_fast {
2279+
if builder.kind == Kind::Test && !builder.fail_fast {
23292280
cargo.arg("--no-fail-fast");
23302281
}
23312282
match builder.doc_tests {
@@ -2388,7 +2339,10 @@ impl Step for CrateRustdoc {
23882339

23892340
builder.info(&format!(
23902341
"{} rustdoc stage{} ({} -> {})",
2391-
test_kind, compiler.stage, &compiler.host, target
2342+
builder.kind.test_description(),
2343+
compiler.stage,
2344+
&compiler.host,
2345+
target
23922346
));
23932347
let _time = util::timeit(&builder);
23942348

@@ -2399,7 +2353,6 @@ impl Step for CrateRustdoc {
23992353
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
24002354
pub struct CrateRustdocJsonTypes {
24012355
host: TargetSelection,
2402-
test_kind: TestKind,
24032356
}
24042357

24052358
impl Step for CrateRustdocJsonTypes {
@@ -2414,13 +2367,10 @@ impl Step for CrateRustdocJsonTypes {
24142367
fn make_run(run: RunConfig<'_>) {
24152368
let builder = run.builder;
24162369

2417-
let test_kind = builder.kind.into();
2418-
2419-
builder.ensure(CrateRustdocJsonTypes { host: run.target, test_kind });
2370+
builder.ensure(CrateRustdocJsonTypes { host: run.target });
24202371
}
24212372

24222373
fn run(self, builder: &Builder<'_>) {
2423-
let test_kind = self.test_kind;
24242374
let target = self.host;
24252375

24262376
// Use the previous stage compiler to reuse the artifacts that are
@@ -2435,12 +2385,12 @@ impl Step for CrateRustdocJsonTypes {
24352385
compiler,
24362386
Mode::ToolRustc,
24372387
target,
2438-
test_kind.subcommand(),
2388+
builder.kind.as_str(),
24392389
"src/rustdoc-json-types",
24402390
SourceType::InTree,
24412391
&[],
24422392
);
2443-
if test_kind.subcommand() == "test" && !builder.fail_fast {
2393+
if builder.kind == Kind::Test && !builder.fail_fast {
24442394
cargo.arg("--no-fail-fast");
24452395
}
24462396

@@ -2455,7 +2405,10 @@ impl Step for CrateRustdocJsonTypes {
24552405

24562406
builder.info(&format!(
24572407
"{} rustdoc-json-types stage{} ({} -> {})",
2458-
test_kind, compiler.stage, &compiler.host, target
2408+
builder.kind.test_description(),
2409+
compiler.stage,
2410+
&compiler.host,
2411+
target
24592412
));
24602413
let _time = util::timeit(&builder);
24612414

0 commit comments

Comments
 (0)