Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8c58c10

Browse files
committedJun 3, 2024·
Auto merge of rust-lang#125752 - jieyouxu:kaboom, r=<try>
run-make: enforce `#[must_use]` and arm command wrappers with drop bombs This PR is one in a series of cleanups to run-make tests and the run-make-support library. ### Summary It's easy to forget to actually executed constructed command wrappers, e.g. `rustc().input("foo.rs")` but forget the `run()`, so to help catch these mistakes, we: - Add `#[must_use]` annotations to functions where suitable and compile rmake.rs recipes with `-Dunused_must_use`. - Arm command wrappers with drop bombs on construction to force them to be executed by test code. ### Details Especially for command wrappers like `Rustc`, it's very easy to build up a command invocation but forget to actually execute it, e.g. by using `run()`. This commit adds "drop bombs" to command wrappers, which are armed on command wrapper construction, and only defused if the command is executed (through `run`, `run_fail` or `run_fail_assert_exit_code`). If the test writer forgets to execute the command, the drop bomb will "explode" and panic with an error message. This is so that tests don't silently pass with constructed-but-not-executed command wrappers. We don't add `#[must_use]` for command wrapper helper methods because they return `&mut Self` and can be annoying e.g. if a helper method is conditionally called, such as ``` if condition { cmd.arg("-Cprefer-dynamic"); // <- unused_must_use fires } cmd.run(); // <- even though cmd is eventually executed ``` This PR is best reviewed commit-by-commit. Fixes rust-lang#125703. Because `command_output()` doesn't defuse the drop bomb, it also fixes rust-lang#125617. try-job: x86_64-msvc
2 parents 9f2d0b3 + ecb1c8b commit 8c58c10

File tree

19 files changed

+182
-85
lines changed

19 files changed

+182
-85
lines changed
 

