Skip to content

Commit d776c5a

Browse files
authored
Rollup merge of #144523 - ojeda:rustdoc-target-modifiers, r=GuillaumeGomez
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()`. Cc: ``@azhogin`` Fixes: #144521
2 parents df6f530 + 558796b commit d776c5a

File tree

5 files changed

+53
-0
lines changed

5 files changed

+53
-0
lines changed

src/librustdoc/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ pub(crate) struct Options {
173173

174174
/// Arguments to be used when compiling doctests.
175175
pub(crate) doctest_build_args: Vec<String>,
176+
177+
/// Target modifiers.
178+
pub(crate) target_modifiers: BTreeMap<OptionsTargetModifiers, String>,
176179
}
177180

178181
impl fmt::Debug for Options {
@@ -846,6 +849,7 @@ impl Options {
846849
unstable_features,
847850
expanded_args: args,
848851
doctest_build_args,
852+
target_modifiers,
849853
};
850854
let render_options = RenderOptions {
851855
output,

src/librustdoc/core.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ pub(crate) fn create_config(
214214
scrape_examples_options,
215215
expanded_args,
216216
remap_path_prefix,
217+
target_modifiers,
217218
..
218219
}: RustdocOptions,
219220
render_options: &RenderOptions,
@@ -277,6 +278,7 @@ pub(crate) fn create_config(
277278
} else {
278279
OutputTypes::new(&[])
279280
},
281+
target_modifiers,
280282
..Options::default()
281283
};
282284

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![allow(internal_features)]
2+
#![feature(lang_items, no_core)]
3+
#![no_core]
4+
5+
fn f() {
6+
d::f();
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![allow(internal_features)]
2+
#![feature(lang_items, no_core)]
3+
#![no_core]
4+
5+
#[lang = "pointee_sized"]
6+
pub trait PointeeSized {}
7+
#[lang = "meta_sized"]
8+
pub trait MetaSized: PointeeSized {}
9+
#[lang = "sized"]
10+
pub trait Sized: MetaSized {}
11+
12+
pub fn f() {}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//! Test that target modifiers are taken into account by `rustdoc`.
2+
//!
3+
//! Otherwise, `rustdoc` errors when trying to generate documentation
4+
//! using dependencies (e.g. `core`) that set a target modifier.
5+
//!
6+
//! Please see https://github.com/rust-lang/rust/issues/144521.
7+
8+
use run_make_support::{rustc, rustdoc};
9+
10+
fn main() {
11+
rustc()
12+
.input("d.rs")
13+
.edition("2024")
14+
.crate_type("rlib")
15+
.emit("metadata")
16+
.sysroot("/dev/null")
17+
.target("aarch64-unknown-none-softfloat")
18+
.arg("-Zfixed-x18")
19+
.run();
20+
21+
rustdoc()
22+
.input("c.rs")
23+
.crate_type("rlib")
24+
.extern_("d", "libd.rmeta")
25+
.target("aarch64-unknown-none-softfloat")
26+
.arg("-Zfixed-x18")
27+
.run();
28+
}

0 commit comments

Comments
 (0)