Repository navigation
rustdoc: Fix impl MyTrait for ! syntax highlighting - #166538
BioTomateDE wants to merge 1 commit into
Conversation
|
r? @notriddle rustbot has assigned @notriddle. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Please add a test case to https://github.com/rust-lang/rust/tree/main/tests/rustdoc-html/codeblock ? probably similar implementation to https://github.com/rust-lang/rust/blob/main/tests/rustdoc-html/codeblock/bad-codeblock-syntax.rs |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
c25c89c to
a0b676c
Compare
|
@bors r+ |
…l, r=notriddle rustdoc: Fix `impl MyTrait for !` syntax highlighting Rustdoc's HTML syntax highlighting does not render trait implementations for the never type `!` correctly because it think it's a macro. ## Example https://doc.rust-lang.org/src/core/hash/mod.rs.html#871 <img alt="rustdoc example screenshot" src="https://github.com/user-attachments/assets/fb427962-6a52-40af-b8d1-fadf7d956ba0" /> ## My Fix I modified `src/librustdoc/html/highlight.rs`. It contains a `NON_MACRO_KEYWORDS` list which denotes keywords that should never be treated as a macro (even) when followed by a `!`. As far as I know, keywords are never valid macro identifiers, so I got rid of this list and the corresponding code. Maybe my thought process here was wrong, idk. Alternatively, `NON_MACRO_KEYWORDS` could simply be extended to include the `for` keyword, which would fix also this issue (I think).
|
This is the only PR touching rustdoc, so I presume this is the cause. |
|
This pull request was unapproved. This PR was contained in a rollup (#166768), which was unapproved. |
Rustdoc's HTML syntax highlighting does not render trait implementations for the never type
!correctly because it think it's a macro.Example
https://doc.rust-lang.org/src/core/hash/mod.rs.html#871

My Fix
I modified
src/librustdoc/html/highlight.rs. It contains aNON_MACRO_KEYWORDSlist which denotes keywords that should never be treated as a macro (even) when followed by a!. As far as I know, keywords are never valid macro identifiers, so I got rid of this list and the corresponding code. Maybe my thought process here was wrong, idk.Alternatively,
NON_MACRO_KEYWORDScould simply be extended to include theforkeyword, which would fix also this issue (I think).Credits
I want to thank Discord User
@_madfrogfor helping me find the relevant code (Conversation link)!