Skip to content

Commit 2253941

Browse files
committed
Avoid a bool and use an Option of ZST instead
1 parent d746eee commit 2253941

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

tests/ui.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,16 @@ fn build_native_lib() -> PathBuf {
8181
native_lib_path
8282
}
8383

84+
struct WithDependencies {}
85+
8486
/// Does *not* set any args or env vars, since it is shared between the test runner and
8587
/// run_dep_mode.
86-
fn miri_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) -> Config {
88+
fn miri_config(
89+
target: &str,
90+
path: &str,
91+
mode: Mode,
92+
with_dependencies: Option<WithDependencies>,
93+
) -> Config {
8794
// Miri is rustc-like, so we create a default builder for rustc and modify it
8895
let mut program = CommandBuilder::rustc();
8996
program.program = miri_path();
@@ -118,7 +125,7 @@ fn miri_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) ->
118125
// keep in sync with `./miri run`
119126
config.comment_defaults.base().add_custom("edition", Edition("2021".into()));
120127

121-
if with_dependencies {
128+
if let Some(WithDependencies {}) = with_dependencies {
122129
config.comment_defaults.base().set_custom("dependencies", DependencyBuilder {
123130
program: CommandBuilder {
124131
// Set the `cargo-miri` binary, which we expect to be in the same folder as the `miri` binary.
@@ -145,7 +152,20 @@ fn run_tests(
145152
with_dependencies: bool,
146153
tmpdir: &Path,
147154
) -> Result<()> {
155+
// Handle command-line arguments.
156+
let mut args = ui_test::Args::test()?;
157+
args.bless |= env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0");
158+
159+
let with_dependencies = with_dependencies.then_some(WithDependencies {});
160+
148161
let mut config = miri_config(target, path, mode, with_dependencies);
162+
config.with_args(&args);
163+
config.bless_command = Some("./miri test --bless".into());
164+
165+
if env::var_os("MIRI_SKIP_UI_CHECKS").is_some() {
166+
assert!(!args.bless, "cannot use RUSTC_BLESS and MIRI_SKIP_UI_CHECKS at the same time");
167+
config.output_conflict_handling = OutputConflictHandling::Ignore;
168+
}
149169

150170
// Add a test env var to do environment communication tests.
151171
config.program.envs.push(("MIRI_ENV_VAR_TEST".into(), Some("0".into())));
@@ -181,16 +201,6 @@ fn run_tests(
181201
config.program.args.push(flag);
182202
}
183203

184-
// Handle command-line arguments.
185-
let mut args = ui_test::Args::test()?;
186-
args.bless |= env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0");
187-
config.with_args(&args);
188-
config.bless_command = Some("./miri test --bless".into());
189-
190-
if env::var_os("MIRI_SKIP_UI_CHECKS").is_some() {
191-
assert!(!args.bless, "cannot use RUSTC_BLESS and MIRI_SKIP_UI_CHECKS at the same time");
192-
config.output_conflict_handling = OutputConflictHandling::Ignore;
193-
}
194204
eprintln!(" Compiler: {}", config.program.display());
195205
ui_test::run_tests_generic(
196206
// Only run one test suite. In the future we can add all test suites to one `Vec` and run
@@ -326,7 +336,7 @@ fn main() -> Result<()> {
326336
}
327337

328338
fn run_dep_mode(target: String, args: impl Iterator<Item = OsString>) -> Result<()> {
329-
let mut config = miri_config(&target, "", Mode::RunDep, /* with dependencies */ true);
339+
let mut config = miri_config(&target, "", Mode::RunDep, Some(WithDependencies {}));
330340
config.comment_defaults.base().custom.remove("edition"); // `./miri` adds an `--edition` in `args`, so don't set it twice
331341
config.fill_host_and_target()?;
332342
config.program.args = args.collect();

0 commit comments

Comments
 (0)