Skip to content

Commit 20bebfd

Browse files
Try fixing multiple std found error
1 parent 6961413 commit 20bebfd

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/librustdoc/doctest.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,11 @@ fn compile_merged_doctest_and_caller_binary(
568568
compiler_args: Vec<String>,
569569
test_code: &str,
570570
instant: Instant,
571-
is_compile_fail: bool,
571+
should_panic: bool,
572572
) -> Result<process::Output, (Duration, Result<(), RustdocResult>)> {
573573
// compile-fail tests never get merged, so this should always pass
574574
let output = child.wait_with_output().expect("Failed to wait");
575-
if is_compile_fail && !output.status.success() {
575+
if !output.status.success() {
576576
return Ok(output);
577577
}
578578

@@ -583,7 +583,7 @@ fn compile_merged_doctest_and_caller_binary(
583583
runner_compiler.env("RUSTC_BOOTSTRAP", "1");
584584
runner_compiler.args(compiler_args);
585585
runner_compiler.args(["--crate-type=bin", "-o"]).arg(output_file);
586-
let base_name = if is_compile_fail {
586+
let base_name = if should_panic {
587587
format!("rust_out")
588588
} else {
589589
format!("doctest_bundle_{edition}", edition = doctest.edition)
@@ -611,7 +611,12 @@ fn compile_merged_doctest_and_caller_binary(
611611
extern_path.push(&output_bundle_file);
612612
runner_compiler.arg(&extern_path);
613613

614-
if is_compile_fail {
614+
let sysroot = &rustdoc_options.sysroot;
615+
if let Some(explicit_sysroot) = &sysroot.explicit {
616+
runner_compiler.arg(format!("--sysroot={}", explicit_sysroot.display()));
617+
}
618+
619+
if should_panic {
615620
add_rustdoc_env_vars(&mut runner_compiler, doctest);
616621
runner_compiler.stderr(Stdio::piped());
617622
runner_compiler.stdin(Stdio::piped());
@@ -635,17 +640,13 @@ fn compile_merged_doctest_and_caller_binary(
635640
}
636641
debug!("compiler invocation for doctest runner: {runner_compiler:?}");
637642

638-
let output = if !output.status.success() {
639-
output
640-
} else {
641-
let mut child_runner = runner_compiler.spawn().expect("Failed to spawn rustc process");
642-
if is_compile_fail {
643-
let stdin = child_runner.stdin.as_mut().expect("Failed to open stdin");
644-
stdin.write_all(test_code.as_bytes()).expect("could write out test sources");
645-
}
646-
child_runner.wait_with_output().expect("Failed to wait")
647-
};
648-
if is_compile_fail {
643+
let mut child_runner = runner_compiler.spawn().expect("Failed to spawn rustc process");
644+
if should_panic {
645+
let stdin = child_runner.stdin.as_mut().expect("Failed to open stdin");
646+
stdin.write_all(test_code.as_bytes()).expect("could write out test sources");
647+
}
648+
let output = child_runner.wait_with_output().expect("Failed to wait");
649+
if should_panic {
649650
Ok(output)
650651
} else {
651652
Ok(process::Output { status: output.status, stdout: Vec::new(), stderr: Vec::new() })

0 commit comments

Comments
 (0)