Commit graph

1638 commits

Author SHA1 Message Date
Jieyou Xu
8dfb888812
Disable dump-ice-to-disk on i686-pc-windows-msvc
Sometimes the middle frames of the ICE backtrace becomes `<unknown>` on
`i686-pc-windows-msvc` which then makes this test flaky.
2026-01-16 09:27:45 +08:00
Jonathan Brouwer
cbcd1c3eef
Rollup merge of #151036 - issue-151026, r=mati865
Better handle when trying to iterate on a `Range` of a type that isn't `Step`

Mention when a trait bound corresponds to an unstable trait.

Mention `Range` when `Step` bound is unment, and explain that only some std types impl `Iterator` for `Range`.

CC rust-lang/rust#151026
2026-01-14 11:05:40 +01:00
Guillaume Gomez
080c7043c1
Rollup merge of #150840 - print-check-cfg-rework-output, r=nnethercote
Make `--print=check-cfg` output compatible `--check-cfg` arguments

This PR changes significantly the output of the unstable `--print=check-cfg` option.

Specifically it removes the ad-hoc resemblance with `--print=cfg` in order to output a simplified but still compatible `--check-cfg` arguments.

The goal is to future proof the output of `--print=check-cfg` like `--check-cfg` is, and the best way to do that is to use it's syntax.

