From 5dc184c1ae3ca7140a92137e8a2c0332c110f75c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 11 Aug 2026 17:57:15 +0200 Subject: [PATCH] rustdoc: Fix invalid CSS classes generated for notable items --- src/librustdoc/html/templates/print_item.html | 2 +- tests/rustdoc-gui/notable-traits.goml | 14 ++++++++++++++ tests/rustdoc-gui/src/test_docs/lib.rs | 9 +++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/rustdoc-gui/notable-traits.goml diff --git a/src/librustdoc/html/templates/print_item.html b/src/librustdoc/html/templates/print_item.html index 71764832abb45..4a257923dc53c 100644 --- a/src/librustdoc/html/templates/print_item.html +++ b/src/librustdoc/html/templates/print_item.html @@ -23,7 +23,7 @@

{% if !notable_trait_badges.is_empty() %}
{% for badge in notable_trait_badges.iter() %} - {{badge.name}} {% endfor %} diff --git a/tests/rustdoc-gui/notable-traits.goml b/tests/rustdoc-gui/notable-traits.goml new file mode 100644 index 0000000000000..f31b83e12edf0 --- /dev/null +++ b/tests/rustdoc-gui/notable-traits.goml @@ -0,0 +1,14 @@ +// This test ensures that the notable trait badges are correctly rendered. +go-to: "file://" + |DOC_PATH| + "/test_docs/notable/struct.Wrapper.html" +show-text: true +store-css: (".notable-trait-badge-container", {"background-color": background_color}) +// The background color should be different. +assert-css-false: (".notable-trait-badge-container > a", {"background-color": |background_color|}) + +store-css: ("#trait-implementations", {"color": text_color}) +assert-css: (".notable-trait-badge-container > a", { + // The color should be the same as the "main color". + "color": |text_color|, + // Checking some additional CSS values. + "border-radius": "12px", +}) diff --git a/tests/rustdoc-gui/src/test_docs/lib.rs b/tests/rustdoc-gui/src/test_docs/lib.rs index bfdbe65f147f4..2bba2ac101544 100644 --- a/tests/rustdoc-gui/src/test_docs/lib.rs +++ b/tests/rustdoc-gui/src/test_docs/lib.rs @@ -13,6 +13,7 @@ #![feature(macro_attr)] #![feature(macro_derive)] #![feature(negative_impls)] +#![feature(doc_notable_trait)] /*! Enable the feature some-feature to enjoy @@ -813,3 +814,11 @@ pub mod tyalias { pub type Y = X; } + +pub mod notable { + #[doc(notable_trait)] + pub trait Labeled {} + + pub struct Wrapper; + impl Labeled for Wrapper {} +}