rustdoc: Show use-site paths for unevaluated const array lengths
After rust-lang/rust#158171, I noticed a few additional issues with the rendering of consts in rustdoc. This PR fixes them. When rendering array lengths, avoid inlining the full definition of unevaluated constants via `print_inlined_const`. Instead, fall back to `Const::to_string()` for use-site rendering, matching the behavior already used for projections without bodies.
r? camelid
QNX target renaming
This PR renames two QNX targets:
- `aarch64-unknown-nto-qnx800` becomes simply `aarch64-unknown-qnx`
- `x86_64-pc-nto-qnx800` becomes simply `x86_64-pc-qnx`
In addition:
- references to *QNX OS* and *QNX Neutrino RTOS* are replaced with *QNX SDP* for uniformity
- the `spec::base::nto_qnx` module is renamed to `base::spec::qnx_sdp` to match the above
- the `target_os` of the QNX SDP 8.0 targets is changed to `qnx` to match the target name
- a *lot* of code is then touched to handle `any(target_os = "nto", target_os = "qnx")`
I think it's worth noting that *QNX Software Development Platform* is the *build environment* that you download and install, and you can use it to create a custom *run-time environment*. In SDP 7.x the run-time environment was based on *QNX Neutrino 7.x*, but in SDP 8.0 the run-time environment is based on *QNX OS 8.0*. I think it was weird to users to see the two different run-time environments in the docs, and referring to the build environment just seems to make more sense anyway because that's what users install, it's where the headers live, and ultimately it's what the toolchain will care about.
The new target names match those reported by `clang` running *on* the [self-hosted *QNX Developer Desktop*](https://www.qnx.com/developers/docs/qnxeverywhere/com.qnx.doc.qdd/topic/about.html).
```console
$ clang --version
QNX clang version 21.1.3
Target: x86_64-pc-qnx
Thread model: posix
InstalledDir: /usr/bin
```
Once the compiler knows about the new target names, `libc`, `backtrace` and `cc-rs` can be updated to match, and then building `libstd` for the new targets can be fixed. This rename will cause a bit of churn, but it seemed important to get it changed before anyone tries to finish libstd support for QNX SDP 8.0 (it's currently noted as "in-progress"). It's also Tier 3 so we have fairly broad latitude to do this I think, and aligning with QNX's build of clang just makes sense.
With these changes I can run:
```console
$ ./x build library/std --stage 2 --target x86_64-pc-nto-qnx710,aarch64-unknown-nto-qnx710,x86_64-pc-nto-qnx710_iosock,aarch64-unknown-nto-qnx710_iosock,aarch64-unknown-nto-qnx700
$ ./x build library/core --stage 1 --target x86_64-pc-qnx,aarch64-unknown-qnx
```
The QNX SDP 7.x targets retain their old names, and their `target_os = "nto", target_env = "qnx710"` configuration, to avoid breakage.
- aarch64-unknown-nto-qnx800 becomes simply aarch64-unknown-qnx
- x86_64-pc-nto-qnx800 becomes simply x86_64-pc-qnx
- references to QNX OS and QNX Neutrino RTOS are replaced with QNX SDP for uniformity
- various nto_qnx modules are named to qnx_sdp to match the above
The new target names are more consistent with those used by the QNX SDP 8.0 toolchain, and reflect a level on ongoing API stability similar to that for macOS and Linux (which simply have minimum supported versions record for their targets).
Once the compiler knows about the new target names, libc and backtrace can be updated to match, and then building libstd for the new targets can be fixed.
With these changes I can run:
```console
$ ./x build library/std --stage 2 --target x86_64-pc-nto-qnx710,aarch64-unknown-nto-qnx710,x86_64-pc-nto-qnx710_iosock,aarch64-unknown-nto-qnx710_iosock,aarch64-unknown-nto-qnx700
$ ./x build library/core --stage 1 --target x86_64-pc-qnx,aarch64-unknown-qnx
```
rustdoc: show impl Trait<Box<Local>> for Foreign, etc on Local's docs
This is a generalization of rust-lang/rust#92940: that PR handled cases like `impl Foreign for Box<Local>`, but was missing handling for a few other closely related cases.
My particular interest was with showing `impl From<Box<Utf8Path>> for Box<Path>` in camino's documentation. But I ended up handling a bunch of related cases along the way.
I'm new to rustdoc so please let me know if I got anything wrong :) took a bit to fully understand how this worked.
<img width="1733" height="483" alt="image" src="https://github.com/user-attachments/assets/4b987c61-bdac-4de3-a491-c0577e06fa7c" />
This is a generalization of PR 92940: that PR handled cases like `impl Foreign for Box<Local>`, but was missing handling for a few other closely related cases.
My particular interest was with showing `impl From<Box<Utf8Path>> for Box<Path>` in camino's documentation. But I ended up handling a bunch of related cases along the way.
I'm new to rustdoc so please let me know if I got anything wrong :) took a bit to fully understand how this worked.
rustdoc: Avoid ICE on unevaluated `type const` projections in array lengths
`clean_middle_ty` used `normalize_erasing_regions` when rendering array lengths, which panics on unevaluatable associated const projections such as `<T as Trait>::ASSOC` under mGCA.
Fixesrust-lang/rust#158155
Fix invalid "jump-to-def" doc link generation when an item has a `derive` proc-macro
Fixes https://github.com/rust-lang/rust/issues/158050.
The problem is that the proc-macros might generate an impl block `impl $(trait)? for Item` where `Item` then has its span pointing to the current item, overwriting its intra-doc link (hopefully this explanation makes sense ^^').
In short, the proc-macro generates an impl block, the `for Item` makes the code enter `visit_qpath` which in turn calls `handle_path` which will take the span of the last segment of the path (so `Item` here) and use it in the link def "span map".
r? @urgau
rustdoc: Fix ICE on delegated async functions
Fixesrust-lang/rust#157040
rustdoc ICEs with "unexpected async fn return type" on an async delegation like `reuse Trait::foo`. The delegation's HIR signature isn't resolved yet, so its return type cleans to `_`, but the header is still `async`, and sugaring an inferred return type panics.
For delegation items we now clean the resolved signature from the ty side, the same way inlined items already do, instead of the HIR one. That sidesteps the panic and also renders the real return type and `self` parameter instead of `-> _` and `self: _`. The `<Self>` generic that shows up on the free-function form is pre-existing (plain sync delegation prints it too) and left alone.
A delegation item (`reuse path::method`) has an unresolved HIR
signature: its inputs and return type are `InferDelegation` nodes that
clean to `_`. When the delegated function is async, the `async` header
over that inferred return type made `clean_fn_decl_with_params` call
`sugared_async_return_type` on a non-`impl Future` type, panicking with
"unexpected async fn return type".
Clean the resolved ty-side signature for delegation items instead, the
same way inlined items are cleaned. This avoids the ICE and renders the
real return type and `self` parameter rather than `-> _` / `self: _`.
rustdoc: correctly propagate cfgs for glob reexports
This fixes some cases of rustdoc not surfacing the correct required feature combination when using `#[cfg(feature = ...)]` in combination with glob reexports.
See the example cases included as tests.
Here's the generated HTML for those test cases before this change:
<img width="150" height="115" alt="Screenshot_20260528_201140" src="https://github.com/user-attachments/assets/8d611f88-7149-49f6-8ee0-530c049ea858" />
and after:
<img width="225" height="125" alt="Screenshot_20260528_201236" src="https://github.com/user-attachments/assets/85cc07c0-9a9a-455f-8ada-69d44d645516" />
My understanding is that this was basically an off-by-one type of oversight.
We need to update `is_inline` before calling `get_all_import_attributes` to immediately reflect that the outermost import we're processing shall indeed be considered as inline, as it's a glob.
Otherwise, we will end up calling `add_without_unwanted_attributes` with `is_inline == false` on the "intermediate" re-export, which will skip propagating its `cfg`s.
I believe this fixes https://github.com/rust-lang/rust/issues/96166, even though the description there is not super clear on the exact test case they used (there's a snippet but the author says their code is actually different).
Refs https://github.com/rust-lang/rust/issues/43781
@rustbot label +F-doc_cfg
@rustbot r? @GuillaumeGomez
[rustdoc] Fix foreign items macro expansion
Fixesrust-lang/rust#156486.
The ICE was coming from ast pretty printing not handling `...` (C var args). To handle that, I added a `CVarArgs` variants for all `PatKind` enums.
Second part (and second commits) was to correctly handle foreign items in rustdoc.
r? @Urgau
* rustdoc: correctly propagate cfgs for glob reexports
* address review feedback, add a comment explaining the test
* empty commit to trigger CI
* empty commit to trigger CI
* fix sorting of features in tests
* assert contents of index.html
rustdoc: deterministic sorting for `doc_cfg` badges
Fixesrust-lang/rust#156391
Currently, target-exclusive `doc_cfg` badges (eg. "Available on...") reuse the order of predicates as they appear in the source code. This often buries popular targets behind niche ones and leads to inconsistent UI rendering.
This PR introduces a deterministic sorting mechanism to the `Cfg` AST prior to HTML/JSON rendering.
**Note for Reviewers:**
To provide the best UX, I implemented a lightweight tiering heuristic (prioritizing major platforms like Linux/Apple/Windows first, followed by mobile, then BSDs, and alphabetizing the rest). However, I am completely open to tweaking these priority groupings or falling back to a different sorting logic if the team prefers. Let me know what you think!
Fix jump to def link generation on primitive type associated methods
Fixesrust-lang/rust#156707.
Interestingly enough, the inference fails on primitive type, so instead I go around a bit by generating a `PrimitiveType` and then tweak a bit the `href` generation.
r? @fmease
Stabilize `--remap-path-prefix` in rustdoc
# Stabilization report of `--remap-path-prefix` in rustdoc
## Summary
`rustc` supports remapping source paths prefixes as a best effort in all compiler generated output, including compiler diagnostics, debugging information, macro expansions, documentation, doctests, etc.
This is useful for normalizing build products, for example, by removing the current directory out of the paths emitted into object files.
This stabilization stabilize the same flag used by `rustc` in `rustdoc`.
There are no tracking issue.
Stabilization was discussed at the last meeting, [#t-rustdoc/meetings > 2026-04-13 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/393423-t-rustdoc.2Fmeetings/topic/2026-04-13/near/585264347).
### What is stabilized
The rustdoc `--remap-path-prefix` flag is being stabilized by this PR. (It's equivalent to rustc flag)
It permits remapping (as a best effort) source path prefixes in all output, including diagnostics, debug information, macro expansions, generated documentation, etc.
It takes a value of the form `FROM=TO` where a path prefix equal to `FROM` is rewritten to the value `TO`.
#### Example
```sh
rustdoc src/lib.rs --remap-path-prefix="$PWD=/foo"
```
### What isn't stabilized
Neither `--remap-path-scope` (~~soon to be added as unstable in `rustdoc`~~ https://github.com/rust-lang/rust/issues/155451) or the already unstable in `rustc` `documentation` scope are being stabilized or added here.
## Design
### Implementation history
- rust-lang/rust#107099
### Unresolved questions
There are no unresolved questions.
### Post-implementation changes
The implementation has evolved with `rustc`, but no changes to the flag it-self have been made.
### Nightly extensions
The `documentation` scope, which currently can only be set from `rustc`, as we need to add an equivalent to the `--remap-path-scope` flag, ~~which is planned~~ (EDIT: https://github.com/rust-lang/rust/issues/155451), but not required, the current `--remap-path-prefix` defaults to the `all` scope, like `rustc`.
### Doors closed
We are committing to having to having a flag that permits remapping paths. The compiler team already made the same commitment.
## Feedback
### Call for testing
No call for testing has been done.
### Nightly use
Unable to determine. A [GitHub search](https://github.com/search?q=%20%2F--remap-path-prefix%2F&type=code) only seems to only reveals the `rustc` usage (over 6k though).
Rust-for-Linux is using the [flag](e80d033851/Makefile (L1151-L1153)).
## Implementation
### Major parts
- rust-lang/rust#107099
- rust-lang/rust#149709
- rust-lang/rust#150172
- rust-lang/rust#151589
### Coverage
- [`tests/rustdoc-ui/remap-path-prefix-failed-doctest-output.rs`](12f35ad39e/tests/rustdoc-ui/remap-path-prefix-failed-doctest-output.rs)
- [`tests/rustdoc-ui/remap-path-prefix-invalid-doctest.rs`](12f35ad39e/tests/rustdoc-ui/remap-path-prefix-invalid-doctest.rs)
- [`tests/rustdoc-ui/remap-path-prefix-macro.rs`](12f35ad39e/tests/rustdoc-ui/remap-path-prefix-macro.rs)
- [`tests/rustdoc-ui/remap-path-prefix-passed-doctest-output.rs`](12f35ad39e/tests/rustdoc-ui/remap-path-prefix-passed-doctest-output.rs)
- [`tests/rustdoc-ui/lints/remap-path-prefix-lint.rs`](12f35ad39e/tests/rustdoc-ui/lints/remap-path-prefix-lint.rs)
- [`tests/rustdoc-html/import-remapped-paths.rs`](12f35ad39e/tests/rustdoc-html/import-remapped-paths.rs)
- [`tests/rustdoc-html/macro/external-macro-src.rs`](12f35ad39e/tests/rustdoc-html/macro/external-macro-src.rs)
### Outstanding bugs
There are no outstanding bugs regarding `--remap-path-prefix` in `rustdoc`.
There are [caveats and limitation](https://doc.rust-lang.org/nightly/rustc/remap-source-paths.html#caveats-and-limitations) in `rustc`, but they mostly concern generated object files, which we don't really have.
### Outstanding FIXMEs
There are no FIXME regarding `--remap-path-prefix`.
## Acknowledgments
- @edward-shen
- @Urgau
rustdoc: properly support macros with multiple kinds
Since it seems like I can't reopen https://github.com/rust-lang/rust/pull/145458, opening this one. Although, it's the same PR minus the last new commit to handle a comment that was left unresolved in the original PR. All relevant details are still in the original PR though.
It's an alternative (and likely a take-over) of https://github.com/rust-lang/rust/pull/148005 since lang-team rejected the idea to add documentation on macro branches, making the multiple files approach less suitable.
This implements rust-lang/rust#145153 in rustdoc. This PR voluntarily doesn't touch anything related to intra-doc links, I'll send a follow-up if needed.
So now about the implementation itself: this is a weird case where a macro can be different things at once but still only gets one file generated. I saw two ways to implement this:
1. Handle `ItemKind::Macro` differently and iter through its `MacroKinds` values.
2. Add new placeholder variants in the `ItemKind` enum, which means that when we encounter them in rendering, we need to ignore them. It also makes the `ItemKind` enum bigger (and also needs more code to be handled). Another downside is that it needs to be handled in the JSON output.
Now there was an interesting improvement that came with this PR in the `html::render::print_item::item_module` function: I simplified its implementation and split the different parts in a `HashMap` where the key is the item type. So then, we can just iterate through the keys and open/close the section at each iteration instead of keeping an `Option<section>` around.
From RFCs:
* https://github.com/rust-lang/rust/pull/144579
* https://github.com/rust-lang/rust/pull/145208
derive:
<img width="442" height="327" alt="Screenshot From 2026-04-18 03-11-40" src="https://github.com/user-attachments/assets/f69587a0-8a2b-4080-bc8a-b63dd18f21c1" />
attr:
<img width="442" height="327" alt="Screenshot From 2026-04-18 03-11-31" src="https://github.com/user-attachments/assets/bf9b235a-9d2f-435c-a91e-167562df6b68" />
both:
<img width="442" height="327" alt="Screenshot From 2026-04-18 03-11-50" src="https://github.com/user-attachments/assets/b7e8b3c6-eb99-495b-bdf9-17ba8fb4da0d" />
r? @notriddle