Skip to content

rustdoc: notable trait badge and popover enhancements - #160370

Open
notriddle wants to merge 7 commits into
rust-lang:mainfrom
notriddle:notable-trait-color
Open

notriddle wants to merge 7 commits into
rust-lang:mainfrom
notriddle:notable-trait-color

Conversation

@notriddle

@notriddle notriddle commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

@rustbot

rustbot commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in GUI tests.

cc @GuillaumeGomez

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez, @lolbinarycat

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

@rustbot

rustbot commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

r? @petrochenkov

rustbot has assigned @petrochenkov.
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: compiler
  • compiler expanded to 75 candidates
  • Random selection from 18 candidates

@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-libs Relevant to the library 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 Aug 2, 2026
@notriddle notriddle removed T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 2, 2026
--notable-badge-pink: oklch(0.88 0.21 0);
--notable-badge-red: oklch(0.88 0.21 40);
--notable-badge-orange: oklch(0.88 0.21 70);
--notable-badge-grey: oklch(0.88 0 0);

@GuillaumeGomez GuillaumeGomez Aug 2, 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.

We're now switching to 8 colors?

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 can’t find it in the meeting minutes, but I remember mentioning the possibility of using the ANSI 3-bit color pallet, because it makes both directions of interop easier:

  • terminal apps like rusty-man can display these colors without requiring their own bespoke color theming system
  • anyone adding new themes to rustdoc-html can easily use a terminal color theme as a starting point

Comment thread compiler/rustc_hir/src/attrs/data_structures.rs Outdated
{% if !notable_trait_badges.is_empty() %}
<div class="notable-trait-badge-container">
{% for badge in notable_trait_badges.iter() %}
<a class="notable-trait-badge notable-trait-badge-{{badge.color}}"

@GuillaumeGomez GuillaumeGomez Aug 2, 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.

I feel like this is duplicating information: the parent is already the unique class notable-trait-badge-container and the badge itself already has the notable-trait-badge class, so having notable-trait-badge- seems too much (also maybe we should remove the notable-trait-badge class). What about just keeping the color?

View changes since the review

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.

Oh also, please indent. Makes it simpler to read the template.

Comment thread src/doc/rustdoc/src/unstable-features.md Outdated
border-radius: 6px;
padding: 8px;
}
.notabletrait-badge.light {

@GuillaumeGomez GuillaumeGomez Aug 2, 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.

Same: why changing the color property?

View changes since the review

border-color: #0f1419;
}
/* https://github.com/rust-lang/rust/pull/91480 */
.notabletrait-badge.light.grey {

@GuillaumeGomez GuillaumeGomez Aug 2, 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.

I'm really not sure it's worth it to show people how to add their own colors.

View changes since the review

padding: 0 0.5rem;
border-radius: 0.75rem;
padding: 0 14px;
border-radius: var(--code-block-border-radius);

@GuillaumeGomez GuillaumeGomez Aug 2, 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.

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.

It’s the same padding and border radius as code blocks.

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.

Do we need it to be the same?

@notriddle notriddle Aug 3, 2026

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 wanted the text inside the badge to line up with the text in the code block, because it was almost aligned already.

I’m less picky about the border radius, but I made it the same because I was worried about hitting psychovisual weirdness that makes the text look misaligned even if the ruler says it’s perfect.

--notable-badge-violet: oklch(0.88 0.21 300);
--notable-badge-magenta: oklch(0.88 0.21 320);
--notable-badge-cyan: oklch(0.88 0.21 180);
--notable-badge-transparent: white;

@GuillaumeGomez GuillaumeGomez Aug 2, 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.

I don't think having text floating around is a good idea, especially when it's a color picked by rustdoc automatically...

View changes since the review

@petrochenkov

Copy link
Copy Markdown
Contributor

r? @GuillaumeGomez

@rust-log-analyzer

This comment has been minimized.

Transparent,
}

impl Into<&'static str> for NotableTraitColor {

@ThierryBerger ThierryBerger Aug 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we prefer From ?

Also, should we consider having the opposite direction ? Simplifying the parsing code and grouping similar behaviour in here.

View changes since the review

Comment thread compiler/rustc_middle/src/queries.rs Outdated
/// Determines whether an item is annotated with `#[doc(notable_trait)]`.
query is_doc_notable_trait(def_id: DefId) -> bool {
/// If an item is annotated with `#[doc(notable_trait)]`,
/// returns the color used to render its pill. If the crate specifies

@ThierryBerger ThierryBerger Aug 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it a pill or a badge ? We should have consistent naming

View changes since the review

@rust-bors

This comment has been minimized.

@notriddle notriddle changed the title rustdoc: notable trait badge color attribute rustdoc: notable trait badge and popover enhancements Sep 19, 2026
@rustbot

rustbot commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_ir

cc @jdonszelmann, @JonathanBrouwer

@rustbot

rustbot commented Sep 19, 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.

@rust-log-analyzer

This comment has been minimized.

Add test cases, and the same detailed info block that you get for return
position notable traits.
@notriddle

Copy link
Copy Markdown
Contributor Author

@GuillaumeGomez @ThierryBerger

I've done some tweaks to take into account feedback from these discussions, plus a few things I noticed while looking around the standard library:

  • The popover is now part of the notable traits row. If the notable trait is only implemented for certain generics, or if it has an associated type, you can see it in there. Also, it says "Notable traits" inside the popup, so there's at least something that tells you where this list comes from.
  • The padding and border radius is returned to what the original version used. The left edge of the notable trait badges are aligned with the left edge of the top-doc.
  • The "transparent" color badges now have a border, so they aren't just floating text with nothing around them.
  • The colored badges aren't in the docs any more. Just a list of color names.
  • Formatting fixes: added missing indent to the template, use From instead of Into for the conversion, and using "badge" consistently.

@rust-log-analyzer

This comment has been minimized.

This still produces the feature gate error, so it's fine, but it also
produces the "trait attribute" warning
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-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