[rustdoc] Correctly handle `dyn` trait methods linking for jump to def feature
Part of the missing pieces for https://github.com/rust-lang/rust/pull/162808 to work.
The issue was that in case we had the method of a dyn trait, we tried to use the dyn trait as is and couldn't generate a correct href to its `DefId`. If we get the trait in the `dyn`, it works just as expected.
r? @Urgau
[rustdoc] Correctly handle intra-doc links on inlined same item with different names
Fixes https://github.com/rust-lang/rust/issues/136777.
It works as follow: we keep the `DefId` indexing, but we add a new `alternatives` entry (same inlined items, but under a different path) which allows to pick the right entry.
So now, why this approach instead of changing the indexing (like `(DefId, Symbol)`)? Because it's much less common to import a same item with different names, so increasing the size of the index seems unnecessary. That does make the code more noisy, which I'm not a big fan of, so if someone has ideas for improvements, definitely interested!
r? @lolbinarycat
[rustc_resolve] Correctly keep all reexports in `ModChild::reexport_chain`
Fixesrust-lang/rust#81893.
First commit comes from https://github.com/rust-lang/rust/pull/161872 and it's the base I used for the fix in the second commit (which also reverts basically everything from the first commit, not sure if I should keep it...). In short, `NameResolution` only seems to have access to local reexports and to the final reexported item. So instead, we keep the information in `DeclKind` (which cannot implement `Drop` because it's part of `DeclData` which is stored in `ResolverArenas::dropless` so I kept a slice instead of a `SmallVec`. Guess how I found out? Lots of `panic`s :') ) and we use this information in `reexport_chain`.
r? @petrochenkov
Clean up `test/rustdoc-html` folder by moving tests where appropriate
<del>Gonna likely continue a bit more before assigning a reviewer.</del>
CI is happy and I think it's already big enough for a first batch.
r? ghost
Add new Tier-3 target: `powerpc64-sony-ps3`
Implements a compatible target for the Sony PlayStation 3 console's PPU processor.
> A tier 3 target must have a designated developer or developers (the “target maintainers”) on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.)
I ([@ZephyrCodesStuff](https://github.com/ZephyrCodesStuff)) am the maintainer and developer, both for this PR's target, as well as a [Rust PS3 SDK](https://github.com/zephyrcodesstuff/rust-ps3) to help developers get started.
> Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target.
Addressed. The PPU is a standard `powerpc64` core, with only marginal changes made for the PS3's hardware configuration. `sony` is used among other Sony console targets, and `ps3` is the console's shorthand.
> Target names should not introduce undue confusion or ambiguity unless absolutely necessary to maintain ecosystem compatibility. For example, if the name of the target makes people extremely likely to form incorrect beliefs about what it targets, the name should be changed or augmented to disambiguate it.
If possible, use only letters, numbers, dashes and underscores for the name. Periods (.) are known to cause issues in Cargo.
Addressed.
> Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users.
The target must not introduce license incompatibilities.
Although it does require a separate linker (`mold`) and a post-fix binary patching tool (included in the SDK above), no part of the build process, from the code, to the compiler, linker or SDK are closed-source. This target is compatible with the aformentioned SDK without any reliance on community "homebrew" tools, nor any licensed Sony / SN Systems compiler or linker.
> Anything added to the Rust repository must be under the standard Rust license (MIT OR Apache-2.0).
All of my code in this PR, including the SDK above, are licensed `MIT OR Apache-2.0`.
> The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy. This applies whether the dependency is a Rust crate that would require adding new license exceptions (as specified by the tidy tool in the rust-lang/rust repository), or whether the dependency is a native library or binary. In other words, the introduction of the target must not cause a user installing or running a version of Rust or the Rust tools to be subject to any new license requirements.
Compiling, linking, and emitting functional binaries, libraries, or other code for the target (whether hosted on the target itself or cross-compiling from another target) must not depend on proprietary (non-FOSS) libraries. Host tools built for the target itself may depend on the ordinary runtime libraries supplied by the platform and commonly used by other applications built for the target, but those libraries must not be required for code generation for the target; cross-compilation to the target must not require such libraries at all. For instance, rustc built for the target may depend on a common proprietary C runtime library or console output library, but must not depend on a proprietary code generation library or code optimization library. Rust’s license permits such combinations, but the Rust project has no interest in maintaining such combinations within the scope of Rust itself, even at tier 3.
Addressed.
> “onerous” here is an intentionally subjective term. At a minimum, “onerous” legal/licensing terms include but are not limited to: non-disclosure requirements, non-compete requirements, contributor license agreements (CLAs) or equivalent, “non-commercial”/“research-only”/etc terms, requirements conditional on the employer or employment of any particular Rust developers, revocable terms, any requirements that create liability for the Rust project or its developers or users, or any requirements that adversely affect the livelihood or prospects of the Rust project or its developers or users.
Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target’s tier status, though they may otherwise participate in discussions.
All of the components are free, open-source software.
> This requirement does not prevent part or all of this policy from being cited in an explicit contract or work agreement (e.g. to implement or maintain support for a target). This requirement exists to ensure that a developer or team responsible for reviewing and approving a target does not face any legal threats or obligations that would prevent them from freely exercising their judgment in such approval, even if such judgment involves subjective matters or goes beyond the letter of these requirements.
Addressed.
> Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions.
This target currently does not support the `std` library, but can fully support the `core` and `alloc` feature-sets. Tested and verified on official hardware with the aid of the SDK above.
> The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running binaries, or running tests (even if they do not pass), the documentation must explain how to run such binaries or tests for the target, using emulation if possible or dedicated hardware if necessary.
Documentation is included, both in this PR's Markdown files, as well as the SDK's repository.
> Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via @) to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages.
This target should not cause issues, as its scope is relatively limited to Sony PlayStation 3 development.
> Backlinks such as those generated by the issue/PR tracker when linking to an issue or PR are not considered a violation of this policy, within reason. However, such messages (even on a separate repository) must not generate notifications to anyone involved with a PR who has not requested such notifications.
Noted.
> Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.
This patch does not touch any other target.
> In particular, this may come up when working on closely related targets, such as variations of the same architecture with different features. Avoid introducing unconditional uses of features that another variation of the target may not have; use conditional compilation or runtime detection, as appropriate, to let each target run code supported by that target.
This target only has one feature, `+altivec`, universally supported on any Sony PlayStation 3 unit.
> Tier 3 targets must be able to produce assembly using at least one of rustc’s supported backends from any host target. (Having support in a fork of the backend is not sufficient, it must be upstream.)
Artifacts built by this target are confirmed to be fully functional on official hardware, once linked with the `mold` linker and patched by the SDK toolchain.
Move rustdoc ui doctests into the right testsuite
When working on https://github.com/rust-lang/rust/pull/161944#discussion_r3886415477, I realized that a lot of doctests in `rustdoc-html` testsuite were not in the correct testsuite, so moving them in the right location.
Because you're the one who made me realize it, here goes @fmease (thanks!) :p
r? @fmease
rustdoc: Take into account edition information for keyword highlighting
Fixes https://github.com/rust-lang/rust/issues/148221.
The only thing that was missing was passing down an `Edition` to the highlighter (and adding tests).
r? @fmease
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
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.
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.
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
`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.
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.
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.