Commit Graph

151 Commits

Author SHA1 Message Date
Jacob Pratt
6a25fdd901 Rollup merge of #161054 - GuillaumeGomez:enum-variant-field-title, r=Urgau
rustdoc: Fix link title attribute value when field of enum variants

Fixes https://github.com/rust-lang/rust/issues/161028.

The issue was that we link to parent page, we generate a "fragment" to the parent item (so here the enum), because we forgot to take into account that there might be two levels: enum variants can have fields. So in case it's an enum and the `DefId` is a field, we add the field's parent name (so the enum variant) to the title.

r? @Urgau
2026-08-13 18:16:29 -04:00
Guillaume Gomez
a89abc8225 Fix link title attribute value when field of enum variants 2026-08-13 16:54:57 +02:00
mejrs
4449de3ac5 ensure anon consts themselves are not documented 2026-08-13 14:49:49 +02:00
mejrs
6ef144dcb3 rustdoc: use anonymous constant for primitives/keywords/attribute docs 2026-08-13 14:49:49 +02:00
Zac Harrold
413fdcabfb Add basic splat support to rustdoc
Simply replace the parameter name and `#[rustc_splat]` attribute with an ellipsis. This preserves the type information of the splat while still documenting the variadic nature of the function.
2026-08-12 08:18:52 +10:00
zakrad
1a049129e6 Add regression test for cross-crate assoc const private field leak 2026-08-08 23:10:17 +03:30
Jonathan Brouwer
408fecd121 Rollup merge of #159473 - notriddle:rename-parts-to-dep-meta, r=camelid
Fix, simplify, and document doc meta finalize mode

Follow up https://github.com/rust-lang/rust/pull/159415#discussion_r3605070232

Get rid of the mode where you can finalize the CCI and generate more docs at the same time. It isn't used in Cargo, and probably won't be used elsewhere?

Fixes a bug where the crate index, settings page, and help page aren’t generated at finalize time.

Update documentation.

Move CCI tests to run-make, so that we can test the finalize step’s CLI.
2026-08-05 21:55:45 +02:00
Jonathan Brouwer
a1eaf4e5a3 Rollup merge of #106643 - WaffleLapkin:read_recursive, r=joshtriplett
Allow only implementing `Read::read_buf`

This PR allows users to only implement `Read::read_buf`, without the need for implementing `Read::read`. `rustc_must_implement_one_of` annotation ensures that **at least** one of the methods is implemented, so that the default impls don't create infinite recursion.

Note that `Read::read_buf` is unstable, so this doesn't change anything on stable, there you still need to implement `Read::read`, since you can't implement `Read::read_buf`. Thus, we don't expose `rustc_must_implement_one_of` to stable.

r? @thomcc
2026-08-02 16:19:29 +02:00
Pavel Lazureykis
54941bef4f rustdoc: fix ICE when a grapheme cluster joins a Prepend character to _
`EscapeBodyTextWithWbr` iterates `text.grapheme_indices(true)`, so `i` is the
start of a grapheme cluster, but the `_`/`:` word-break arm sliced at `i + 1` --
assuming a cluster containing `_` or `:` is exactly one byte long.

UAX#29 GB9b joins a `Prepend`-class character (U+0600-U+0605, U+0D4E, U+111C2,
...) with the character that follows it, so a cluster can start with a
multi-byte character and still contain `_`. `i + 1` then lands inside that
character and `str` indexing panics. U+0D4E is `XID_Continue`, so this is
reachable from an item name rustc accepts, e.g. `pub struct abc<U+0D4E>_defgh;`,
and rustdoc ICEs instead of documenting the crate.

Break after the whole cluster (`i + s.len()`) instead. The adjacent CamelCase
arm already slices at `i`, which is always a cluster boundary, so it is
unaffected.

This also stops the `<wbr>` from being inserted between `_` and a combining
mark that trails it, which split a grapheme cluster without panicking.
2026-07-30 19:23:18 +00:00
Jonathan Brouwer
ee17d0d02f Rollup merge of #157058 - ThierryBerger:rustdoc_label_trait, r=GuillaumeGomez
Rustdoc label badge for notable traits

- Part of rust-lang/rust#156865
- [x] reuse notable trait feature to feed badge data
- [x] render it in html
- [x] add some html tests
- [x] Render a color from a hash from `its full path`
- [x] fixed oklch hue-driven palette checked against wcag/apca

Should the following be out of scope ?

