Skip to content

Commit 611b086

Browse files
committed
Add must_use to msg_ functions
This caught several places which weren't waiting until the command finished to drop the Group. I also took the liberty of calling `msg_sysroot_tool` from `run_cargo_test` to reduce code duplication and make errors like this less likely in the future.
1 parent dd5797a commit 611b086

File tree

3 files changed

+67
-45
lines changed

3 files changed

+67
-45
lines changed

src/bootstrap/doc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ impl Step for TheBook {
222222
let shared_assets = builder.ensure(SharedAssets { target });
223223

224224
// build the redirect pages
225-
builder.msg_doc(compiler, "book redirect pages", target);
225+
let _guard = builder.msg_doc(compiler, "book redirect pages", target);
226226
for file in t!(fs::read_dir(builder.src.join(&relative_path).join("redirects"))) {
227227
let file = t!(file);
228228
let path = file.path();
@@ -306,7 +306,7 @@ impl Step for Standalone {
306306
fn run(self, builder: &Builder<'_>) {
307307
let target = self.target;
308308
let compiler = self.compiler;
309-
builder.msg_doc(compiler, "standalone", target);
309+
let _guard = builder.msg_doc(compiler, "standalone", target);
310310
let out = builder.doc_out(target);
311311
t!(fs::create_dir_all(&out));
312312

@@ -812,8 +812,6 @@ macro_rules! tool_doc {
812812
SourceType::Submodule
813813
};
814814

815-
builder.msg_doc(compiler, stringify!($tool).to_lowercase(), target);
816-
817815
// Symlink compiler docs to the output directory of rustdoc documentation.
818816
let out_dirs = [
819817
builder.stage_out(compiler, Mode::ToolRustc).join(target.triple).join("doc"),
@@ -852,6 +850,8 @@ macro_rules! tool_doc {
852850
cargo.rustdocflag("--show-type-layout");
853851
cargo.rustdocflag("--generate-link-to-definition");
854852
cargo.rustdocflag("-Zunstable-options");
853+
854+
let _guard = builder.msg_doc(compiler, stringify!($tool).to_lowercase(), target);
855855
builder.run(&mut cargo.into());
856856
}
857857
}

src/bootstrap/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ impl Build {
10041004
}
10051005
}
10061006

1007+
#[must_use = "Groups should not be dropped until the Step finishes running"]
10071008
fn msg_check(
10081009
&self,
10091010
what: impl Display,
@@ -1012,6 +1013,7 @@ impl Build {
10121013
self.msg(Kind::Check, self.config.stage, what, self.config.build, target)
10131014
}
10141015

1016+
#[must_use = "Groups should not be dropped until the Step finishes running"]
10151017
fn msg_doc(
10161018
&self,
10171019
compiler: Compiler,
@@ -1021,6 +1023,7 @@ impl Build {
10211023
self.msg(Kind::Doc, compiler.stage, what, compiler.host, target.into())
10221024
}
10231025

1026+
#[must_use = "Groups should not be dropped until the Step finishes running"]
10241027
fn msg_build(
10251028
&self,
10261029
compiler: Compiler,
@@ -1033,6 +1036,7 @@ impl Build {
10331036
/// Return a `Group` guard for a [`Step`] that is built for each `--stage`.
10341037
///
10351038
/// [`Step`]: crate::builder::Step
1039+
#[must_use = "Groups should not be dropped until the Step finishes running"]
10361040
fn msg(
10371041
&self,
10381042
action: impl Into<Kind>,
@@ -1059,6 +1063,7 @@ impl Build {
10591063
/// Return a `Group` guard for a [`Step`] that is only built once and isn't affected by `--stage`.
10601064
///
10611065
/// [`Step`]: crate::builder::Step
1066+
#[must_use = "Groups should not be dropped until the Step finishes running"]
10621067
fn msg_unstaged(
10631068
&self,
10641069
action: impl Into<Kind>,
@@ -1070,6 +1075,7 @@ impl Build {
10701075
self.group(&msg)
10711076
}
10721077

1078+
#[must_use = "Groups should not be dropped until the Step finishes running"]
10731079
fn msg_sysroot_tool(
10741080
&self,
10751081
action: impl Into<Kind>,

src/bootstrap/test.rs

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,8 @@ impl Step for CrateBootstrap {
117117
SourceType::InTree,
118118
&[],
119119
);
120-
let _group = builder.msg(Kind::Test, compiler.stage, path, compiler.host, bootstrap_host);
121120
let crate_name = path.rsplit_once('/').unwrap().1;
122-
run_cargo_test(cargo, &[], &[], crate_name, compiler, bootstrap_host, builder);
121+
run_cargo_test(cargo, &[], &[], crate_name, crate_name, compiler, bootstrap_host, builder);
123122
}
124123
}
125124

@@ -159,14 +158,6 @@ You can skip linkcheck with --exclude src/tools/linkchecker"
159158
let bootstrap_host = builder.config.build;
160159
let compiler = builder.compiler(0, bootstrap_host);
161160

162-
let self_test_group = builder.msg(
163-
Kind::Test,
164-
compiler.stage,
165-
"linkchecker self tests",
166-
bootstrap_host,
167-
bootstrap_host,
168-
);
169-
170161
let cargo = tool::prepare_tool_cargo(
171162
builder,
172163
compiler,
@@ -177,8 +168,16 @@ You can skip linkcheck with --exclude src/tools/linkchecker"
177168
SourceType::InTree,
178169
&[],
179170
);
180-
run_cargo_test(cargo, &[], &[], "linkchecker", compiler, bootstrap_host, builder);
181-
drop(self_test_group);
171+
run_cargo_test(
172+
cargo,
173+
&[],
174+
&[],
175+
"linkchecker",
176+
"linkchecker self tests",
177+
compiler,
178+
bootstrap_host,
179+
builder,
180+
);
182181

183182
if builder.doc_tests == DocTests::No {
184183
return;
@@ -415,8 +414,7 @@ impl Step for RustAnalyzer {
415414
cargo.env("SKIP_SLOW_TESTS", "1");
416415

417416
cargo.add_rustc_lib_path(builder, compiler);
418-
builder.msg_sysroot_tool(Kind::Test, compiler.stage, "rust-analyzer", host, host);
419-
run_cargo_test(cargo, &[], &[], "rust-analyzer", compiler, host, builder);
417+
run_cargo_test(cargo, &[], &[], "rust-analyzer", "rust-analyzer", compiler, host, builder);
420418
}
421419
}
422420

@@ -465,8 +463,7 @@ impl Step for Rustfmt {
465463

466464
cargo.add_rustc_lib_path(builder, compiler);
467465

468-
builder.msg_sysroot_tool(Kind::Test, compiler.stage, "rustfmt", host, host);
469-
run_cargo_test(cargo, &[], &[], "rustfmt", compiler, host, builder);
466+
run_cargo_test(cargo, &[], &[], "rustfmt", "rustfmt", compiler, host, builder);
470467
}
471468
}
472469

@@ -514,7 +511,16 @@ impl Step for RustDemangler {
514511
cargo.env("RUST_DEMANGLER_DRIVER_PATH", rust_demangler);
515512
cargo.add_rustc_lib_path(builder, compiler);
516513

517-
run_cargo_test(cargo, &[], &[], "rust-demangler", compiler, host, builder);
514+
run_cargo_test(
515+
cargo,
516+
&[],
517+
&[],
518+
"rust-demangler",
519+
"rust-demangler",
520+
compiler,
521+
host,
522+
builder,
523+
);
518524
}
519525
}
520526

@@ -756,7 +762,16 @@ impl Step for CompiletestTest {
756762
&[],
757763
);
758764
cargo.allow_features("test");
759-
run_cargo_test(cargo, &[], &[], "compiletest", compiler, host, builder);
765+
run_cargo_test(
766+
cargo,
767+
&[],
768+
&[],
769+
"compiletest",
770+
"compiletest self test",
771+
compiler,
772+
host,
773+
builder,
774+
);
760775
}
761776
}
762777

@@ -812,7 +827,7 @@ impl Step for Clippy {
812827
cargo.env("BLESS", "Gesundheit");
813828
}
814829

815-
builder.msg_sysroot_tool(Kind::Test, compiler.stage, "clippy", host, host);
830+
let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "clippy", host, host);
816831

817832
if builder.try_run(&mut cargo).is_ok() {
818833
// The tests succeeded; nothing to do.
@@ -2207,18 +2222,22 @@ impl Step for CrateLibrustc {
22072222
/// Given a `cargo test` subcommand, add the appropriate flags and run it.
22082223
///
22092224
/// Returns whether the test succeeded.
2210-
fn run_cargo_test(
2225+
fn run_cargo_test<'a>(
22112226
cargo: impl Into<Command>,
22122227
libtest_args: &[&str],
22132228
crates: &[Interned<String>],
22142229
primary_crate: &str,
2230+
description: impl Into<Option<&'a str>>,
22152231
compiler: Compiler,
22162232
target: TargetSelection,
22172233
builder: &Builder<'_>,
22182234
) -> bool {
22192235
let mut cargo =
22202236
prepare_cargo_test(cargo, libtest_args, crates, primary_crate, compiler, target, builder);
22212237
let _time = util::timeit(&builder);
2238+
let _group = description.into().and_then(|what| {
2239+
builder.msg_sysroot_tool(Kind::Test, compiler.stage, what, compiler.host, target)
2240+
});
22222241

22232242
#[cfg(feature = "build-metrics")]
22242243
builder.metrics.begin_test_suite(
@@ -2384,14 +2403,16 @@ impl Step for Crate {
23842403
_ => panic!("can only test libraries"),
23852404
};
23862405

2387-
let _guard = builder.msg(
2388-
builder.kind,
2389-
compiler.stage,
2390-
crate_description(&self.crates),
2391-
compiler.host,
2406+
run_cargo_test(
2407+
cargo,
2408+
&[],
2409+
&self.crates,
2410+
&self.crates[0],
2411+
&*crate_description(&self.crates),
2412+
compiler,
23922413
target,
2414+
builder,
23932415
);
2394-
run_cargo_test(cargo, &[], &self.crates, &self.crates[0], compiler, target, builder);
23952416
}
23962417
}
23972418

@@ -2484,18 +2505,12 @@ impl Step for CrateRustdoc {
24842505
dylib_path.insert(0, PathBuf::from(&*libdir));
24852506
cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
24862507

2487-
let _guard = builder.msg_sysroot_tool(
2488-
builder.kind,
2489-
compiler.stage,
2490-
"rustdoc",
2491-
compiler.host,
2492-
target,
2493-
);
24942508
run_cargo_test(
24952509
cargo,
24962510
&[],
24972511
&[INTERNER.intern_str("rustdoc:0.0.0")],
24982512
"rustdoc",
2513+
"rustdoc",
24992514
compiler,
25002515
target,
25012516
builder,
@@ -2551,13 +2566,12 @@ impl Step for CrateRustdocJsonTypes {
25512566
&[]
25522567
};
25532568

2554-
let _guard =
2555-
builder.msg(builder.kind, compiler.stage, "rustdoc-json-types", compiler.host, target);
25562569
run_cargo_test(
25572570
cargo,
25582571
libtest_args,
25592572
&[INTERNER.intern_str("rustdoc-json-types")],
25602573
"rustdoc-json-types",
2574+
"rustdoc-json-types",
25612575
compiler,
25622576
target,
25632577
builder,
@@ -2728,7 +2742,7 @@ impl Step for Bootstrap {
27282742
}
27292743
// rustbuild tests are racy on directory creation so just run them one at a time.
27302744
// Since there's not many this shouldn't be a problem.
2731-
run_cargo_test(cmd, &["--test-threads=1"], &[], "bootstrap", compiler, host, builder);
2745+
run_cargo_test(cmd, &["--test-threads=1"], &[], "bootstrap", None, compiler, host, builder);
27322746
}
27332747

27342748
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
@@ -2846,14 +2860,16 @@ impl Step for RustInstaller {
28462860
&[],
28472861
);
28482862

2849-
let _guard = builder.msg(
2850-
Kind::Test,
2851-
compiler.stage,
2863+
run_cargo_test(
2864+
cargo,
2865+
&[],
2866+
&[],
2867+
"installer",
28522868
"rust-installer",
2869+
compiler,
28532870
bootstrap_host,
2854-
bootstrap_host,
2871+
builder,
28552872
);
2856-
run_cargo_test(cargo, &[], &[], "installer", compiler, bootstrap_host, builder);
28572873

28582874
// We currently don't support running the test.sh script outside linux(?) environments.
28592875
// Eventually this should likely migrate to #[test]s in rust-installer proper rather than a

0 commit comments

Comments
 (0)