refactor: remove unreachable match arms for tests/benches

To justify why it won't affect any existing behavior:

* For the default set of Cargo targets,
  test/bench targets would only be selected by `cargo test`,
  whose UserIntent will turn into `CompileMode::Test`,
  but never `CompileMode::Build`.

* For selective Cargo targets, i.e., `--tests`, or `--test`,
  Their `CompileMode` would either be `Check { test }` or `Test`.
  They will never be `Build`.
  See https://github.com/rust-lang/cargo/blob/bffece899e9/src/cargo/ops/cargo_compile/unit_generator.rs#L450-L465

According to these facts, there won't be a case that
bench/test targets get assigned to `CompileMode::Build`.
This commit is contained in:
Weihang Lo 2025-05-29 00:37:57 -04:00
parent bef07b2de1
commit 5fb96e85bc
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7

View File

@ -11,8 +11,8 @@ use crate::core::dependency::DepKind;
use crate::core::profiles::{Profiles, UnitFor};
use crate::core::resolver::features::{self, FeaturesFor};
use crate::core::resolver::{HasDevUnits, Resolve};
use crate::core::Workspace;
use crate::core::{FeatureValue, Package, PackageSet, Summary, Target};
use crate::core::{TargetKind, Workspace};
use crate::util::restricted_names::is_glob_pattern;
use crate::util::{closest_msg, CargoResult};
@ -84,11 +84,6 @@ impl<'a> UnitGenerator<'a, '_> {
CompileMode::Test
}
}
CompileMode::Build => match *target.kind() {
TargetKind::Test => CompileMode::Test,
TargetKind::Bench => CompileMode::Test,
_ => CompileMode::Build,
},
_ => initial_target_mode,
};