Skip to content

Commit 2fc7e6e

Browse files
committed
refactor: remove unsed Bench mode
The purpose of it was for indicating old "global mode". There should be no difference between building a test or a bench, as we already coerce Bench to Test: https://github.com/rust-lang/cargo/blob/6ffc01f9fa7aa50d0/src/cargo/ops/cargo_compile/unit_generator.rs#L91-L99 The the removal of serialization for `CompileMode::Bench` affects nothing because it was never really constructed.
1 parent 2bab011 commit 2fc7e6e

File tree

6 files changed

+9
-43
lines changed

6 files changed

+9
-43
lines changed

src/cargo/core/compiler/build_config.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,6 @@ pub enum CompileMode {
175175
/// If `test` is true, then it is also compiled with `--test` to check it like
176176
/// a test.
177177
Check { test: bool },
178-
/// Used to indicate benchmarks should be built. This is not used in
179-
/// `Unit`, because it is essentially the same as `Test` (indicating
180-
/// `--test` should be passed to rustc) and by using `Test` instead it
181-
/// allows some de-duping of Units to occur.
182-
Bench,
183178
/// Document with `rustdoc`.
184179
///
185180
/// If `deps` is true, then it will also document all dependencies.
@@ -203,7 +198,6 @@ impl ser::Serialize for CompileMode {
203198
Test => "test".serialize(s),
204199
Build => "build".serialize(s),
205200
Check { .. } => "check".serialize(s),
206-
Bench => "bench".serialize(s),
207201
Doc { .. } => "doc".serialize(s),
208202
Doctest => "doctest".serialize(s),
209203
Docscrape => "docscrape".serialize(s),
@@ -238,19 +232,13 @@ impl CompileMode {
238232
pub fn is_any_test(self) -> bool {
239233
matches!(
240234
self,
241-
CompileMode::Test
242-
| CompileMode::Bench
243-
| CompileMode::Check { test: true }
244-
| CompileMode::Doctest
235+
CompileMode::Test | CompileMode::Check { test: true } | CompileMode::Doctest
245236
)
246237
}
247238

248239
/// Returns `true` if this is something that passes `--test` to rustc.
249240
pub fn is_rustc_test(self) -> bool {
250-
matches!(
251-
self,
252-
CompileMode::Test | CompileMode::Bench | CompileMode::Check { test: true }
253-
)
241+
matches!(self, CompileMode::Test | CompileMode::Check { test: true })
254242
}
255243

256244
/// Returns `true` if this is the *execution* of a `build.rs` script.
@@ -263,10 +251,7 @@ impl CompileMode {
263251
/// Note that this also returns `true` for building libraries, so you also
264252
/// have to check the target.
265253
pub fn generates_executable(self) -> bool {
266-
matches!(
267-
self,
268-
CompileMode::Test | CompileMode::Bench | CompileMode::Build
269-
)
254+
matches!(self, CompileMode::Test | CompileMode::Build)
270255
}
271256
}
272257

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ impl TargetInfo {
574574
) -> CargoResult<(Vec<FileType>, Vec<CrateType>)> {
575575
match mode {
576576
CompileMode::Build => self.calc_rustc_outputs(target_kind, target_triple, gctx),
577-
CompileMode::Test | CompileMode::Bench => {
577+
CompileMode::Test => {
578578
match self.file_types(&CrateType::Bin, FileFlavor::Normal, target_triple)? {
579579
Some(fts) => Ok((fts, Vec::new())),
580580
None => Ok((Vec::new(), vec![CrateType::Bin])),

src/cargo/core/compiler/build_runner/compilation_files.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,7 @@ impl<'a, 'gctx: 'a> CompilationFiles<'a, 'gctx> {
493493
flavor: FileFlavor::Normal,
494494
}]
495495
}
496-
CompileMode::Test
497-
| CompileMode::Build
498-
| CompileMode::Bench
499-
| CompileMode::Check { .. } => {
496+
CompileMode::Test | CompileMode::Build | CompileMode::Check { .. } => {
500497
let mut outputs = self.calc_outputs_rustc(unit, bcx)?;
501498
if bcx.build_config.sbom && bcx.gctx.cli_unstable().sbom {
502499
let sbom_files: Vec<_> = outputs

src/cargo/core/compiler/lto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn calculate(
9797
let crate_types = match unit.mode {
9898
// Note: Doctest ignores LTO, but for now we'll compute it as-if it is
9999
// a Bin, in case it is ever supported in the future.
100-
CompileMode::Test | CompileMode::Bench | CompileMode::Doctest => vec![CrateType::Bin],
100+
CompileMode::Test | CompileMode::Doctest => vec![CrateType::Bin],
101101
// Notes on other modes:
102102
// - Check: Treat as the underlying type, it doesn't really matter.
103103
// - Doc: LTO is N/A for the Doc unit itself since rustdoc does not

src/cargo/core/compiler/timings.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ impl<'gctx> Timings<'gctx> {
168168
CompileMode::Build => {}
169169
CompileMode::Check { test: true } => target.push_str(" (check-test)"),
170170
CompileMode::Check { test: false } => target.push_str(" (check)"),
171-
CompileMode::Bench => target.push_str(" (bench)"),
172171
CompileMode::Doc { .. } => target.push_str(" (doc)"),
173172
CompileMode::Doctest => target.push_str(" (doc test)"),
174173
CompileMode::Docscrape => target.push_str(" (doc scrape)"),

src/cargo/ops/cargo_compile/unit_generator.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,9 @@ impl<'a> UnitGenerator<'a, '_> {
8686
}
8787
CompileMode::Build => match *target.kind() {
8888
TargetKind::Test => CompileMode::Test,
89-
TargetKind::Bench => CompileMode::Bench,
89+
TargetKind::Bench => CompileMode::Test,
9090
_ => CompileMode::Build,
9191
},
92-
// `CompileMode::Bench` is only used to inform `filter_default_targets`
93-
// which command is being used (`cargo bench`). Afterwards, tests
94-
// and benches are treated identically. Switching the mode allows
95-
// de-duplication of units that are essentially identical. For
96-
// example, `cargo build --all-targets --release` creates the units
97-
// (lib profile:bench, mode:test) and (lib profile:bench, mode:bench)
98-
// and since these are the same, we want them to be de-duplicated in
99-
// `unit_dependencies`.
100-
CompileMode::Bench => CompileMode::Test,
10192
_ => initial_target_mode,
10293
};
10394

@@ -476,11 +467,6 @@ impl<'a> UnitGenerator<'a, '_> {
476467
FilterRule::All => Target::benched,
477468
FilterRule::Just(_) => Target::is_bench,
478469
};
479-
let bench_mode = match self.intent {
480-
UserIntent::Build => CompileMode::Bench,
481-
UserIntent::Check { .. } => CompileMode::Check { test: true },
482-
_ => default_mode,
483-
};
484470

485471
proposals.extend(self.list_rule_targets(
486472
bins,
@@ -499,7 +485,7 @@ impl<'a> UnitGenerator<'a, '_> {
499485
benches,
500486
"bench",
501487
bench_filter,
502-
bench_mode,
488+
test_mode,
503489
)?);
504490
}
505491
}
@@ -792,8 +778,7 @@ Rustdoc did not scrape the following examples because they require dev-dependenc
792778
/// Converts [`UserIntent`] to [`CompileMode`] for root units.
793779
fn to_compile_mode(intent: UserIntent) -> CompileMode {
794780
match intent {
795-
UserIntent::Test => CompileMode::Test,
796-
UserIntent::Bench => CompileMode::Bench,
781+
UserIntent::Test | UserIntent::Bench => CompileMode::Test,
797782
UserIntent::Build => CompileMode::Build,
798783
UserIntent::Check { test } => CompileMode::Check { test },
799784
UserIntent::Doc { deps, json } => CompileMode::Doc { deps, json },

0 commit comments

Comments
 (0)