- [ ] Parse color (`#[doc(notable_trait(color="0xff0000")]`)
- [ ] display a small colored indicator (with a hover/first letter?) when a type implementing a notable trait is listed outside of its main page
- [ ] Some Integration with rust analyzer

<img width="315" height="222" alt="Screenshot 2026-05-28 at 14 06 01" src="https://github.com/user-attachments/assets/2b7c19c4-0d6e-4ed7-8901-f82fba7fc122" />

## Color discussion

I went for the higher chroma, even though some values use a fallback, I'm not opposed to go for a less chromatic palette, but that's very bikeshedding so I'll defer to authority.

with chroma 0.21:
<img width="1048" height="274" alt="Screenshot 2026-06-30 at 21 57 27" src="https://github.com/user-attachments/assets/9f374295-4eb3-43ee-bffa-51276ffa39d2" />

with chroma 0.090:
<img width="1037" height="274" alt="Screenshot 2026-06-30 at 21 58 38" src="https://github.com/user-attachments/assets/81d9c5b5-02a8-4f75-969f-0d4fc62bebd0" />

## History

Initially, this PR added a new feature "label_trait", it was then decided in [rustdoc meeting](https://hackmd.io/CxdTcVFTQPmBUrx-PWXTAw?view) to reuse current notable_trait feature.
2026-07-29 14:10:33 +02:00
Josh Triplett
39429fd245 Fix links to std::io::Read::read 2026-07-28 16:12:25 -07:00
bors
701a6513a4 Auto merge of #159854 - camelid:selfty-head, r=notriddle,GuillaumeGomez
rustdoc: Only analyze head of self type when deciding impl inlining



We only care about whether the self type is a generic or an item (inlined) in
the current crate, so we don't actually need to compute the param_env, which is
expensive when done to every external impl.  This PR avoids computing the
param_env until we actually decide to inline the impl.  Moreover, it adds
specialized cleaning logic for types that stops after the "head" (the top-level
structure) is constructed, which is enough for the self type-based impl
inlining analysis.
2026-07-28 22:40:33 +00:00
Guillaume Gomez
493ed4a987 Make notable trait badge tests a bit "stronger" 2026-07-28 23:21:51 +02:00
Noah Lev
27c97d1380 rustdoc: Remove unneeded branches, add test 2026-07-28 16:51:55 +00:00
Thierry Berger
5b47394a50 add more tests about unlinkable private/doc-hidden/undocumented 2026-07-28 16:47:26 +02:00
Thierry Berger
5c465a6215 use css classes for colors, number down to 6 2026-07-28 16:47:26 +02:00
Thierry Berger
81983a1421 label trait feature now part of notable traits features 2026-07-28 16:47:23 +02:00
Thierry Berger
46ac557f15 rustdoc: add #[doc(label_trait)] to render a trait badge 2026-07-28 16:39:55 +02:00
Jacob Pratt
a2dd212d5b Rollup merge of #159819 - Vastargazing:fix/poison-error-auto-cfg-note, r=GuillaumeGomez
std::sync::poison: disable auto_cfg on PoisonError::new

`PoisonError::new` is defined twice, once for `#[cfg(panic = "unwind")]` and once for its negation. While exactly one definition survives expansion in any given build, the method itself is actually present in every configuration.

Currently, rustdoc's `auto_cfg` only looks at whichever `cfg` survived expansion and tags the method accordingly, generating a misleading "Available on panic=unwind only" portability badge in the docs.

This is the same `auto_cfg` limitation previously addressed in rust-lang/rust#153964, rust-lang/rust#154311, and rust-lang/rust#156426: when an item is split into mutually-exclusive `cfg` variants that collectively cover all builds, rustdoc incorrectly marks it as conditionally available. Issue rust-lang/rust#149786 pointed out `PoisonError::new` as another case of this pattern, but it hadn't been touched yet.

This PR applies the same fix as rust-lang/rust#156426 (adding `#[doc(auto_cfg = false)]` to both variants) and adds a regression test to cover this pattern going forward.

r? @GuillaumeGomez
2026-07-26 00:21:49 -04:00
Michael Howell
a36c898d05 rustdoc: move CCI tests to run-make
Since we're getting rid of the ability to do finalize and document at
the same time, we can't actually do this in the rustdoc-html test build
system and need to do it this way instead.
2026-07-25 19:06:12 -07:00
Vastargazing
f176d8bd2d std::sync::poison: disable auto_cfg on PoisonError::new
PoisonError::new is defined twice, once under #[cfg(panic = "unwind")]
and once under its negation, so exactly one definition exists in any
given build. rustdoc's auto_cfg only sees whichever cfg survived
expansion and tags the method as available under that cfg only, even
though it is callable in every configuration - it just panics under
panic=abort instead of returning.

Disable auto_cfg on both variants so the portability note stops
implying the method doesn't exist elsewhere. The doc comment already
explains the panic=abort behavior in prose, so the cfg doesn't need to
leak into the generated badge.

Add a minimal regression test.
2026-07-24 11:05:35 +03:00
Guillaume Gomez
7f88868ce4 Extend cfg_attr retrieval for all impls, including ones without the automatically_derived attribute 2026-07-23 00:20:33 +02:00
Guillaume Gomez
35c57b5638 Add regression test for doc_cfg feature on derive impl blocks 2026-07-22 23:50:54 +02:00
bors
c188565812 Auto merge of #159623 - camelid:good-impls, r=notriddle,GuillaumeGomez
rustdoc: Only build extern trait impls if needed



or, finally remove the `BadImplStripper`!

Building inlined impls is expensive, and most of them end up being
unneeded and stripped later in this function. So we should filter them
ahead of time. This requires inlining external auto traits when we
construct auto impls, since this no longer happens as a side effect.

We inline external impls when they are
* for generics (i.e., blanket impls)
* for primitive types (probably this should be handled below really)
* for a type (inlined) in the current crate
* of a trait (inlined) in the current crate
* of `Deref`
These rules are based on the existing filtering rules that are applied
after building the inlined impls.

After doing the filtering ahead of time, we can remove the downstream
filtering. Thus, we can finally remove `BadImplStripper` and unused
deref-following logic. It appears that all this `Deref` logic was pointless
in the first place since following derefs already happens elsewhere in
rustdoc, where it is actually needed.
2026-07-22 09:55:03 +00:00
Noah Lev
afaa98372c rustdoc: Keep external impls of notable traits
The code predating this PR was actually incorrect since it did not keep
these impls. However, removing the redundant deref-following logic had
the side effect of breaking a GUI test for the notable traits tooltip.
It seems like previously an unrelated type with a deref impl to
`Vec<u8>` ended up causing the impl of `Write` for it to be kept.

In fact, this change required some snapshot tests to be updated because
it fixed a latent bug where the notable trait tooltip would not appear
for many external traits (if they didn't happen to get pulled in like
`Write for Vec<u8>` did).
2026-07-21 18:16:01 +00:00
Jonathan Brouwer
fd4b1d563d Rollup merge of #159058 - khyperia:macroless_generic_const_args, r=BoxyUwU
implement #![feature(macroless_generic_const_args)]

tracking issue: https://github.com/rust-lang/rust/issues/159006

lots of description of what is happening here in the tracking issue, not gonna copypaste it into here :)

