Skip to content

Rustdoc label trait feature#157058

Open
ThierryBerger wants to merge 3 commits into
rust-lang:mainfrom
ThierryBerger:rustdoc_label_trait
Open

Rustdoc label trait feature#157058
ThierryBerger wants to merge 3 commits into
rust-lang:mainfrom
ThierryBerger:rustdoc_label_trait

Conversation

@ThierryBerger

@ThierryBerger ThierryBerger commented May 28, 2026

Copy link
Copy Markdown

View all comments

  • Part of Tracking Issue for doc_label_trait #156865
  • reuse notable trait feature to feed badge data
  • render it in html
  • add some html tests
  • Render a color from a hash from its full path
  • 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
Screenshot 2026-05-28 at 14 06 01

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:
badge_high_chroma

with chroma 0.090:
badge_low_chroma

History

Initially, this PR added a new feature "label_trait", it was then decided in rustdoc meeting to reuse current notable_trait feature.

@rustbot

rustbot commented May 28, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez, @lolbinarycat

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-js Area: Rustdoc's JS front-end A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels May 28, 2026
@rustbot

rustbot commented May 28, 2026

Copy link
Copy Markdown
Collaborator

r? @fmease

rustbot has assigned @fmease.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: rustdoc
  • rustdoc expanded to 9 candidates
  • Random selection from GuillaumeGomez, camelid, fmease, lolbinarycat, notriddle

@rust-log-analyzer

This comment has been minimized.

Comment thread src/doc/rustdoc/src/unstable-features.md Outdated
Comment thread src/doc/rustdoc/src/unstable-features.md Outdated
Comment thread src/doc/unstable-book/src/language-features/doc-label_trait.md Outdated
Comment thread src/librustdoc/html/render/print_item.rs
Comment thread compiler/rustc_feature/src/unstable.rs Outdated
@GuillaumeGomez

Copy link
Copy Markdown
Member

Render a color from a hash from DefId -> ⚠️ is that an issue? color won't be stable between releases.

I would generated the color hash from the trait path (so crate::Trait for current crate, etc). Like that it will be stable across releases.

Comment thread src/librustdoc/html/render/mod.rs Outdated
Comment thread src/librustdoc/html/render/mod.rs Outdated
Comment thread src/librustdoc/html/render/mod.rs Outdated

let Some(impls) = cx.cache().impls.get(&did) else { return Vec::new() };

let mut out: Vec<LabelTraitInfo> = impls

@GuillaumeGomez GuillaumeGomez May 28, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using a Vec, would be better to use a BTreeMap. It's sorted on insert and prevents duplications.

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed to do that but then collect it to Vec, keeping this discussion opened as I'm not sure if you meant something else.

Comment thread src/librustdoc/html/render/print_item.rs Outdated
Comment thread src/librustdoc/html/render/mod.rs Outdated
Comment thread src/librustdoc/html/templates/print_item.html Outdated
Comment thread src/librustdoc/html/templates/print_item.html Outdated
Comment thread src/librustdoc/html/templates/print_item.html Outdated
Comment thread src/librustdoc/html/templates/print_item.html Outdated
Comment thread compiler/rustc_passes/src/check_attr.rs Outdated

@Veykril Veykril left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove the two rust-analyzer changes please? They don't do anything as is so they will likely cause unnecessary conflicts for us

View changes since this review

@rust-log-analyzer

This comment has been minimized.

@ThierryBerger ThierryBerger force-pushed the rustdoc_label_trait branch from 2977320 to 6cddf7b Compare May 28, 2026 19:50
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@ThierryBerger ThierryBerger force-pushed the rustdoc_label_trait branch from 60688d1 to 58f56a9 Compare June 5, 2026 13:17
@rustbot

This comment has been minimized.

@fmease fmease assigned GuillaumeGomez and unassigned fmease Jun 5, 2026
@rust-bors

This comment has been minimized.

@rustbot

rustbot commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-rustdoc-js Area: Rustdoc's JS front-end A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants