-
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
Fix union keyword highlighting in rustdoc HTML sources #87428
Conversation
Why is rustdoc rewriting its own rust parsing? Can't we use rustc_parser somehow? |
To be confirmed but iirc, last time we checked it was doing too much: unnecessary tokens like whitespaces for example were removed. However, we need them, which is why we have to rely on the |
cc @camelid |
This comment has been minimized.
This comment has been minimized.
Could we modify the parser to not discard the whitespaces somehow as a new mode of operation? |
Again: to be checked. But that'll make the parsing slower overall if the compiler has to discard them every time. We could always add a parameter to allow to keep them around. Not sure if that's something the people in charge of the parser would want? |
593d190
to
b638eb2
Compare
This comment has been minimized.
This comment has been minimized.
b638eb2
to
80abc4d
Compare
This comment has been minimized.
This comment has been minimized.
80abc4d
to
ee38116
Compare
The two people most involved with the parser are @petrochenkov and myself. Personally, if there's no or low perf impact I'd prefer avoiding duplicated logic, and I'm expecting @petrochenkov's concern to be of maintainability. If it can be done cleanly, I would prefer going the single parser way. |
Alright, I'll try to do that as soon as I can! |
Rust-Analyzer has a parser that preserves spaces, and already uses it for syntax highlighting. But can we use it in rust-lang/rust right now? |
I'd prefer to use the existing compiler tools rather than add external ones. |
r? @estebank |
Did I miss anything? |
@bors: r=notriddle |
📌 Commit ee38116 has been approved by |
…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`
⌛ Testing commit ee38116 with merge 874499884d0418da80234d5898c1fead0fa964fe... |
💔 Test failed - checks-actions |
@bors retry |
This comment has been minimized.
This comment has been minimized.
Rollup of 13 pull requests Successful merges: - rust-lang#87428 (Fix union keyword highlighting in rustdoc HTML sources) - rust-lang#88412 (Remove ignore-tidy-undocumented-unsafe from core::slice::sort) - rust-lang#89098 (Fix generics where bounds order) - rust-lang#89232 (Improve help for recursion limit errors) - rust-lang#89294 (:arrow_up: rust-analyzer) - rust-lang#89297 (Remove Never variant from clean::Type enum) - rust-lang#89311 (Add unit assignment to MIR for `asm!()`) - rust-lang#89313 (PassWrapper: handle function rename from upstream D36850) - rust-lang#89315 (Clarify that `CString::from_vec_unchecked` appends 0 byte.) - rust-lang#89335 (Optimize is_sorted for Range and RangeInclusive) - rust-lang#89366 (rustdoc: Remove lazy_static dependency) - rust-lang#89377 (Update cargo) - rust-lang#89378 (Update books) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
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 #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