Skip to content

Conversation

@GuillaumeGomez
Copy link
Member

Fixes bug reported in this comment.

r? @lolbinarycat

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Oct 20, 2025
@lolbinarycat
Copy link
Contributor

  1. I think we should include the path of the file we are trying to execute in the error
  2. (related) the message "failed to spawn rustc process" is a bit misleading, since (as far as I understand it) the entire point of this flag is you can pass an executable that isn't rustc, and such an error would likely cause an error to debug issues with rustc, instead of debugging their wrapper.

I think a message like "failed to spawn {compiler_path:?}: {error:?}" would be significantly more clear and helpful.

@GuillaumeGomez GuillaumeGomez force-pushed the graceful-doctest-error-handling branch from 4e0541a to 0c495ae Compare October 21, 2025 10:23
@GuillaumeGomez
Copy link
Member Author

Agreed, improved error messages.

@GuillaumeGomez GuillaumeGomez changed the title [rustdoc] Gracefully handle in case we cannot run the compiler in doctests [rustdoc] Gracefully handle error in case we cannot run the compiler in doctests Oct 22, 2025
@GuillaumeGomez
Copy link
Member Author

@lolbinarycat
Copy link
Contributor

I would prefer using Command::get_program instead of returning a tuple with duplicate data.

Alternatively, we could just throw the whole command into the error message through it's Debug impl, but that might be a bit noisy.

@GuillaumeGomez GuillaumeGomez force-pushed the graceful-doctest-error-handling branch from 0c495ae to ce42e06 Compare October 31, 2025 17:11
@GuillaumeGomez
Copy link
Member Author

Thanks, much better this way.

@@ -500,7 +501,7 @@ fn add_exe_suffix(input: String, target: &TargetTuple) -> String {
input + &exe_suffix
}

fn wrapped_rustc_command(rustc_wrappers: &[PathBuf], rustc_binary: &Path) -> Command {
fn wrapped_rustc_command<'a>(rustc_wrappers: &'a [PathBuf], rustc_binary: &'a Path) -> Command {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the explicit lifetime? leftover from when it returned a tuple?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oups indeed, removing that.

@@ -670,7 +671,14 @@ fn run_test(

debug!("compiler invocation for doctest: {compiler:?}");

let mut child = compiler.spawn().expect("Failed to spawn rustc process");
let binary_path = compiler.get_program().to_os_string();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to clone this, it's not like spawn consumes the command or holds a mutable borrow to it, so we just need to make sure we're calling get_program after spawn.

Copy link
Member Author

@GuillaumeGomez GuillaumeGomez Oct 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was sure spawn was taking self and not &mut self. Well, good to know. :)

Comment on lines 743 to 749
let binary_path = runner_compiler.get_program().to_os_string();
let mut child_runner = match runner_compiler.spawn() {
Ok(child) => child,
Err(error) => {
eprintln!("Failed to spawn {binary_path:?}: {error:?}");
return (Duration::default(), Err(TestFailure::CompileError));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let binary_path = runner_compiler.get_program().to_os_string();
let mut child_runner = match runner_compiler.spawn() {
Ok(child) => child,
Err(error) => {
eprintln!("Failed to spawn {binary_path:?}: {error:?}");
return (Duration::default(), Err(TestFailure::CompileError));
}
let mut child_runner = match runner_compiler.spawn() {
Ok(child) => child,
Err(error) => {
let binary_path = runner_compiler.get_program();
eprintln!("Failed to spawn {binary_path:?}: {error:?}");
return (Duration::default(), Err(TestFailure::CompileError));
}

as explained above

.arg("--test-builder")
.arg(&absolute_path)
.run_fail();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets also assert that the exit code is 1 (ICE gives 101, like other panics), seems more robust than string comparisons.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

panic! isn't always 101 as exit code (depends on the target). So we can't really check for that. ^^'

Discovered that while reading https://github.com/rust-lang/rust/blob/master/library/test/src/test_result.rs#L107.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, you can just stick it behind a cfg(unix) or something, it would still me more reliable than only looking at the strings.

Is normal error exit always 1? Because that's what I was reccomending we actually put in the assertion.

@GuillaumeGomez GuillaumeGomez force-pushed the graceful-doctest-error-handling branch from ce42e06 to 29fe476 Compare October 31, 2025 23:11
@rustbot
Copy link
Collaborator

rustbot commented Oct 31, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@GuillaumeGomez
Copy link
Member Author

Updated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

3 participants