the test situation is that after discussion with boxy of whether our mgca tests should be:

- keep them under only `min_generic_const_args`, and add `direct_const_arg!()` where it's needed
- keep the code contents as-is, and add `#![feature(macroless_generic_const_args)]` where it's needed

the second seems more desirable, so that's what I did. There are still quite a few tests that only have `min_generic_const_args` without `macroless_generic_const_args` (140 of them, to be exact - `rg --files-without-match macroless_generic_const_args $(rg -g '*.rs' --files-with-matches min_generic_const_args tests) | wc -l`, and now 90 with `macroless_generic_const_args`)

r? @BoxyUwU
2026-07-21 12:24:55 +02:00
khyperia
a388f03123 macroless_generic_const_args 2026-07-20 18:24:17 +02:00
Zac Harrold
e33662abd6 Move std::io::BufRead to alloc::io 2026-07-19 07:32:45 +10:00
Jonathan Brouwer
fa73a93bed Rollup merge of #158544 - bushrat011899:core_io_read, r=clarfonthey
Move `std::io::Read` to `alloc::io`

ACP: https://github.com/rust-lang/libs-team/issues/755
Tracking issue: https://github.com/rust-lang/rust/issues/154046
Split From: https://github.com/rust-lang/rust/pull/156527
~~Blocked On: https://github.com/rust-lang/rust/pull/158541~~

## Description

Moves `std::io::Read` to `alloc::io`. This is mostly a direct cut and paste, but with a large diff due to how many implementations need to be moved into `alloc`. Blocked on rust-lang/rust#158541.

There is some new code written for some of the `Read` implementations to account for the `no_global_oom_handling` configuration, since `Vec::extend_from_slice` and `String::push_str` are unavailable. I've highlighted all of these such instances with review comments for clarity.

