diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index e142d831fe4..ff71d0b1aa9 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -1,6 +1,6 @@ use std::ffi::OsString; -use crate::core::compiler::{Compilation, Doctest}; +use crate::core::compiler::{Compilation, CompileKind, Doctest}; use crate::core::shell::Verbosity; use crate::core::Workspace; use crate::ops; @@ -163,7 +163,10 @@ fn run_doc_tests( .arg(&target.crate_name()); if doctest_xcompile { - p.arg("--target").arg(&compilation.target); + if let CompileKind::Target(target) = options.compile_opts.build_config.requested_kind { + // use `rustc_target()` to properly handle JSON target paths + p.arg("--target").arg(target.rustc_target()); + } p.arg("-Zunstable-options"); p.arg("--enable-per-target-ignores"); } diff --git a/tests/testsuite/custom_target.rs b/tests/testsuite/custom_target.rs index 3970bc8d43f..75aba8a9976 100644 --- a/tests/testsuite/custom_target.rs +++ b/tests/testsuite/custom_target.rs @@ -51,6 +51,12 @@ fn custom_target_minimal() { p.cargo("build --lib --target custom-target.json -v").run(); p.cargo("build --lib --target src/../custom-target.json -v") .run(); + + // Ensure that the correct style of flag is passed to --target with doc tests. + p.cargo("test --doc --target src/../custom-target.json -v -Zdoctest-xcompile") + .masquerade_as_nightly_cargo() + .with_stderr_contains("[RUNNING] `rustdoc [..]--target [..]foo/custom-target.json[..]") + .run(); } #[cargo_test]