-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
union
and other weak keywords are not highlighted correctly in rustdoc code blocks
#85016
Comments
Hm, now that I think about it, this might be a bit harder to solve than I initially thought, as weak keywords require a bit of syntactic context to find out whether they're being used as keywords or not. Thus, the logic for weak keywords will probably have to be further up the chain than |
…r=notriddle Fix union keyword highlighting in rustdoc HTML sources I followed this logic: if I find an ident "union", I check if it followed by another ident or not. If it's the case, then I consider this is a keyword because it's declaring a union type. To do so I created a new Iterator which allows to peek the next items without moving the current iterator position. This is part of rust-lang#85016. If the fix makes sense, I'll extend it to other weak keywords (the issue only mentions they exist but https://doc.rust-lang.org/nightly/reference/keywords.html#weak-keywords only talks about `dyn` and `'static` so not sure if there is anything else to be done?). cc `@notriddle` (you're one of the last ones who worked on this part of rustdoc so here you go 😉 ) r? `@jyn514`
…r=notriddle Fix union keyword highlighting in rustdoc HTML sources I followed this logic: if I find an ident "union", I check if it followed by another ident or not. If it's the case, then I consider this is a keyword because it's declaring a union type. To do so I created a new Iterator which allows to peek the next items without moving the current iterator position. This is part of rust-lang#85016. If the fix makes sense, I'll extend it to other weak keywords (the issue only mentions they exist but https://doc.rust-lang.org/nightly/reference/keywords.html#weak-keywords only talks about `dyn` and `'static` so not sure if there is anything else to be done?). cc `@notriddle` (you're one of the last ones who worked on this part of rustdoc so here you go 😉 ) r? `@jyn514`
The |
This issue is quite similar to #80004, which I also worked on, so I have a general idea of how it might be able to be fixed.
I tried this code:
I expected to see this happen:
union
is highlighted, even though it is a weak keyword, as it is acting as a keyword in that location in the codeInstead, this happened: They were not highlighted, but regular keywords including reserved ones and edition 2018+ ones (fixed in #80266) were.
The issue is here, because
Ident::is_reserved
does not check for weak keyword status:rust/src/librustdoc/html/highlight.rs
Lines 139 to 147 in 8db7973
Meta
Tested
rustc --version --verbose
:stable:
nightly:
Backtrace is not applicable.
@rustbot claim
@rustbot modify labels: +A-rustdoc +A-rustdoc-ui +C-bug
The text was updated successfully, but these errors were encountered: