Skip to content

rustdoc: notable trait badge color attribute - #160370

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

rustdoc: notable trait badge color attribute#160370
notriddle wants to merge 2 commits into
rust-lang:mainfrom
notriddle:notable-trait-color

Conversation

@notriddle

@notriddle notriddle commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Part of #45040

Screenshots

image image image image

@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.

one of the other colors in the list:

<style>
.notabletrait-badge {

@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.

Why changing the appearance of the badge?

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 wanted the text inside the badge to be aligned with the code block below it.

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.

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

Co-authored-by: Guillaume Gomez <contact@guillaume-gomez.fr>
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
   Compiling rustc_next_trait_solver v0.0.0 (/checkout/compiler/rustc_next_trait_solver)
[RUSTC-TIMING] rustc_next_trait_solver test:false 2.032
[RUSTC-TIMING] rustc_target test:false 12.134
   Compiling rustc_hir v0.0.0 (/checkout/compiler/rustc_hir)
error[E0277]: the trait bound `&str: From<&NotableTraitColor>` is not satisfied
   --> compiler/rustc_hir/src/attrs/data_structures.rs:647:26
    |
647 |         f.write_str(self.into())
    |                          ^^^^ the trait `From<&NotableTraitColor>` is not implemented for `&str`
    |
    = note: required for `&NotableTraitColor` to implement `Into<&str>`
help: consider dereferencing here
    |
647 |         f.write_str((*self).into())
    |                     ++    +

For more information about this error, try `rustc --explain E0277`.
[RUSTC-TIMING] rustc_hir test:false 1.706
error: could not compile `rustc_hir` (lib) due to 1 previous error
Bootstrap failed while executing `--stage 2 test --skip tidy --skip intrinsic-test --skip compiler --skip src`

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

/// 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

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