‎src/tools/compiletest/src/runtest.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3530,6 +3530,10 @@ impl<'test> TestCx<'test> {
35303530
.env_remove("MFLAGS")
35313531
.env_remove("CARGO_MAKEFLAGS");
35323532

3533+
// In test code we want to be very pedantic about values being silently discarded that are
3534+
// annotated with `#[must_use]`.
3535+
cmd.arg("-Dunused_must_use");
3536+
35333537
if std::env::var_os("COMPILETEST_FORCE_STAGE0").is_some() {
35343538
let mut stage0_sysroot = build_root.clone();
35353539
stage0_sysroot.push("stage0-sysroot");

‎src/tools/run-make-support/src/cc.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::env;
22
use std::path::Path;
33
use std::process::Command;
44

5+
use crate::drop_bomb::DropBomb;
56
use crate::{bin_name, cygpath_windows, handle_failed_output, is_msvc, is_windows, tmp_dir, uname};
67

78
/// Construct a new platform-specific C compiler invocation.
@@ -14,9 +15,11 @@ pub fn cc() -> Cc {
1415

1516
/// A platform-specific C compiler invocation builder. The specific C compiler used is
1617
/// passed down from compiletest.
18+
#[must_use]
1719
#[derive(Debug)]
1820
pub struct Cc {
1921
cmd: Command,
22+
drop_bomb: DropBomb,
2023
}
2124

2225
crate::impl_common_helpers!(Cc);
@@ -36,7 +39,7 @@ impl Cc {
3639
cmd.arg(flag);
3740
}
3841

39-
Self { cmd }
42+
Self { cmd, drop_bomb: DropBomb::arm("cc invocation must be executed") }
4043
}
4144

4245
/// Specify path of the input file.
@@ -94,6 +97,7 @@ impl Cc {
9497
}
9598

9699
/// `EXTRACFLAGS`
100+
#[must_use]
97101
pub fn extra_c_flags() -> Vec<&'static str> {
98102
// Adapted from tools.mk (trimmed):
99103
//
@@ -152,6 +156,7 @@ pub fn extra_c_flags() -> Vec<&'static str> {
152156
}
153157

154158
/// `EXTRACXXFLAGS`
159+
#[must_use]
155160
pub fn extra_cxx_flags() -> Vec<&'static str> {
156161
// Adapted from tools.mk (trimmed):
157162
//

‎src/tools/run-make-support/src/clang.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::env;
22
use std::path::Path;
33
use std::process::Command;
44

5+
use crate::drop_bomb::DropBomb;
56
use crate::{bin_name, handle_failed_output, tmp_dir};
67

78
/// Construct a new `clang` invocation. `clang` is not always available for all targets.
@@ -10,62 +11,72 @@ pub fn clang() -> Clang {
1011
}
1112

1213
/// A `clang` invocation builder.
14+
#[must_use]
1315
#[derive(Debug)]
1416
pub struct Clang {
1517
cmd: Command,
18+
drop_bomb: DropBomb,
1619
}
1720

1821
crate::impl_common_helpers!(Clang);
1922

2023
impl Clang {
2124
/// Construct a new `clang` invocation. `clang` is not always available for all targets.
25+
#[must_use]
2226
pub fn new() -> Self {
2327
let clang =
2428
env::var("CLANG").expect("`CLANG` not specified, but this is required to find `clang`");
2529
let cmd = Command::new(clang);
26-
Self { cmd }
30+
Self { cmd, drop_bomb: DropBomb::arm("clang invocation must be executed") }
2731
}
2832

2933
/// Provide an input file.
34+
#[must_use]
3035
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
3136
self.cmd.arg(path.as_ref());
3237
self
3338
}
3439

3540
/// Specify the name of the executable. The executable will be placed under `$TMPDIR`, and the
3641
/// extension will be determined by [`bin_name`].
42+
#[must_use]
3743
pub fn out_exe(&mut self, name: &str) -> &mut Self {
3844
self.cmd.arg("-o");
3945
self.cmd.arg(tmp_dir().join(bin_name(name)));
4046
self
4147
}
4248

4349
/// Specify which target triple clang should target.
50+
#[must_use]
4451
pub fn target(&mut self, target_triple: &str) -> &mut Self {
4552
self.cmd.arg("-target");
4653
self.cmd.arg(target_triple);
4754
self
4855
}
4956

5057
/// Pass `-nostdlib` to disable linking the C standard library.
58+
#[must_use]
5159
pub fn no_stdlib(&mut self) -> &mut Self {
5260
self.cmd.arg("-nostdlib");
5361
self
5462
}
5563

5664
/// Specify architecture.
65+
#[must_use]
5766
pub fn arch(&mut self, arch: &str) -> &mut Self {
5867
self.cmd.arg(format!("-march={arch}"));
5968
self
6069
}
6170

6271
/// Specify LTO settings.
72+
#[must_use]
6373
pub fn lto(&mut self, lto: &str) -> &mut Self {
6474
self.cmd.arg(format!("-flto={lto}"));
6575
self
6676
}
6777

6878
/// Specify which ld to use.
79+
#[must_use]
6980
pub fn use_ld(&mut self, ld: &str) -> &mut Self {
7081
self.cmd.arg(format!("-fuse-ld={ld}"));
7182
self

‎src/tools/run-make-support/src/diff/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,37 @@ use regex::Regex;
22
use similar::TextDiff;
33
use std::path::Path;
44

5+
use crate::drop_bomb::DropBomb;
6+
57
#[cfg(test)]
68
mod tests;
79

810
pub fn diff() -> Diff {
911
Diff::new()
1012
}
1113

14+
#[must_use]
1215
#[derive(Debug)]
1316
pub struct Diff {
1417
expected: Option<String>,
1518
expected_name: Option<String>,
1619
actual: Option<String>,
1720
actual_name: Option<String>,
1821
normalizers: Vec<(String, String)>,
22+
drop_bomb: DropBomb,
1923
}
2024

2125
impl Diff {
2226
/// Construct a bare `diff` invocation.
27+
#[must_use]
2328
pub fn new() -> Self {
2429
Self {
2530
expected: None,
2631
expected_name: None,
2732
actual: None,
2833
actual_name: None,
2934
normalizers: Vec::new(),
35+
drop_bomb: DropBomb::arm("diff invocation must be executed"),
3036
}
3137
}
3238

@@ -79,9 +85,9 @@ impl Diff {
7985
self
8086
}
8187

82-
/// Executes the diff process, prints any differences to the standard error.
8388
#[track_caller]
84-
pub fn run(&self) {
89+
pub fn run(&mut self) {
90+
self.drop_bomb.defuse();
8591
let expected = self.expected.as_ref().expect("expected text not set");
8692
let mut actual = self.actual.as_ref().expect("actual text not set").to_string();
8793
let expected_name = self.expected_name.as_ref().unwrap();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//! This module implements "drop bombs" intended for use by command wrappers to ensure that the
2+
//! constructed commands are *eventually* executed. This is exactly like `rustc_errors::Diag`
3+
//! where we force every `Diag` to be consumed or we emit a bug, but we panic instead.
4+
//!
5+
//! This is inspired by <https://docs.rs/drop_bomb/latest/drop_bomb/>.
6+
7+
use std::borrow::Cow;
8+
9+
#[cfg(test)]
10+
mod tests;
11+
12+
#[derive(Debug)]
13+
pub(crate) struct DropBomb {
14+
msg: Cow<'static, str>,
15+
defused: bool,
16+
}
17+
18+
impl DropBomb {
19+
/// Arm a [`DropBomb`]. If the value is dropped without being [`defused`][Self::defused], then
20+
/// it will panic.
21+
pub(crate) fn arm<S: Into<Cow<'static, str>>>(message: S) -> DropBomb {
22+
DropBomb { msg: message.into(), defused: false }
23+
}
24+
25+
/// Defuse the [`DropBomb`]. This will prevent the drop bomb from panicking when dropped.
26+
pub(crate) fn defuse(&mut self) {
27+
self.defused = true;
28+
}
29+
}
30+
31+
impl Drop for DropBomb {
32+
fn drop(&mut self) {
33+
if !self.defused && !std::thread::panicking() {
34+
panic!("{}", self.msg)
35+
}
36+
}
37+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use super::DropBomb;
2+
3+
#[test]
4+
#[should_panic]
5+
fn test_arm() {
6+
let bomb = DropBomb::arm("hi :3");
7+
drop(bomb); // <- armed bomb should explode when not defused
8+
}
9+
10+
#[test]
11+
fn test_defuse() {
12+
let mut bomb = DropBomb::arm("hi :3");
13+
bomb.defuse();
14+
drop(bomb); // <- defused bomb should not explode
15+
}

‎src/tools/run-make-support/src/lib.rs

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
pub mod cc;
77
pub mod clang;
88
pub mod diff;
9+
mod drop_bomb;
910
pub mod llvm_readobj;
1011
pub mod run;
1112
pub mod rustc;
@@ -31,52 +32,62 @@ pub use rustc::{aux_build, rustc, Rustc};
3132
pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc};
3233

3334
/// Path of `TMPDIR` (a temporary build directory, not under `/tmp`).
35+
#[must_use]
3436
pub fn tmp_dir() -> PathBuf {
3537
env::var_os("TMPDIR").unwrap().into()
3638
}
3739

3840
/// `TARGET`
41+
#[must_use]
3942
pub fn target() -> String {
4043
env::var("TARGET").unwrap()
4144
}
4245

4346
/// Check if target is windows-like.
47+
#[must_use]
4448
pub fn is_windows() -> bool {
4549
target().contains("windows")
4650
}
4751

4852
/// Check if target uses msvc.
53+
#[must_use]
4954
pub fn is_msvc() -> bool {
5055
target().contains("msvc")
5156
}
5257

5358
/// Check if target uses macOS.
59+
#[must_use]
5460
pub fn is_darwin() -> bool {
5561
target().contains("darwin")
5662
}
5763

5864
/// Construct a path to a static library under `$TMPDIR` given the library name. This will return a
5965
/// path with `$TMPDIR` joined with platform-and-compiler-specific library name.
66+
#[must_use]
6067
pub fn static_lib(name: &str) -> PathBuf {
6168
tmp_dir().join(static_lib_name(name))
6269
}
6370

71+
#[must_use]
6472
pub fn python_command() -> Command {
6573
let python_path = std::env::var("PYTHON").expect("PYTHON environment variable does not exist");
6674
Command::new(python_path)
6775
}
6876

77+
#[must_use]
6978
pub fn htmldocck() -> Command {
7079
let mut python = python_command();
7180
python.arg(source_path().join("src/etc/htmldocck.py"));
7281
python
7382
}
7483

84+
#[must_use]
7585
pub fn source_path() -> PathBuf {
7686
std::env::var("S").expect("S variable does not exist").into()
7787
}
7888

7989
/// Construct the static library name based on the platform.
90+
#[must_use]
8091
pub fn static_lib_name(name: &str) -> String {
8192
// See tools.mk (irrelevant lines omitted):
8293
//
@@ -102,11 +113,13 @@ pub fn static_lib_name(name: &str) -> String {
102113

103114
/// Construct a path to a dynamic library under `$TMPDIR` given the library name. This will return a
104115
/// path with `$TMPDIR` joined with platform-and-compiler-specific library name.
116+
#[must_use]
105117
pub fn dynamic_lib(name: &str) -> PathBuf {
106118
tmp_dir().join(dynamic_lib_name(name))
107119
}
108120

109121
/// Construct the dynamic library name based on the platform.
122+
#[must_use]
110123
pub fn dynamic_lib_name(name: &str) -> String {
111124
// See tools.mk (irrelevant lines omitted):
112125
//
@@ -143,8 +156,9 @@ pub fn dynamic_lib_extension() -> &'static str {
143156
}
144157
}
145158

146-
/// Construct a path to a rust library (rlib) under `$TMPDIR` given the library name. This will return a
147-
/// path with `$TMPDIR` joined with the library name.
159+
/// Construct a path to a rust library (rlib) under `$TMPDIR` given the library name. This will
160+
/// return a path with `$TMPDIR` joined with the library name.
161+
#[must_use]
148162
pub fn rust_lib(name: &str) -> PathBuf {
149163
tmp_dir().join(rust_lib_name(name))
150164
}
@@ -156,12 +170,14 @@ pub fn rust_lib_name(name: &str) -> String {
156170
}
157171

158172
/// Construct the binary name based on platform.
173+
#[must_use]
159174
pub fn bin_name(name: &str) -> String {
160175
if is_windows() { format!("{name}.exe") } else { name.to_string() }
161176
}
162177

163178
/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
164179
/// available on the platform!
180+
#[must_use]
165181
#[track_caller]
166182
pub fn cygpath_windows<P: AsRef<Path>>(path: P) -> String {
167183
let caller_location = std::panic::Location::caller();
@@ -180,6 +196,7 @@ pub fn cygpath_windows<P: AsRef<Path>>(path: P) -> String {
180196
}
181197

182198
/// Run `uname`. This assumes that `uname` is available on the platform!
199+
#[must_use]
183200
#[track_caller]
184201
pub fn uname() -> String {
185202
let caller_location = std::panic::Location::caller();
@@ -299,19 +316,21 @@ pub fn assert_not_contains(haystack: &str, needle: &str) {
299316
}
300317
}
301318

319+
// FIXME(jieyouxu): convert this macro to become a command wrapper trait.
302320
/// Implement common helpers for command wrappers. This assumes that the command wrapper is a struct
303-
/// containing a `cmd: Command` field and a `output` function. The provided helpers are:
321+
/// containing a `cmd: Command` field, a `command_output()` function, and a `drop_bomb` field. The
322+
/// provided helpers can be grouped into a few categories:
304323
///
305324
/// 1. Generic argument acceptors: `arg` and `args` (delegated to [`Command`]). These are intended
306325
/// to be *fallback* argument acceptors, when specific helpers don't make sense. Prefer to add
307326
/// new specific helper methods over relying on these generic argument providers.
308327
/// 2. Environment manipulation methods: `env`, `env_remove` and `env_clear`: these delegate to
309328
/// methods of the same name on [`Command`].
310-
/// 3. Output and execution: `output`, `run` and `run_fail` are provided. `output` waits for the
311-
/// command to finish running and returns the process's [`Output`]. `run` and `run_fail` are
312-
/// higher-level convenience methods which waits for the command to finish running and assert
313-
/// that the command successfully ran or failed as expected. Prefer `run` and `run_fail` when
314-
/// possible.
329+
/// 3. Output and execution: `run`, `run_fail` and `run_fail_assert_exit_code` are provided. `run*`
330+
/// are higher-level convenience methods which waits for the command to finish running and assert
331+
/// that the command successfully ran or failed as expected.
332+
///
333+
/// `command_output()` should almost never be used in test code.
315334
///
316335
/// Example usage:
317336
///
@@ -392,9 +411,16 @@ macro_rules! impl_common_helpers {
392411
self
393412
}
394413

414+
/// Set the path where the command will be run.
415+
pub fn current_dir<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
416+
self.cmd.current_dir(path);
417+
self
418+
}
419+
395420
/// Run the constructed command and assert that it is successfully run.
396421
#[track_caller]
397422
pub fn run(&mut self) -> ::std::process::Output {
423+
self.drop_bomb.defuse();
398424
let caller_location = ::std::panic::Location::caller();
399425
let caller_line_number = caller_location.line();
400426

@@ -408,6 +434,7 @@ macro_rules! impl_common_helpers {
408434
/// Run the constructed command and assert that it does not successfully run.
409435
#[track_caller]
410436
pub fn run_fail(&mut self) -> ::std::process::Output {
437+
self.drop_bomb.defuse();
411438
let caller_location = ::std::panic::Location::caller();
412439
let caller_line_number = caller_location.line();
413440

@@ -418,10 +445,20 @@ macro_rules! impl_common_helpers {
418445
output
419446
}
420447

421-
/// Set the path where the command will be run.
422-
pub fn current_dir<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
423-
self.cmd.current_dir(path);
424-
self
448+
/// Run the constructed command and assert that it does not successfully run and
449+
/// exits with the expected exit code.
450+
// FIXME(jieyouxu): we should probably *always* assert the expected exit code?
451+
#[track_caller]
452+
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> ::std::process::Output {
453+
self.drop_bomb.defuse();
454+
let caller_location = ::std::panic::Location::caller();
455+
let caller_line_number = caller_location.line();
456+
457+
let output = self.command_output();
458+
if output.status.code().unwrap() != code {
459+
handle_failed_output(&self.cmd, output, caller_line_number);
460+
}
461+
output
425462
}
426463
}
427464
};

‎src/tools/run-make-support/src/llvm_readobj.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::env;
22
use std::path::{Path, PathBuf};
33
use std::process::Command;
44

5+
use crate::drop_bomb::DropBomb;
56
use crate::handle_failed_output;
67

78
/// Construct a new `llvm-readobj` invocation. This assumes that `llvm-readobj` is available
@@ -11,9 +12,11 @@ pub fn llvm_readobj() -> LlvmReadobj {
1112
}
1213

1314
/// A `llvm-readobj` invocation builder.
15+
#[must_use]
1416
#[derive(Debug)]
1517
pub struct LlvmReadobj {
1618
cmd: Command,
19+
drop_bomb: DropBomb,
1720
}
1821

1922
crate::impl_common_helpers!(LlvmReadobj);
@@ -27,7 +30,7 @@ impl LlvmReadobj {
2730
let llvm_bin_dir = PathBuf::from(llvm_bin_dir);
2831
let llvm_readobj = llvm_bin_dir.join("llvm-readobj");
2932
let cmd = Command::new(llvm_readobj);
30-
Self { cmd }
33+
Self { cmd, drop_bomb: DropBomb::arm("llvm-readobj invocation must be executed") }
3134
}
3235

3336
/// Provide an input file.

‎src/tools/run-make-support/src/rustc.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::io::Write;
44
use std::path::Path;
55
use std::process::{Command, Output, Stdio};
66

7+
use crate::drop_bomb::DropBomb;
78
use crate::{handle_failed_output, set_host_rpath, tmp_dir};
89

910
/// Construct a new `rustc` invocation.
@@ -17,36 +18,39 @@ pub fn aux_build() -> Rustc {
1718
}
1819

1920
/// A `rustc` invocation builder.
21+
#[must_use]
2022
#[derive(Debug)]
2123
pub struct Rustc {
2224
cmd: Command,
2325
stdin: Option<Box<[u8]>>,
26+
drop_bomb: DropBomb,
2427
}
2528

2629
crate::impl_common_helpers!(Rustc);
2730

28-
fn setup_common() -> Command {
31+
fn setup_common() -> (Command, DropBomb) {
2932
let rustc = env::var("RUSTC").unwrap();
3033
let mut cmd = Command::new(rustc);
3134
set_host_rpath(&mut cmd);
3235
cmd.arg("--out-dir").arg(tmp_dir()).arg("-L").arg(tmp_dir());
33-
cmd
36+
let drop_bomb = DropBomb::arm("rustc invocation must be executed");
37+
(cmd, drop_bomb)
3438
}
3539

3640
impl Rustc {
3741
// `rustc` invocation constructor methods
3842

3943
/// Construct a new `rustc` invocation.
4044
pub fn new() -> Self {
41-
let cmd = setup_common();
42-
Self { cmd, stdin: None }
45+
let (cmd, drop_bomb) = setup_common();
46+
Self { cmd, stdin: None, drop_bomb }
4347
}
4448

4549
/// Construct a new `rustc` invocation with `aux_build` preset (setting `--crate-type=lib`).
4650
pub fn new_aux_build() -> Self {
47-
let mut cmd = setup_common();
51+
let (mut cmd, drop_bomb) = setup_common();
4852
cmd.arg("--crate-type=lib");
49-
Self { cmd, stdin: None }
53+
Self { cmd, stdin: None, drop_bomb }
5054
}
5155

5256
// Argument provider methods
@@ -230,16 +234,4 @@ impl Rustc {
230234
self.cmd.output().expect("failed to get output of finished process")
231235
}
232236
}
233-
234-
#[track_caller]
235-
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
236-
let caller_location = std::panic::Location::caller();
237-
let caller_line_number = caller_location.line();
238-
239-
let output = self.command_output();
240-
if output.status.code().unwrap() != code {
241-
handle_failed_output(&self.cmd, output, caller_line_number);
242-
}
243-
output
244-
}
245237
}

‎src/tools/run-make-support/src/rustdoc.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::io::Write;
44
use std::path::Path;
55
use std::process::{Command, Output, Stdio};
66

7+
use crate::drop_bomb::DropBomb;
78
use crate::{handle_failed_output, set_host_rpath};
89

910
/// Construct a plain `rustdoc` invocation with no flags set.
@@ -16,34 +17,36 @@ pub fn rustdoc() -> Rustdoc {
1617
Rustdoc::new()
1718
}
1819

20+
#[must_use]
1921
#[derive(Debug)]
2022
pub struct Rustdoc {
2123
cmd: Command,
2224
stdin: Option<Box<[u8]>>,
25+
drop_bomb: DropBomb,
2326
}
2427

2528
crate::impl_common_helpers!(Rustdoc);
2629

27-
fn setup_common() -> Command {
30+
fn setup_common() -> (Command, DropBomb) {
2831
let rustdoc = env::var("RUSTDOC").unwrap();
2932
let mut cmd = Command::new(rustdoc);
3033
set_host_rpath(&mut cmd);
31-
cmd
34+
(cmd, DropBomb::arm("rustdoc invocation must be executed"))
3235
}
3336

3437
impl Rustdoc {
3538
/// Construct a bare `rustdoc` invocation.
3639
pub fn bare() -> Self {
37-
let cmd = setup_common();
38-
Self { cmd, stdin: None }
40+
let (cmd, drop_bomb) = setup_common();
41+
Self { cmd, stdin: None, drop_bomb }
3942
}
4043

4144
/// Construct a `rustdoc` invocation with `-L $(TARGET_RPATH_DIR)` set.
4245
pub fn new() -> Self {
43-
let mut cmd = setup_common();
46+
let (mut cmd, drop_bomb) = setup_common();
4447
let target_rpath_dir = env::var_os("TARGET_RPATH_DIR").unwrap();
4548
cmd.arg(format!("-L{}", target_rpath_dir.to_string_lossy()));
46-
Self { cmd, stdin: None }
49+
Self { cmd, stdin: None, drop_bomb }
4750
}
4851

4952
/// Specify where an external library is located.
@@ -96,7 +99,7 @@ impl Rustdoc {
9699

97100
/// Get the [`Output`] of the finished process.
98101
#[track_caller]
99-
pub fn command_output(&mut self) -> ::std::process::Output {
102+
pub fn command_output(&mut self) -> Output {
100103
// let's make sure we piped all the input and outputs
101104
self.cmd.stdin(Stdio::piped());
102105
self.cmd.stdout(Stdio::piped());
@@ -157,16 +160,4 @@ impl Rustdoc {
157160
self.cmd.arg(format);
158161
self
159162
}
160-
161-
#[track_caller]
162-
pub fn run_fail_assert_exit_code(&mut self, code: i32) -> Output {
163-
let caller_location = std::panic::Location::caller();
164-
let caller_line_number = caller_location.line();
165-
166-
let output = self.command_output();
167-
if output.status.code().unwrap() != code {
168-
handle_failed_output(&self.cmd, output, caller_line_number);
169-
}
170-
output
171-
}
172163
}

‎tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ fn main() {
1313
let mut stable_path = PathBuf::from(env!("TMPDIR"));
1414
stable_path.push("libstable.rmeta");
1515

16-
let output =
17-
rustc().input("main.rs").emit("metadata").extern_("stable", &stable_path).command_output();
16+
let output = rustc().input("main.rs").emit("metadata").extern_("stable", &stable_path).run();
1817

1918
let stderr = String::from_utf8_lossy(&output.stderr);
2019
let version = include_str!(concat!(env!("S"), "/src/version"));

‎tests/run-make/c-link-to-rust-staticlib/rmake.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ fn main() {
1010
rustc().input("foo.rs").run();
1111
cc().input("bar.c").input(static_lib("foo")).out_exe("bar").args(&extra_c_flags()).run();
1212
run("bar");
13-
fs::remove_file(static_lib("foo"));
13+
fs::remove_file(static_lib("foo")).unwrap();
1414
run("bar");
1515
}

‎tests/run-make/doctests-keep-binaries/rmake.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn setup_test_env<F: FnOnce(&Path, &Path)>(callback: F) {
1010
create_dir(&out_dir).expect("failed to create doctests folder");
1111
rustc().input("t.rs").crate_type("rlib").run();
1212
callback(&out_dir, &tmp_dir().join("libt.rlib"));
13-
remove_dir_all(out_dir);
13+
remove_dir_all(out_dir).unwrap();
1414
}
1515

1616
fn check_generated_binaries() {
@@ -60,6 +60,6 @@ fn main() {
6060
.extern_("t", "libt.rlib")
6161
.run();
6262

63-
remove_dir_all(run_dir_path);
63+
remove_dir_all(run_dir_path).unwrap();
6464
});
6565
}

‎tests/run-make/doctests-runtool/rmake.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ fn main() {
3333
.current_dir(tmp_dir())
3434
.run();
3535

36-
remove_dir_all(run_dir);
37-
remove_dir_all(run_tool);
36+
remove_dir_all(run_dir).unwrap();
37+
remove_dir_all(run_tool).unwrap();
3838
}

‎tests/run-make/reset-codegen-1/rmake.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ fn main() {
3131
("multi-output", Some("asm,obj")),
3232
];
3333
for (output_file, emit) in flags {
34-
fs::remove_file(output_file).unwrap_or_default();
34+
fs::remove_dir_all(tmp_dir()).unwrap_or_default();
35+
fs::create_dir_all(tmp_dir()).unwrap();
3536
compile(output_file, emit);
36-
fs::remove_file(output_file);
37+
fs::remove_dir_all(tmp_dir()).unwrap();
3738
}
3839
}

‎tests/run-make/rustdoc-error-lines/rmake.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
use run_make_support::rustdoc;
55

66
fn main() {
7-
let output =
8-
String::from_utf8(rustdoc().input("input.rs").arg("--test").command_output().stdout)
9-
.unwrap();
7+
let output = rustdoc().input("input.rs").arg("--test").run_fail();
8+
let output = String::from_utf8(output.stdout).unwrap();
109

1110
let should_contain = &[
1211
"input.rs - foo (line 5)",

‎tests/run-make/rustdoc-scrape-examples-macros/rmake.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,14 @@ fn main() {
99
let proc_crate_name = "foobar_macro";
1010
let crate_name = "foobar";
1111

12-
let dylib_name = String::from_utf8(
13-
rustc()
14-
.crate_name(proc_crate_name)
15-
.crate_type("dylib")
16-
.arg("--print")
17-
.arg("file-names")
18-
.arg("-")
19-
.command_output()
20-
.stdout,
21-
)
22-
.unwrap();
12+
let output = rustc()
13+
.crate_name(proc_crate_name)
14+
.crate_type("dylib")
15+
.arg("--print")
16+
.arg("file-names")
17+
.arg("-")
18+
.run();
19+
let dylib_name = String::from_utf8(output.stdout).unwrap();
2320

2421
rustc()
2522
.input("src/proc.rs")

‎tests/run-make/rustdoc-shared-flags/rmake.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use run_make_support::{rustc, rustdoc, Diff};
22

33
fn compare_outputs(args: &[&str]) {
4-
let rustc_output = String::from_utf8(rustc().args(args).command_output().stdout).unwrap();
5-
let rustdoc_output = String::from_utf8(rustdoc().args(args).command_output().stdout).unwrap();
4+
let rustc_output = String::from_utf8(rustc().args(args).run().stdout).unwrap();
5+
let rustdoc_output = String::from_utf8(rustdoc().args(args).run().stdout).unwrap();
66

77
Diff::new().expected_text("rustc", rustc_output).actual_text("rustdoc", rustdoc_output).run();
88
}

‎tests/run-make/same-lib-two-locations-no-panic/rmake.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@
77

88
//@ ignore-cross-compile
99

10-
use run_make_support::{dynamic_lib, rust_lib, rustc, tmp_dir};
10+
use run_make_support::{dynamic_lib, dynamic_lib_name, rust_lib, rust_lib_name, rustc, tmp_dir};
1111
use std::fs;
1212

1313
fn main() {
1414
let tmp_dir_other = tmp_dir().join("other");
1515

16-
fs::create_dir(&tmp_dir_other);
16+
fs::create_dir(&tmp_dir_other).unwrap();
1717
rustc().input("foo.rs").crate_type("dylib").arg("-Cprefer-dynamic").run();
18-
fs::rename(dynamic_lib("foo"), &tmp_dir_other);
18+
fs::rename(dynamic_lib("foo"), tmp_dir_other.join(dynamic_lib_name("foo"))).unwrap();
1919
rustc().input("foo.rs").crate_type("dylib").arg("-Cprefer-dynamic").run();
2020
rustc().input("bar.rs").library_search_path(&tmp_dir_other).run();
21-
fs::remove_dir_all(tmp_dir());
21+
fs::remove_dir_all(tmp_dir()).unwrap();
2222

23-
fs::create_dir_all(&tmp_dir_other);
23+
fs::create_dir_all(&tmp_dir_other).unwrap();
2424
rustc().input("foo.rs").crate_type("rlib").run();
25-
fs::rename(rust_lib("foo"), &tmp_dir_other);
25+
fs::rename(rust_lib("foo"), tmp_dir_other.join(rust_lib_name("foo"))).unwrap();
2626
rustc().input("foo.rs").crate_type("rlib").run();
2727
rustc().input("bar.rs").library_search_path(tmp_dir_other).run();
2828
}

0 commit comments

Comments
 (0)
This repository has been archived.