---

## Notes

* No AI tooling of any kind was used during the creation of this PR.
* Please see https://github.com/rust-lang/rust/issues/154046#issuecomment-4416678427 for a review order and broader context for this PR.
2026-07-17 23:17:28 +02:00
Jonathan Brouwer
139b0fb16b Rollup merge of #159415 - notriddle:rename-parts-to-dep-meta, r=GuillaumeGomez
rustdoc: rename the doc parts metadata params

Written in response to https://github.com/rust-lang/rust/pull/152902#issuecomment-4984544246
2026-07-17 15:22:13 +02:00
Michael Howell
50fd1f18d1 rustdoc: rename the doc parts metadata params 2026-07-16 18:54:58 -07:00
Jose Torres
526787dbbc rename from lazy_type_alias to checked_type_aliases
Co-authored-by: lcnr <rust@lcnr.de>
2026-07-15 11:50:42 -04:00
Jacob Pratt
c9f758330a Rollup merge of #159194 - Dnreikronos:rustdoc/auto_trait_param_env, r=lolbinarycat
rustdoc: Fix auto trait normalization env

Fixes rust-lang/rust#159065

rustdoc ICEs on #[doc(inline)] pub use std as other; with -Znext-solver=globally -Znormalize-docs. The synthetic auto-trait code builds a ParamEnv for the generated where-clauses, but nested type normalization still reads cx.param_env (via `clean_predicate` -> `clean_middle_ty` -> `normalize`). In the inline std case that env can be empty, so the solver later idk's the type of the placeholder const.

Use that synthetic auto-trait ParamEnv while cleaning the generated where-clauses. imo this is the least weird place to do it: the clauses came from that env, so their normalization should use it too. btw, the added rustdoc-html test is just the reduced issue case, fyi.
2026-07-14 23:23:13 -04:00
Jana Dönszelmann
25745ee1f1 fix all tidy annotations 2026-07-13 10:54:53 +02:00
Dnreikronos
1592a06404 Fix rustdoc auto trait normalization env 2026-07-12 17:20:31 -03:00
Zac Harrold
032721ce21 Move std::io::Read to alloc::io 2026-07-10 15:23:35 +10:00
James Barford-Evans
84aa27d895 Tests for find_auto_trait_generics_next_solver path 2026-07-06 16:11:03 +01:00
Guillaume Gomez
d6f62f661d rustdoc: Fix crash when trying to inline foreign item which cannot have attributes 2026-07-03 23:33:36 +02:00
Jacob Pratt
9fa34499e3 Rollup merge of #158334 - lapla-cogito:rustdoc_typeconst, r=camelid
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
2026-07-01 17:42:28 -04:00
Jacob Pratt
e601172b0b Rollup merge of #158449 - ferrocene:rename-qnx-targets, r=workingjubilee
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.
2026-07-01 01:03:15 -04:00
Guillaume Gomez
9aba0b60dd Add rustdoc HTML test to ensure that the inlining of a #[doc(no_inline)] is working as expected 2026-06-30 12:55:28 +02:00
Jonathan Pallant
4eec7f5d40 Fix rustdoc tests
The name of the OS had changed, so the tests needed updating
2026-06-30 09:01:03 +00:00
Jonathan Pallant
804de70ca0 QNX target renaming
- 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
```
2026-06-30 09:01:03 +00:00
Guillaume Gomez
a5cb0e7780 Fix handling of inlining of no_inline of foreign items 2026-06-29 23:14:02 +02:00
lapla
1f4b09e15a Show use-site paths for unevaluated const array lengths 2026-06-30 00:06:28 +09:00
Jacob Pratt
a1fbf7b8ea Rollup merge of #158466 - sunshowers:nested-fundamental, r=notriddle
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" />
2026-06-27 22:13:46 -04:00
Rain
c3864bee80 rustdoc: show impl Trait<Box<Local>> for Foreign, etc on Local's docs
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.
2026-06-27 03:27:43 -07:00
Guillaume Gomez
702445c767 Remove doc_cfg show/hide conflict error and correctly handle values(any()) 2026-06-26 12:27:26 +02:00
Guillaume Gomez
c383e5c2db Add more regression tests for doc(auto_cfg()) 2026-06-26 12:27:26 +02:00
Guillaume Gomez
3c92a3ce48 Move doc-cfg tests into the right location 2026-06-26 12:27:26 +02:00