Skip to content

Rustdoc label badge for notable traits - #157058

Merged
rust-bors[bot] merged 12 commits into
rust-lang:mainfrom
ThierryBerger:rustdoc_label_trait
Jul 29, 2026
Merged

Rustdoc label badge for notable traits#157058
rust-bors[bot] merged 12 commits into
rust-lang:mainfrom
ThierryBerger:rustdoc_label_trait

Conversation

@ThierryBerger

@ThierryBerger ThierryBerger commented May 28, 2026

Copy link
Copy Markdown
Contributor

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:
Screenshot 2026-06-30 at 21 57 27

with chroma 0.090:
Screenshot 2026-06-30 at 21 58 38

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 Outdated
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
Contributor 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

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 8, 2026
@rustbot

rustbot commented Jul 28, 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.

@GuillaumeGomez

Copy link
Copy Markdown
Member

With my changes, it now looks like this:

Screenshot From 2026-07-28 22-51-13 Screenshot From 2026-07-28 22-51-18 Screenshot From 2026-07-28 22-51-24

The text color is the same as the main one, so I changed the badges color a bit to match with it.

@ThierryBerger: I don't think we'll allow to set any color we want (because of theme things), only one between the 6 we provide. If it's fine with you, let's do that in a follow-up.

@rust-log-analyzer

This comment has been minimized.

@ThierryBerger

ThierryBerger commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Nice, thanks @GuillaumeGomez ; your changes look good to me, I agree with restricting users to the provided set of colors as a follow up.

@GuillaumeGomez

Copy link
Copy Markdown
Member

Let's do it like this then. Thanks a lot for your work. Let's approve this. :)

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 493ed4a has been approved by GuillaumeGomez

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 29, 2026
rust-bors Bot pushed a commit that referenced this pull request Jul 29, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #158460 (Remove llvm_enzyme feature outside of bootstrap)
 - #159509 (Generate `valid_range`s for enums sign-agnostically)
 - #159632 (CFI: Add support for the adt_const_params feature)
 - #159671 (Add semver check test command for checking API compatibility of stdlib)
 - #157058 (Rustdoc label badge for notable traits)
 - #159717 (Add `-Zimplicit-sysroot-deps`)
 - #159850 (Add regression test for closure in array-length const generic)
 - #159994 (Show jobs where a given test was executed in `test-dashboard`)
 - #160110 (convert rustc_hir::Target inherent methods to From impls)
 - #160123 (add additional license option for third-party dependencies)
 - #160131 (bootstrap: remove temporary bors email lookup)
rust-bors Bot pushed a commit that referenced this pull request Jul 29, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #158460 (Remove llvm_enzyme feature outside of bootstrap)
 - #159509 (Generate `valid_range`s for enums sign-agnostically)
 - #159632 (CFI: Add support for the adt_const_params feature)
 - #159671 (Add semver check test command for checking API compatibility of stdlib)
 - #157058 (Rustdoc label badge for notable traits)
 - #159717 (Add `-Zimplicit-sysroot-deps`)
 - #159850 (Add regression test for closure in array-length const generic)
 - #159994 (Show jobs where a given test was executed in `test-dashboard`)
 - #160110 (convert rustc_hir::Target inherent methods to From impls)
 - #160123 (add additional license option for third-party dependencies)
 - #160131 (bootstrap: remove temporary bors email lookup)
@rust-bors
rust-bors Bot merged commit ee17d0d into rust-lang:main Jul 29, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 29, 2026
rust-timer added a commit that referenced this pull request Jul 29, 2026
Rollup merge of #157058 - ThierryBerger:rustdoc_label_trait, r=GuillaumeGomez

Rustdoc label badge for notable traits

- Part of #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.
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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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