Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add color on item name in item declaration #117643

Closed

Conversation

GuillaumeGomez
Copy link
Member

Fixes #117555.

I'm really not convinced this is a good idea. It does put more colors, but I'm not sure it's adding any value. We have two different color systems: one for source codes and one for documentation. Item declaration is actually using the same system as "documentation", so only highlighting links.

So in this draft, I generated an empty link on the item name to add some color, but again, really not convinced by this approach...

You can test it here.

Some screenshots:

image

image

image

@rustbot
Copy link
Collaborator

rustbot commented Nov 6, 2023

r? @notriddle

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Nov 6, 2023
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-15 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
##[group]Testing stage2 compiletest suite=rustdoc mode=rustdoc (x86_64-unknown-linux-gnu)
warning: `tidy` is not installed; diffs will not be generated

running 671 tests
iF..................F...............................F......F..........F.F...............  88/671
.........i................................................................F............F 176/671
......................................F.........F..........F.FF.........F............... 264/671
........................................................................................ 440/671
........................................................................................ 440/671
......F.i............................................F.................................. 528/671
........................i.F.......F..........F.......................................... 616/671
........................F........................F...F.
failures:

---- [rustdoc] tests/rustdoc/array-links.rs stdout ----


error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/array-links" "/checkout/tests/rustdoc/array-links.rs"
--- expected ---


<code>pub fn alpha() -&gt; &amp;'static [<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.u32.html">u32</a>; <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">1</a>]</code>


--- actual ---


<code>pub fn <a class="fn" href="#">alpha</a>() -&gt; &amp;'static [<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.u32.html">u32</a>; <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">1</a>]</code>
--- expected ---


<code>pub fn beta&lt;T&gt;() -&gt; &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">[T; 1]</a></code>

--- actual ---


<code>pub fn <a class="fn" href="#">beta</a>&lt;T&gt;() -&gt; &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">[T; 1]</a></code>
--- expected ---


<code>pub fn gamma() -&gt; <a class="struct" href="struct.MyBox.html" title="struct foo::MyBox">MyBox</a>&lt;[<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.u32.html">u32</a>; <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">1</a>]&gt;</code>

--- actual ---


<code>pub fn <a class="fn" href="#">gamma</a>() -&gt; <a class="struct" href="struct.MyBox.html" title="struct foo::MyBox">MyBox</a>&lt;[<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.u32.html">u32</a>; <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">1</a>]&gt;</code>
--- expected ---


<code>pub fn delta&lt;T&gt;() -&gt; <a class="struct" href="struct.MyBox.html" title="struct foo::MyBox">MyBox</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">[T; 1]</a>&gt;</code>

--- actual ---


<code>pub fn <a class="fn" href="#">delta</a>&lt;T&gt;() -&gt; <a class="struct" href="struct.MyBox.html" title="struct foo::MyBox">MyBox</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.array.html">[T; 1]</a>&gt;</code>
--- stderr -------------------------------
--- stderr -------------------------------
text: 'pub fn ' != "pub fn alpha() -> &'static ["
children 1 do not match: code
7: @snapshot check failed
 Actual snapshot value is different than expected
 // @snapshot link_slice_u32 - '//pre[@class="rust item-decl"]/code'
text: 'pub fn ' != "pub fn beta<T>() -> &'static "
children 1 do not match: code
13: @snapshot check failed
 Actual snapshot value is different than expected
 // @snapshot link_slice_generic - '//pre[@class="rust item-decl"]/code'
text: 'pub fn ' != 'pub fn gamma() -> '
children 1 do not match: code
19: @snapshot check failed
 Actual snapshot value is different than expected
 // @snapshot link_box_u32 - '//pre[@class="rust item-decl"]/code'
text: 'pub fn ' != 'pub fn delta<T>() -> '
children 1 do not match: code
25: @snapshot check failed
 Actual snapshot value is different than expected
 // @snapshot link_box_generic - '//pre[@class="rust item-decl"]/code'
Encountered 4 errors
------------------------------------------



---- [rustdoc] tests/rustdoc/async-fn.rs stdout ----

