From 558796b4600828d5fa731e8a2c9364a282a995d5 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Sun, 27 Jul 2025 01:37:03 +0200 Subject: [PATCH] rustdoc: save target modifiers `rustdoc` was filling a `target_modifiers` variable, but it was not using the result. In turn, that means that trying to use a dependency that set a target modifier fails. For instance, running: ```sh RUSTC_BOOTSTRAP=1 rustc --edition=2024 --target=aarch64-unknown-none-softfloat --sysroot=/dev/null --emit=metadata -Zfixed-x18 --crate-type rlib --crate-name core $(rustc --print sysroot)/lib/rustlib/src/rust/library/core/src/lib.rs echo '#![allow(internal_features)] ' | RUSTC_BOOTSTRAP=1 rustdoc --edition=2021 --target=aarch64-unknown-none-softfloat --sysroot=/dev/null -Zfixed-x18 --extern core=libcore.rmeta - ``` will fail with: ```text error: mixing `-Zfixed-x18` will cause an ABI mismatch in crate `rust_out` | = help: the `-Zfixed-x18` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely = note: unset `-Zfixed-x18` in this crate is incompatible with `-Zfixed-x18=` in dependency `core` = help: set `-Zfixed-x18=` in this crate or unset `-Zfixed-x18` in `core` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=fixed-x18` to silence this error ``` Thus save the targets modifiers in `Options` to then pass it to the session options, so that eventually the diff can be performed as expected in `report_incompatible_target_modifiers()`. Fixes: https://github.com/rust-lang/rust/issues/144521 Signed-off-by: Miguel Ojeda --- src/librustdoc/config.rs | 4 +++ src/librustdoc/core.rs | 2 ++ tests/run-make/rustdoc-target-modifiers/c.rs | 7 +++++ tests/run-make/rustdoc-target-modifiers/d.rs | 12 ++++++++ .../rustdoc-target-modifiers/rmake.rs | 28 +++++++++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 tests/run-make/rustdoc-target-modifiers/c.rs create mode 100644 tests/run-make/rustdoc-target-modifiers/d.rs create mode 100644 tests/run-make/rustdoc-target-modifiers/rmake.rs diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 986390dbaa084..57456e906de55 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -173,6 +173,9 @@ pub(crate) struct Options { /// Arguments to be used when compiling doctests. pub(crate) doctest_build_args: Vec, + + /// Target modifiers. + pub(crate) target_modifiers: BTreeMap, } impl fmt::Debug for Options { @@ -846,6 +849,7 @@ impl Options { unstable_features, expanded_args: args, doctest_build_args, + target_modifiers, }; let render_options = RenderOptions { output, diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index bd57bb21e639b..e89733b2f6d5c 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -214,6 +214,7 @@ pub(crate) fn create_config( scrape_examples_options, expanded_args, remap_path_prefix, + target_modifiers, .. }: RustdocOptions, render_options: &RenderOptions, @@ -277,6 +278,7 @@ pub(crate) fn create_config( } else { OutputTypes::new(&[]) }, + target_modifiers, ..Options::default() }; diff --git a/tests/run-make/rustdoc-target-modifiers/c.rs b/tests/run-make/rustdoc-target-modifiers/c.rs new file mode 100644 index 0000000000000..287d0bbd72527 --- /dev/null +++ b/tests/run-make/rustdoc-target-modifiers/c.rs @@ -0,0 +1,7 @@ +#![allow(internal_features)] +#![feature(lang_items, no_core)] +#![no_core] + +fn f() { + d::f(); +} diff --git a/tests/run-make/rustdoc-target-modifiers/d.rs b/tests/run-make/rustdoc-target-modifiers/d.rs new file mode 100644 index 0000000000000..6cbff06079ed2 --- /dev/null +++ b/tests/run-make/rustdoc-target-modifiers/d.rs @@ -0,0 +1,12 @@ +#![allow(internal_features)] +#![feature(lang_items, no_core)] +#![no_core] + +#[lang = "pointee_sized"] +pub trait PointeeSized {} +#[lang = "meta_sized"] +pub trait MetaSized: PointeeSized {} +#[lang = "sized"] +pub trait Sized: MetaSized {} + +pub fn f() {} diff --git a/tests/run-make/rustdoc-target-modifiers/rmake.rs b/tests/run-make/rustdoc-target-modifiers/rmake.rs new file mode 100644 index 0000000000000..ee522501fd286 --- /dev/null +++ b/tests/run-make/rustdoc-target-modifiers/rmake.rs @@ -0,0 +1,28 @@ +//! Test that target modifiers are taken into account by `rustdoc`. +//! +//! Otherwise, `rustdoc` errors when trying to generate documentation +//! using dependencies (e.g. `core`) that set a target modifier. +//! +//! Please see https://github.com/rust-lang/rust/issues/144521. + +use run_make_support::{rustc, rustdoc}; + +fn main() { + rustc() + .input("d.rs") + .edition("2024") + .crate_type("rlib") + .emit("metadata") + .sysroot("/dev/null") + .target("aarch64-unknown-none-softfloat") + .arg("-Zfixed-x18") + .run(); + + rustdoc() + .input("c.rs") + .crate_type("rlib") + .extern_("d", "libd.rmeta") + .target("aarch64-unknown-none-softfloat") + .arg("-Zfixed-x18") + .run(); +}