This is particularly relevant for [RFC3905](https://github.com/rust-lang/rfcs/pull/3905) which wants to introduce a new predicate: `version(...)`.
2026-01-13 23:39:09 +01:00
Esteban Küber
1fe705ca70 Mention the type in the label, to avoid confusion at the cost of redundancy 2026-01-13 19:47:06 +00:00
bors
db1484bdee Auto merge of #151051 - JonathanBrouwer:rollup-SuaGLmP, r=JonathanBrouwer
Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#150151 (Destabilise `target-spec-json`)
 - rust-lang/rust#150826 (Add `f16` inline ASM support for s390x)
 - rust-lang/rust#150883 (Improve span for "unresolved intra doc link" on `deprecated` attribute)
 - rust-lang/rust#150934 (Move some checks from `check_doc_attrs` directly into `rustc_attr_parsing`)
 - rust-lang/rust#150943 (Port `#[must_not_suspend]` to attribute parser)
 - rust-lang/rust#150990 (std: sys: net: uefi: Make TcpStream Send)
 - rust-lang/rust#150995 (core: ptr: split_at_mut: fix typo in safety doc)
 - rust-lang/rust#150998 (Relax test expectation for @__llvm_profile_runtime_user)
 - rust-lang/rust#151002 (Remove a workaround for a bug (take 2))
 - rust-lang/rust#151005 (Fix typo in `MaybeUninit` docs)
 - rust-lang/rust#151011 (Update books)
 - rust-lang/rust#151029 (rustc-dev-guide subtree update)
 - rust-lang/rust#151032 (fix: added missing backtick in triagebot.toml)
 - rust-lang/rust#151035 (Don't suggest replacing closure parameter with type name)

r? @ghost
2026-01-13 10:47:20 +00:00
Jonathan Brouwer
a89683dd95
Rollup merge of #150151 - destabilise-target-spec-json, r=Kivooeo
Destabilise `target-spec-json`

Per rust-lang/compiler-team#944:

> Per https://github.com/rust-lang/rust/issues/71009, the ability to load target spec JSONs was stabilised accidentally. Within the team, we've always considered the format to be unstable and have changed it freely. This has been feasible as custom targets can only be used with core, like any other target, and so custom targets de-facto require nightly to be used (i.e. to build core manually or use Cargo's -Zbuild-std).
>
> Current build-std RFCs (https://github.com/rust-lang/rfcs/pull/3873, https://github.com/rust-lang/rfcs/pull/3874) propose a mechanism for building core on stable (at the request of Rust for Linux), which combined with a stable target-spec-json format, permit the current format to be used much more widely on stable toolchains. This would prevent us from improving the format - making it less tied to LLVM, switching to TOML, enabling keys in the spec to be stabilised individually, etc.
>
> De-stabilising the format gives us the opportunity to improve the format before it is too challenging to do so. Internal company toolchains and projects like Rust for Linux already use target-spec-json, but must use nightly at some point while doing so, so while it could be inconvenient for those users to destabilise this, it is hoped that an minimal alternative that we could choose to stabilise can be proposed relatively quickly.
2026-01-13 09:01:29 +01:00
Esteban Küber
9b7f612d44 Update main label 2026-01-13 02:57:40 +00:00
Esteban Küber
47089856ab Update run-make test output 2026-01-13 02:14:31 +00:00
Urgau
feb44c3f48 Make --print=check-cfg output compatible --check-cfg arguments 2026-01-12 23:46:22 +01:00
Akshit Gaur
e03cb1f0a6
run-make-support: resolve .rmeta companion for .rlib stubs
Add .rmeta resolution for run-make/sysroot-crates-are-unstable test
2026-01-12 10:52:14 +01:00
Jieyou Xu
dd948f96f3
Thread --jobs from bootstrap -> compiletest -> run-make-support 2026-01-06 14:51:51 +08:00
Matthias Krüger
78376fd39c
Rollup merge of #150558 - estebank:multiple-dep-versions, r=jieyouxu
Detect cases where `?` is applied on a type that could be coming from a different crate version than expected

```
error[E0277]: `?` couldn't convert the error to `dependency::Error`
  --> replaced
   |
LL | fn main() -> Result<(), Error> {
   |              ----------------- expected `dependency::Error` because of this
...
LL |     Err(Error2)?;
   |     -----------^ the trait `From<Error2>` is not implemented for `dependency::Error`
   |     |
   |     this can't be annotated with `?` because it has type `Result<_, Error2>`
   |
   = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
help: the trait `From<Error2>` is not implemented for `dependency::Error`
      but trait `From<()>` is implemented for it
  --> replaced
   |
LL | impl From<()> for Error {
   | ^^^^^^^^^^^^^^^^^^^^^^^
   = help: for that trait implementation, expected `()`, found `Error2`
   = note: there are multiple different versions of crate `dependency` in the dependency graph
   = help: you can use `cargo tree` to explore your dependency tree
```

The existing checks rely on having access to the actual types/traits that diverged to detect they are called the same, come from different crates with the same name. The new check is less specific, merely looking to see if the crate name the involved type belongs has multiple crates.

CC rust-lang/rust#78552.
2026-01-03 10:09:29 +01:00
Esteban Küber
22bb4fe147 Detect cases where ? is applied on a type that could be coming from a different crate version than expected
```
error[E0277]: `?` couldn't convert the error to `dependency::Error`
  --> replaced
   |
LL | fn main() -> Result<(), Error> {
   |              ----------------- expected `dependency::Error` because of this
...
LL |     Err(Error2)?;
   |     -----------^ the trait `From<Error2>` is not implemented for `dependency::Error`
   |     |
   |     this can't be annotated with `?` because it has type `Result<_, Error2>`
   |
   = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
help: the trait `From<Error2>` is not implemented for `dependency::Error`
      but trait `From<()>` is implemented for it
  --> replaced
   |
LL | impl From<()> for Error {
   | ^^^^^^^^^^^^^^^^^^^^^^^
   = help: for that trait implementation, expected `()`, found `Error2`
   = note: there are multiple different versions of crate `dependency` in the dependency graph
   = help: you can use `cargo tree` to explore your dependency tree
```

The existing checks rely on having access to the actual types/traits that diverged to detect they are called the same, come from different crates with the same name. The new check is less specific, merely looking to see if the crate name the involved type belongs has multiple crates.
2025-12-31 23:40:16 +00:00
bjorn3
1a4e7f9aa9 Use --print target-libdir in run-make tests
This makes the tests more robust against sysroot layout changes and
slightly simplifies them.
2025-12-31 15:15:28 +00:00
Jonathan Brouwer
77fe25a741
Rollup merge of #150311 - ChrisDenton:no-temp, r=Kivooeo
Avoid using env::temp when linking a binary

This keeps all build artefacts (even temporary ones) within the build directory.

Fixes rust-lang/rust#139963
2025-12-24 14:19:22 +01:00
Chris Denton
6e354544bf
Rename invalid-tmpdir-env-var
to invalid-tmpdir-no-ice
2025-12-24 06:41:44 +00:00
Chris Denton
b5c473e414
Avoid using env::temp when linking a binary
This keeps all build artefacts (even temporary ones) within the build directory.
2025-12-24 06:41:42 +00:00
bors
efa32de15b Auto merge of #150283 - Urgau:remap-debuginfo-absolute, r=jieyouxu
Remap both absolute and relative paths when building `rustc` and `std`

Turns out [#150110](https://github.com/rust-lang/rust/issues/150110) didn't work as expected, because when the standard library sources are present, we [helpfully un-remap the paths](e951f470d7/compiler/rustc_metadata/src/rmeta/decoder.rs (L1656-L1702)) to the local directory of the user, including when we are building the compiler and standard library it-self (duh!), and since those paths are absolute (not relative), our purely relative remapping didn't pick them up.

This behavior wasn't a issue before because the un-remap logic immediately tries to remap them again, and since we had the absolute remapping we would just remap them to the the same thing.

To fix that issue I've adjusted our remapping to remap both the absolute and relative paths when building `rustc` and `std`, as well as added a run-make to make sure we don't regress it again (with a new `needs-std-remap-debuginfo` directive).

r? `@jieyouxu`
2025-12-24 06:23:00 +00:00
Tshepang Mbambo
e7965821e8 use new term in description of --target 2025-12-23 23:35:58 +02:00
Urgau
4d839da22b Remap both absolute and relative paths when building rustc and std 2025-12-22 19:44:13 +01:00
bors
d3f16d2f35 Auto merge of #149437 - ilammy:patch-1, r=Mark-Simulacrum
Fix trailing newline in JUnit formatter

`write_message()` expects messages to contain no newlines.

Fixes https://github.com/rust-lang/rust/issues/149436
2025-12-21 10:37:51 +00:00
David Wood
6c4c4384e8
destabilise target-spec-json 2025-12-19 11:57:34 +00:00
Oleksii Lozovskyi
a8f4a6744c rustdoc: Test only in stage2
stage1's rustdoc is using stage0's libtest which does not have
a fix from 069cf9dfc9, making the test run fail. Ensure that
this test is executed with everything recompiled in stage2.
2025-12-16 21:10:29 +09:00
Matthias Krüger
3e412faa66
Rollup merge of #149994 - Flakebi:amdgpu-vectors, r=jieyouxu
Allow vector types for amdgpu

The amdgpu target uses vector types in various places. The vector types can be used on all architectures, there is no associated target feature that needs to be enabled.

The largest vector type found in LLVM intrinsics is `v32i32` (`[32 x i32]`) for mfma intrinsics. Note that while this intrinsic is only supported on some architectures, the vector type itself is supported on all architectures.

Tracking issue: rust-lang/rust#135024

(I used an empty string to say “does not need a target feature”. If you prefer an `Option` or something like that, I’ll change it.)
2025-12-15 08:08:04 +01:00
Matthias Krüger
98f87362d9
Rollup merge of #149969 - jyn514:ibt, r=jieyouxu
don't use no_main and no_core to test IBT

The previous test was quite fragile and depended on a bunch of internal features. Simplify it.

Split out of https://github.com/rust-lang/rust/pull/149937.

cc ```@jieyouxu``` ```@Oneirical```
2025-12-14 20:04:57 +01:00
Flakebi
a9b147259b
Allow vector types for amdgpu
The amdgpu target uses vector types in various places. The vector types
can be used on all architectures, there is no associated target feature
that needs to be enabled.

The largest vector type found in LLVM intrinsics is `v32i32`
(`[32 x i32]`) for mfma intrinsics. Note that while this intrinsic is
only supported on some architectures, the vector type itself is
supported on all architectures.
2025-12-14 17:03:51 +01:00
jyn
309e9ec576 don't use no_main and no_core to test IBT
also assert that the property is IBT and not some random other property.
2025-12-14 09:18:31 -05:00
bors
08de25c4ea Auto merge of #149273 - bjorn3:crate_locator_improvements, r=petrochenkov
Don't leak sysroot crates through dependencies

Previously if a dependency of the current crate depended on a sysroot crate, then `extern crate` would in the current crate would pick the first loaded version of said sysroot crate even in case of an ambiguity. This is surprising and brittle. For `-Ldependency=` we already blocked this since rust-lang/rust#110229, but the fix didn't account for sysroot crates.

Should fix https://github.com/rust-lang/rust/issues/147966
2025-12-14 09:16:11 +00:00
bors
8188f6c808 Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Overhaul filename handling for cross-compiler consistency

This PR overhauls the way we handle filenames in the compiler and `rmeta` in order to achieve achieve cross-compiler consistency (ie. having the same path no matter if the filename was created in the current compiler session or is coming from `rmeta`).

This is required as some parts of the compiler rely on consistent paths for the soundness of generated code (see rust-lang/rust#148328).

In order to achieved consistency multiple steps are being taken by this PR:
 - by making `RealFileName` immutable
 - by only having `SourceMap::to_real_filename` create `RealFileName`
   - currently `RealFileName` can be created from any `Path` and are remapped afterwards, which creates consistency issue
 - by also making `RealFileName` holds it's working directory, embeddable name and the remapped scopes
   - this removes the need for a `Session`, to know the current(!) scopes and cwd, which is invalid as they may not be equal to the scopes used when creating the filename

In order for `SourceMap::to_real_filename` to know which scopes to apply `FilePathMapping` now takes the current remapping scopes to apply, which makes `FileNameDisplayPreference` and company useless and are removed.

This PR is split-up in multiple commits (unfortunately not atomic), but should help review the changes.

Unblocks https://github.com/rust-lang/rust/pull/147611
Fixes https://github.com/rust-lang/rust/issues/148328
2025-12-13 14:32:09 +00:00
Oleksii Lozovskyi
069cf9dfc9 rustdoc: Write newline differently
Fix the panic in write_message() which expects messages to contain
no embedded newlines. We still want a trailing newline at the end
of the file though, so write it in different manner.

Doctest runner no longer panics, but the output is kinda broken
when `compile_fail` doctests are present. This is because they
are not mergeable.
2025-12-13 16:31:09 +09:00
Oleksii Lozovskyi
2cc434863c rustdoc: Test --format=junit
Copied validate_junit.py from libtest-junit.

JUnit format works well in edition 2021, but is currently broken
in edition 2024 by the mergeable doctest report.
2025-12-13 16:31:02 +09:00
Oleksii Lozovskyi
e39e127bd0 libtest: Stricter XML validation
Expect the entire input to be a single XML document, instead of
reading it line by line. This detects trailing junk better.
2025-12-13 16:30:32 +09:00
Urgau
0afd21d646 Add ignore-cross-compile to remap-path-prefix-consts run-make test 2025-12-12 07:34:52 +01:00
Urgau
8b035e473a Add regression test for Location::caller() in consts across crates 2025-12-12 07:34:52 +01:00
Urgau
8cbfb26383 Overhaul filename handling for cross-compiler consistency
This commit refactors `SourceMap` and most importantly `RealFileName` to
make it self-contained in order to achieve cross-compiler consistency.

This is achieved:
 - by making `RealFileName` immutable
 - by only having `SourceMap::to_real_filename` create `RealFileName`
 - by also making `RealFileName` holds it's working directory,
   it's embeddable name and the remapped scopes
 - by making most `FileName` and `RealFileName` methods take a scope as
   an argument

In order for `SourceMap::to_real_filename` to know which scopes to apply
`FilePathMapping` now takes the current remapping scopes to apply, which
makes `FileNameDisplayPreference` and company useless and are removed.

The scopes type `RemapPathScopeComponents` was moved from
`rustc_session::config` to `rustc_span`.

The previous system for scoping the local/remapped filenames
`RemapFileNameExt::for_scope` is no longer useful as it's replaced by
methods on `FileName` and `RealFileName`.
2025-12-12 07:33:09 +01:00
Matthias Krüger
0dfc23839b
Rollup merge of #149565 - jyn514:force-doctest-merge, r=notriddle
rustdoc: Add unstable `--merge-doctests=yes/no/auto` flag

This is useful for changing the *default* for whether doctests are merged or not. Currently, that default is solely controlled by `edition = 2024`, which adds a high switching cost to get doctest merging. This flag allows opting in even on earlier editions.

Unlike the `edition = 2024` default, `--merge-doctests=yes` gives a hard error if merging fails instead of falling back to running standalone tests. The user has explicitly said they want merging, so we shouldn't silently do something else.

`--merge-doctests=auto` is equivalent to the current 2024 edition behavior, but available on earlier editions.

Helps with https://github.com/rust-lang/rust/issues/141240. ``@epage`` said in that issue he would like a per-doctest opt-in, and that seems useful to me in addition to this flag, but I think it's a separate use case from changing the default.
2025-12-11 22:09:54 +01:00
bjorn3
b01a2fb652 Add a test for not resolving ambiguity for multiple --extern with same name 2025-12-11 12:08:20 +01:00
Matthias Krüger
679ab9e061
Rollup merge of #149400 - Skgland:tracked_mod, r=Amanieu
unstable proc_macro tracked::* rename/restructure

Picking up what should be the uncontroversial part of rust-lang/rust#87173 (closed due to inactivity over two years ago).

Part of rust-lang/rust#99515.

- move `proc_macro::tracked_env::var` to `proc_macro::tracked::env_var`
- move `proc_macro::tracked_path::path` to `proc_macro::tracked::path`
- change the argument of `proc_macro::tracked::path` from `AsRef<str>` to `AsRef<Path>`.
2025-12-09 17:36:48 +01:00
dianqk
611c956c78
test: Add test for 146133
Even if a crate is marked as #![no_builtins], we can still generate bitcode for rlib,
but we cannot emit bitcode to the linker in rustc's LTO.
2025-12-08 21:57:17 +08:00
Michael Howell
38a2a3da3c rustdoc: test for loading index when user said no
Also mentioned, as a perf problem, in
<https://github.com/rust-lang/cargo/pull/16309#discussion_r2586792981>
2025-12-05 21:00:14 -07:00
Michael Howell
cf83387d2f rustdoc: add test case for alias bug
Reproduces
<https://github.com/rust-lang/cargo/pull/16309#discussion_r2586792981>
2025-12-05 20:45:28 -07:00
bors
36b2369c91 Auto merge of #141980 - beetrees:va-list-proposal, r=workingjubilee
`c_variadic`: make `VaList` abi-compatible with C

tracking issue: https://github.com/rust-lang/rust/issues/44930
related PR: rust-lang/rust#144529

On some platforms, the C `va_list` type is actually a single-element array of a struct (on other platforms it is just a pointer). In C, arrays passed as function arguments expirience array-to-pointer decay, which means that C will pass a pointer to the array in the caller instead of the array itself, and modifications to the array in the callee will be visible to the caller (this does not match Rust by-value semantics). However, for `va_list`, the C standard explicitly states that it is undefined behaviour to use a `va_list` after it has been passed by value to a function (in Rust parlance, the `va_list` is moved, not copied). This matches Rust's pass-by-value semantics, meaning that when the C `va_list` type is a single-element array of a struct, the ABI will match C as long as the Rust type is always be passed indirectly.

In the old implementation, this ABI was achieved by having two separate types: `VaList` was the type that needed to be used when passing a `VaList` as a function parameter, whereas `VaListImpl` was the actual `va_list` type that was correct everywhere else. This however is quite confusing, as there are lots of footguns: it is easy to cause bugs by mixing them up (e.g. the C function `void foo(va_list va)` was equivalent to the Rust `fn foo(va: VaList)` whereas the C function `void bar(va_list* va)` was equivalent to the Rust `fn foo(va: *mut VaListImpl)`, not `fn foo(va: *mut VaList)` as might be expected); also converting from `VaListImpl` to `VaList` with `as_va_list()` had platform specific behaviour: on single-element array of a struct platforms it would return a `VaList` referencing the original `VaListImpl`, whereas on other platforms it would return a cioy,

In this PR, there is now just a single `VaList` type (renamed from `VaListImpl`) which represents the C `va_list` type and will just work in all positions. Instead of having a separate type just to make the ABI work, rust-lang/rust#144529 adds a `#[rustc_pass_indirectly_in_non_rustic_abis]` attribute, which when applied to a struct will force the struct to be passed indirectly by non-Rustic calling conventions. This PR then implements the `VaList` rework, making use of the new attribute on all platforms where the C `va_list` type is a single-element array of a struct.

Cleanup of the `VaList` API and implementation is also included in this PR: since it was decided it was OK to experiment with Rust requiring that not calling `va_end` is not undefined behaviour (https://github.com/rust-lang/rust/issues/141524#issuecomment-3028383594), I've removed the `with_copy` method as it was redundant to the `Clone` impl (the `Drop` impl of `VaList` is a no-op as `va_end` is a no-op on all known platforms).

Previous discussion: rust-lang/rust#141524 and [t-compiler > c_variadic API and ABI](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/c_variadic.20API.20and.20ABI)
Tracking issue: https://github.com/rust-lang/rust/issues/44930
r? `@joshtriplett`
2025-12-05 23:36:55 +00:00
Zalathar
84ff44c749 Add perma-unstable --print=backend-has-zstd for use by compiletest
Tests for `-Zdebuginfo-compression=zstd` need to be skipped if LLVM was built
without support for zstd compression.

Currently, compiletest relies on messy and fragile heuristics to detect whether
the compiler's LLVM was built with zstd support. But the compiler itself
already knows whether LLVM has zstd or not, so it's easier for compiletest to
just ask the compiler.
2025-12-05 14:27:52 +11:00
beetrees
f7b3c1d3c0
Rework c_variadic 2025-12-04 10:51:34 +01:00
Jynn Nelson
29f31f1662 rustdoc: Add unstable --merge-doctests=yes/no/auto flag
This is useful for changing the *default* for whether doctests are
merged or not. Currently, that default is solely controlled by
`edition = 2024`, which adds a high switching cost to get doctest
merging. This flag allows opt-ing in even on earlier additions.

Unlike the `edition = 2024` default, `--merge-doctests=yes` gives a hard
error if merging fails instead of falling back to running standalone
tests. The user has explicitly said they want merging, so we shouldn't
silently do something else.

`--merge-doctests=auto` is equivalent to the current 2024 edition
behavior, but available on earlier editions.
2025-12-03 15:48:05 -05:00
Skgland
3f67246af5
fix tests/run-make/track-path-dep-info attempt 2 2025-11-28 20:47:03 +01:00
Skgland
f4296bce97
fix tests 2025-11-27 22:02:47 +01:00
Matthias Krüger
be49e00109
Rollup merge of #148234 - notriddle:doc-cci, r=GuillaumeGomez
rustdoc: make mergeable crate info more usable

Part of https://github.com/rust-lang/rust/issues/130676

Adds documentation and a feature change aimed at making this usable without breaking backwards compat.

cc ``@EtomicBomb``
2025-11-24 19:10:43 +01:00
Guillaume Gomez
629a283b98
Rollup merge of #149043 - aDotInTheVoid:is-this-real-is-this-out-of-spite-does-it-matter, r=GuillaumeGomez
rustdoc-json: add rlib path to ExternalCrate to enable robust crate resolution

Historically, it's not been possible to robustly resolve a cross-crate item in rustdoc-json. If you had a `Id` that wasn't in `Crate::index` (because it was defined in a different crate), you could only look it up it `Crate::paths`. But there, you don't get the full information, only an `ItemSummary`. This tells you the `path` and the `crate_id`.

But knowing the `crate_id` isn't enough to be able to build/find the rustdoc-json output with this item. It's only use is to get a `ExternalCrate` (via `Crate::external_crates`). But that only tells you the `name` (as a string). This isn't enough to uniquely identify a crate, as there could be multiple versions/features [^1] [^2].

This was originally proposed to be solved via `@LukeMathWalker's` `--orchestrator-id` proposal (https://github.com/rust-lang/compiler-team/issues/635). But that requires invasive changes to cargo/rustc. This PR instead implements `@Urgau's` proposal to re-use the path to a crate's rmeta/rlib as a unique identifer. Callers can use that to determine which package it corresponds to in the language of the build-system above rustc. E.g. for cargo, `cargo rustdoc --message-format=json --output-format=json -Zunstable-options`).

(Once you've found the right external crate's rustdoc-json output, you still need to resolve the path->id in that crate. But that's """just""" a matter of walking the module tree. We should probably still make that nicer (by, for example, allowing sharing `Id`s between rustdoc-json document), but that's a future concern)

For some notes from RustWeek 2025, where this was designed, see https://hackmd.io/0jkdguobTnW7nXoGKAxfEQ

CC `@obi1kenobi` (who wants this for cargo-semver-checks [^3]), `@epage` (who's conversations on what and wasn't possible with cargo informed taking this approach to solve this problem)

r? `@GuillaumeGomez`

## TODO:

- [x] Docs: [Done](e4cdd0c24a..457ed4edb1)
- [x] Tests: [Done](2e1b954dc5..4d00c1a7ee)

[^1]: https://github.com/rust-lang/compiler-team/issues/635#issue-1714254865 § Problem
[^2]: https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/Identifying.20external.20crates.20in.20Rustdoc.20JSON/with/352701211
[^3]: https://github.com/obi1kenobi/cargo-semver-checks/issues/638
2025-11-21 21:34:26 +01:00
Alona Enraght-Moony
361af821ab rustdoc-json: add rlib path to ExternalCrate to enable robust crate resolution
Historically, it's not been possible to robustly resolve a cross-crate
item in rustdoc-json. If you had a `Id` that wasn't in `Crate::index`
(because it was defined in a different crate), you could only look it up
it `Crate::paths`. But there, you don't get the full information, only
an `ItemSummary`. This tells you the `path` and the `crate_id`.

But knowing the `crate_id` isn't enough to be able to build/find the
rustdoc-json output with this item. It's only use is to get a
`ExternalCrate` (via `Crate::external_crates`). But that only tells you
the `name` (as a string). This isn't enough to uniquely identify a
crate, as there could be multiple versions/features [1] [2].

This was originally proposed to be solved via LukeMathWalker's
`--orchestrator-id` proposal
(https://www.github.com/rust-lang/compiler-team/issues/635). But that
requires invasive changes to cargo/rustc. This PR instead implements
Urgau's proposal to re-use the path to a crate's rmeta/rlib as a unique
identifer. Callers can use that to determine which package it
corresponds to in the language of the build-system above rustc. E.g. for
cargo, `cargo rustdoc --message-format=json --output-format=json
-Zunstable-options`).

(Once you've found the right external crate's rustdoc-json output, you
still need to resolve the path->id in that crate. But that's """just"""
a matter of walking the module tree. We should probably still make that
nicer (by, for example, allowing sharing `Id`s between rustdoc-json
document), but that's a future concern)

For some notes from RustWeek 2025, where this was designed, see
https://hackmd.io/0jkdguobTnW7nXoGKAxfEQ

[1]: https://www.github.com/rust-lang/compiler-team/issues/635#issue-1714254865 § Problem
[2]: https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/Identifying.20external.20crates.20in.20Rustdoc.20JSON/with/352701211
2025-11-21 09:22:59 +00:00