Rustdoc label badge for notable traits - #157058
Conversation
|
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 |
|
r? @fmease rustbot has assigned @fmease. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
I would generated the color hash from the trait path (so |
|
|
||
| let Some(impls) = cx.cache().impls.get(&did) else { return Vec::new() }; | ||
|
|
||
| let mut out: Vec<LabelTraitInfo> = impls |
There was a problem hiding this comment.
Instead of using a Vec, would be better to use a BTreeMap. It's sorted on insert and prevents duplications.
There was a problem hiding this comment.
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.
f478afa to
5b47394
Compare
|
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. |
|
With my changes, it now looks like this:
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. |
This comment has been minimized.
This comment has been minimized.
114fadf to
493ed4a
Compare
|
Nice, thanks @GuillaumeGomez ; your changes look good to me, I agree with restricting users to the provided set of colors as a follow up. |
|
Let's do it like this then. Thanks a lot for your work. Let's approve this. :) @bors r+ rollup |
…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)
…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)
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.



View all comments
its full pathShould the following be out of scope ?
#[doc(notable_trait(color="0xff0000")])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:

with chroma 0.090:

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