error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/async-fn" "/checkout/tests/rustdoc/async-fn.rs"
--- stderr -------------------------------
53: @has check failed
53: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//pre[@class="rust item-decl"]' 'pub async fn const_generics<const N: usize>(_: impl Trait<N>)'
70: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//pre[@class="rust item-decl"]' "pub async fn lifetime_for_trait(foo: &str) -> Box<dyn Bar + '_>"
73: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//pre[@class="rust item-decl"]' "pub async fn elided_in_input_trait(t: impl Pattern<'_>)"
94: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//pre[@class="rust item-decl"]' "pub async fn named_trait<'a, 'b>(foo: impl Pattern<'a>) -> impl Pattern<'b>"
Encountered 4 errors
------------------------------------------



---- [rustdoc] tests/rustdoc/const-intrinsic.rs stdout ----

error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/const-intrinsic" "/checkout/tests/rustdoc/const-intrinsic.rs"
--- stderr -------------------------------
9: @has check failed
9: @has check failed
 `XPATH PATTERN` did not match
     // @has - '//pre[@class="rust item-decl"]' 'pub const unsafe extern "rust-intrinsic" fn transmute<T, U>(_: T) -> U'
15: @has check failed
 `XPATH PATTERN` did not match
     // @has - '//pre[@class="rust item-decl"]' 'pub unsafe extern "rust-intrinsic" fn unreachable() -> !'
Encountered 2 errors
------------------------------------------



---- [rustdoc] tests/rustdoc/const-generics/const-generics-docs.rs stdout ----

error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/const-generics/const-generics-docs" "/checkout/tests/rustdoc/const-generics/const-generics-docs.rs"
--- stderr -------------------------------
6: @has check failed
6: @has check failed
 `XPATH PATTERN` did not match
 // @has foo/fn.extern_fn.html '//pre[@class="rust item-decl"]' 'pub fn extern_fn<const N: usize>() -> impl Iterator<Item = [u8; N]>'
65: @has check failed
 `XPATH PATTERN` did not match
 // @has foo/fn.a_sink.html '//pre[@class="rust item-decl"]' 'pub async fn a_sink<const N: usize>(v: [u8; N]) -> impl Trait<N>'
Encountered 2 errors
------------------------------------------



---- [rustdoc] tests/rustdoc/decl-trailing-whitespace.rs stdout ----

error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/decl-trailing-whitespace" "/checkout/tests/rustdoc/decl-trailing-whitespace.rs"
--- expected ---


<code>pub trait Write {
    // Required methods
    fn <a href="#tymethod.poll_write" class="fn">poll_write</a>(
        self,
        cx: &amp;mut <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,
        buf: &amp;mut [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>]
    ) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>&gt;&gt;;
<span class="item-spacer" />    fn <a href="#tymethod.poll_flush" class="fn">poll_flush</a>(self, cx: &amp;mut <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>&gt;&gt;;
<span class="item-spacer" />    fn <a href="#tymethod.poll_close" class="fn">poll_close</a>(self, cx: &amp;mut <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>&gt;&gt;;
    // Provided method
    // Provided method
    fn <a href="#method.poll_write_vectored" class="fn">poll_write_vectored</a>(
        self,
        cx: &amp;mut <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,
        bufs: &amp;[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>]
    ) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>&gt;&gt; { ... }
}</code>

--- actual ---


<code>pub trait <a class="trait" href="#">Write</a> {
    // Required methods
    fn <a href="#tymethod.poll_write" class="fn">poll_write</a>(
        self,
        cx: &amp;mut <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,
        buf: &amp;mut [<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>]
    ) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>&gt;&gt;;
<span class="item-spacer" />    fn <a href="#tymethod.poll_flush" class="fn">poll_flush</a>(self, cx: &amp;mut <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>&gt;&gt;;
<span class="item-spacer" />    fn <a href="#tymethod.poll_close" class="fn">poll_close</a>(self, cx: &amp;mut <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.unit.html">()</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>&gt;&gt;;
    // Provided method
    // Provided method
    fn <a href="#method.poll_write_vectored" class="fn">poll_write_vectored</a>(
        self,
        cx: &amp;mut <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,
        bufs: &amp;[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>]
    ) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/option/enum.Option.html" title="enum core::option::Option">Option</a>&lt;<a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, <a class="struct" href="struct.Error.html" title="struct foo::Error">Error</a>&gt;&gt; { ... }
}</code>
--- stderr -------------------------------
--- stderr -------------------------------
text: 'pub trait ' != 'pub trait Write {\n    // Required methods\n    fn '
children 1 do not match: code
10: @snapshot check failed
 Actual snapshot value is different than expected
     // @snapshot 'declaration' - '//*[@class="rust item-decl"]//code'
Encountered 1 errors
------------------------------------------



---- [rustdoc] tests/rustdoc/decl-line-wrapping-empty-arg-list.rs stdout ----

error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/decl-line-wrapping-empty-arg-list" "/checkout/tests/rustdoc/decl-line-wrapping-empty-arg-list.rs"
--- expected ---


<pre class="rust item-decl"><code>pub fn create(
) -&gt; <a class="struct" href="struct.Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000.html" title="struct decl_line_wrapping_empty_arg_list::Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000">Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000</a></code></pre>

--- actual ---


<pre class="rust item-decl"><code>pub fn <a class="fn" href="#">create</a>(
) -&gt; <a class="struct" href="struct.Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000.html" title="struct decl_line_wrapping_empty_arg_list::Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000">Padding00000000000000000000000000000000000000000000000000000000000000000000000000000000</a></code></pre>
--- stderr -------------------------------
--- stderr -------------------------------
text: 'pub fn ' != 'pub fn create(\n) -> '
children 1 do not match: code
children 1 do not match: pre
9: @snapshot check failed
 Actual snapshot value is different than expected
 // @snapshot decl - '//pre[@class="rust item-decl"]'
Encountered 1 errors
------------------------------------------



---- [rustdoc] tests/rustdoc/ffi.rs stdout ----

error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/ffi" "/checkout/tests/rustdoc/ffi.rs"
--- stderr -------------------------------
6: @has check failed
6: @has check failed
 `XPATH PATTERN` did not match
 // @has ffi/fn.foreigner.html //pre 'pub unsafe extern "C" fn foreigner(cold_as_ice: u32)'
10: @has check failed
 `XPATH PATTERN` did not match
     // @has ffi/fn.another.html //pre 'pub unsafe extern "C" fn another(cold_as_ice: u32)'
Encountered 2 errors
------------------------------------------



---- [rustdoc] tests/rustdoc/generic-associated-types/issue-94683.rs stdout ----

error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/generic-associated-types/issue-94683" "/checkout/tests/rustdoc/generic-associated-types/issue-94683.rs"
--- stderr -------------------------------
--- stderr -------------------------------
10: @hasraw check failed
 `PATTERN` did not match
 // @hasraw - "pub type T = "
Encountered 1 errors
------------------------------------------



---- [rustdoc] tests/rustdoc/inherent-projections.rs stdout ----

error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/inherent-projections" "/checkout/tests/rustdoc/inherent-projections.rs"
--- stderr -------------------------------
16: @has check failed
16: @has check failed
 `XPATH PATTERN` did not match
 // @has 'inherent_projections/fn.user.html' '//pre[@class="rust item-decl"]' "user(_: for<'a> fn(_: Carrier<'a>::Focus))"
Encountered 1 errors
------------------------------------------



---- [rustdoc] tests/rustdoc/inline_cross/attributes.rs stdout ----

error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/inline_cross/attributes" "/checkout/tests/rustdoc/inline_cross/attributes.rs"
--- stderr -------------------------------
6: @has check failed
6: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//*[@class="rust item-decl"]//*[@class="code-attribute"]' '#[non_exhaustive]'
Encountered 1 errors
------------------------------------------



---- [rustdoc] tests/rustdoc/inline_cross/dyn_trait.rs stdout ----

error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/inline_cross/dyn_trait" "/checkout/tests/rustdoc/inline_cross/dyn_trait.rs"
--- stderr -------------------------------
139: @has check failed
139: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//pre[@class="rust item-decl"]' "apit_rpit(o: impl Outer<dyn Inner>) -> impl Outer<dyn Inner>"
Encountered 1 errors
------------------------------------------



---- [rustdoc] tests/rustdoc/inline_cross/impl_trait.rs stdout ----

error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/inline_cross/impl_trait" "/checkout/tests/rustdoc/inline_cross/impl_trait.rs"
--- stderr -------------------------------
20: @has check failed
20: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//pre[@class="rust item-decl"]' "_x: impl Iterator<Item = impl Iterator<Item = u8>> + Clone)"
Encountered 1 errors
------------------------------------------



---- [rustdoc] tests/rustdoc/inline_cross/impl-sized.rs stdout ----

error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/inline_cross/impl-sized" "/checkout/tests/rustdoc/inline_cross/impl-sized.rs"
--- stderr -------------------------------
11: @has check failed
11: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//pre[@class="rust item-decl"]' "sized_outlives<'a>(x: impl Sized + 'a) -> impl Sized + 'a"
20: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//pre[@class="rust item-decl"]' "debug_maybe_sized(x: &(impl Debug + ?Sized)) -> &(impl Debug + ?Sized)"
25: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//pre[@class="rust item-decl"]' "maybe_sized_outlives<'t>(x: &(impl ?Sized + 't)) -> &(impl ?Sized + 't)"
Encountered 3 errors
------------------------------------------



---- [rustdoc] tests/rustdoc/inline_cross/repr.rs stdout ----

error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/inline_cross/repr" "/checkout/tests/rustdoc/inline_cross/repr.rs"
--- stderr -------------------------------
11: @has check failed
11: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//*[@class="rust item-decl"]//*[@class="code-attribute"]' '#[repr(C, align(8))]'
14: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//*[@class="rust item-decl"]//*[@class="code-attribute"]' '#[repr(simd, packed(2))]'
17: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//*[@class="rust item-decl"]//*[@class="code-attribute"]' '#[repr(transparent)]'
20: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//*[@class="rust item-decl"]//*[@class="code-attribute"]' '#[repr(isize)]'
23: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//*[@class="rust item-decl"]//*[@class="code-attribute"]' '#[repr(u8)]'
35: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//*[@class="rust item-decl"]//*[@class="code-attribute"]' '#[repr(transparent)]'
Encountered 6 errors
------------------------------------------



---- [rustdoc] tests/rustdoc/legacy-const-generic.rs stdout ----

error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/legacy-const-generic" "/checkout/tests/rustdoc/legacy-const-generic.rs"
--- stderr -------------------------------
5: @has check failed
5: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//pre[@class="rust item-decl"]' 'fn foo(x: usize, const Y: usize, z: usize) -> [usize; 3]'
12: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//pre[@class="rust item-decl"]' 'fn bar(x: usize, const Y: usize, const Z: usize) -> [usize; 3]'
Encountered 2 errors
------------------------------------------



---- [rustdoc] tests/rustdoc/nested-modules.rs stdout ----

error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/nested-modules" "/checkout/tests/rustdoc/nested-modules.rs"
--- stderr -------------------------------
--- stderr -------------------------------
10: @hasraw check failed
 `PATTERN` did not match
         // @hasraw aCrate/a_nested_module/fn.a_nested_public_function.html 'pub fn a_nested_public_function()'
14: @hasraw check failed
 `PATTERN` did not match
         // @hasraw aCrate/a_nested_module/fn.another_nested_public_function.html 'pub fn another_nested_public_function()'
Encountered 2 errors
------------------------------------------



---- [rustdoc] tests/rustdoc/safe-intrinsic.rs stdout ----

error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/safe-intrinsic" "/checkout/tests/rustdoc/safe-intrinsic.rs"
--- stderr -------------------------------
14: @has check failed
14: @has check failed
 `XPATH PATTERN` did not match
     // @has - '//pre[@class="rust item-decl"]' 'pub unsafe extern "rust-intrinsic" fn unreachable() -> !'
Encountered 1 errors
------------------------------------------



---- [rustdoc] tests/rustdoc/repr.rs stdout ----

error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/repr" "/checkout/tests/rustdoc/repr.rs"
--- stderr -------------------------------
13: @has check failed
13: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//*[@class="rust item-decl"]//*[@class="code-attribute"]' '#[repr(transparent)]'
22: @has check failed
 `XPATH PATTERN` did not match
 // @has - '//*[@class="rust item-decl"]//*[@class="code-attribute"]' '#[repr(transparent)]'
Encountered 2 errors
------------------------------------------



---- [rustdoc] tests/rustdoc/slice-links.rs stdout ----

error: htmldocck failed!
status: exit status: 1
command: "/usr/bin/python3" "/checkout/src/etc/htmldocck.py" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc/slice-links" "/checkout/tests/rustdoc/slice-links.rs"
--- expected ---


<code>pub fn alpha() -&gt; &amp;'static [<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.u32.html">u32</a>]</code>

--- actual ---


<code>pub fn <a class="fn" href="#">alpha</a>() -&gt; &amp;'static [<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.u32.html">u32</a>]</code>
--- expected ---


<code>pub fn beta&lt;T&gt;() -&gt; &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">[T]</a></code>

--- actual ---


<code>pub fn <a class="fn" href="#">beta</a>&lt;T&gt;() -&gt; &amp;'static <a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">[T]</a></code>
--- expected ---


<code>pub fn gamma() -&gt; <a class="struct" href="struct.MyBox.html" title="struct foo::MyBox">MyBox</a>&lt;[<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.u32.html">u32</a>]&gt;</code>

--- actual ---


<code>pub fn <a class="fn" href="#">gamma</a>() -&gt; <a class="struct" href="struct.MyBox.html" title="struct foo::MyBox">MyBox</a>&lt;[<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.u32.html">u32</a>]&gt;</code>
--- expected ---


<code>pub fn delta&lt;T&gt;() -&gt; <a class="struct" href="struct.MyBox.html" title="struct foo::MyBox">MyBox</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">[T]</a>&gt;</code>

--- actual ---


<code>pub fn <a class="fn" href="#">delta</a>&lt;T&gt;() -&gt; <a class="struct" href="struct.MyBox.html" title="struct foo::MyBox">MyBox</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/core/primitive.slice.html">[T]</a>&gt;</code>
--- stderr -------------------------------
--- stderr -------------------------------
text: 'pub fn ' != "pub fn alpha() -> &'static ["
children 1 do not match: code
7: @snapshot check failed
 Actual snapshot value is different than expected
 // @snapshot link_slice_u32 - '//pre[@class="rust item-decl"]/code'
text: 'pub fn ' != "pub fn beta<T>() -> &'static "
children 1 do not match: code
13: @snapshot check failed
 Actual snapshot value is different than expected
 // @snapshot link_slice_generic - '//pre[@class="rust item-decl"]/code'
text: 'pub fn ' != 'pub fn gamma() -> '
children 1 do not match: code
19: @snapshot check failed

@Wilfred
Copy link
Contributor

Wilfred commented Nov 6, 2023

Stupid question: why do we have two different colour systems? What's stopping us rendering all the 'documentation' system the same way as source code?

(Full disclosure: I've been helping maintain the VS Code syntax highlighter for Rust recently, so I might be extra sensitive to highlighting inconsistencies.)

@PatchMixolydic
Copy link
Contributor

This doesn't seem to be working for macros.

std::pin::pin!:
image

std::println!:
image

@GuillaumeGomez
Copy link
Member Author

The macros are the exceptions: they use code highlighting and not doc highlighting.

Stupid question: why do we have two different colour systems? What's stopping us rendering all the 'documentation' system the same way as source code?

(Full disclosure: I've been helping maintain the VS Code syntax highlighter for Rust recently, so I might be extra sensitive to highlighting inconsistencies.)

In documentation, we want to put more importance not on keywords but on items name (which you can click most of the time). You don't read documentation the same you read source code, hence why we have two different colour systems.

@Wilfred
Copy link
Contributor

Wilfred commented Nov 7, 2023

we want to put more importance not on keywords but on items name (which you can click most of the time)

Gotcha, that makes sense. So the goal is to distinguish examples (full highlighting) with prose that has clickable links?

Screenshot 2023-11-07 at 09 59 33

I see new, Vec and Global are links here. I agree that highlighting pub const would be distracting.

Screenshot 2023-11-07 at 10 01 27

That makes total sense: in the header here you absolutely want to be able click Global and Allocator. The surprising thing is the background colour on the item declaration, despite using the more minimal documentation highlighter.

I guess options might be:

(1) Add comment highlighting to the documentation highlighter. I think this would help users read the declaration, because it makes the rest of the declaration more prominent.

(2) Add a third highlighter, 'full highlighting but with links'. We could use it for declarations, and maybe even code snippets and highlighted source code like https://doc.rust-lang.org/src/alloc/vec/mod.rs.html too. Racket does this, and it makes the docs super easy to navigate: https://docs.racket-lang.org/guide/Lists__Iteration__and_Recursion.html#%28part._.Predefined_.List_.Loops%29

If these seem reasonable, I'm also willing to help if you have code pointers :)

@GuillaumeGomez
Copy link
Member Author

This is a very nice write-up. Adding comment highlighting seems like the best choice (ie, dimming it out a bit to give it less importance?)

(2) Add a third highlighter, 'full highlighting but with links'. We could use it for declarations, and maybe even code snippets and highlighted source code like https://doc.rust-lang.org/src/alloc/vec/mod.rs.html too. Racket does this, and it makes the docs super easy to navigate: https://docs.racket-lang.org/guide/Lists__Iteration__and_Recursion.html#%28part._.Predefined_.List_.Loops%29

I'm not sure to fully understand what you're suggesting here. By code snippets you mean code in paragraph like this one? If so, we definitely don't want to add highlighting for that because we can't ever be sure what language this is and if the snippet is actually complete.

The code examples and source code pages are already highlighted, so not sure what you mean there either.

In any case, having highlighting for comments in item declarations is easy to do: wrap the text inside <span class="comment">text</span> and it's done, CSS is already done. Which gives:

image

The "tricky" part is to find where the comments are generated (a grep will find that easily) and to not forget any kind comments in the types declaration. It's the same files that are updated in this PR. Want to send a PR for that? :)

Closing this PR in any case.

@GuillaumeGomez GuillaumeGomez deleted the item-decl-more-color branch November 8, 2023 20:00
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 3, 2023
…g-item-decl, r=notriddle

[rustdoc] Add highlighting for comments in items declaration

Fixes rust-lang#117555.

So after the discussion in rust-lang#117643, the outcome was that having the comments in the item declaration at the same level (in term of color) as the rest of the code was actually a bit distracting and could be improved.

The current highlighting color for comments is "lighter" than the rest and I think it fits perfectly to improve the current situation. With this, we now have different "levels" which makes it easier to read and filter out what we want when reading the items declaration.

Here's a screenshot:

![image](https://github.com/rust-lang/rust/assets/3050060/dbd98029-e98b-4997-9a89-6b823eaac9a4)

r? `@notriddle`
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Dec 3, 2023
Rollup merge of rust-lang#117869 - GuillaumeGomez:comment-highlighting-item-decl, r=notriddle

[rustdoc] Add highlighting for comments in items declaration

Fixes rust-lang#117555.

So after the discussion in rust-lang#117643, the outcome was that having the comments in the item declaration at the same level (in term of color) as the rest of the code was actually a bit distracting and could be improved.

The current highlighting color for comments is "lighter" than the rest and I think it fits perfectly to improve the current situation. With this, we now have different "levels" which makes it easier to read and filter out what we want when reading the items declaration.

Here's a screenshot:

![image](https://github.com/rust-lang/rust/assets/3050060/dbd98029-e98b-4997-9a89-6b823eaac9a4)

r? `@notriddle`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustdoc does not consistently apply syntax highlighting to the item declaration
6 participants