Open
Description
At the moment, rustdoc uses only the lexer to do syntax highlighting (#75775). This has the benefits of simplicity & performance, and gets us 80% of the way quality wise, but it is not perfect. For example, lexer-based highlighting can't properly detect contextual keywords, glued/split operators, etc.
We can and probably should make this better, though this requires a lot of fundamental work on IDE-ification of the compiler
- the simple thing we can do is to use better heuristic to glue token (Use rustc_lexer for rustdoc syntax highlighting #75775 (comment))
- the next step is to use parser & syntax tree for highlighting. This probably should be done after parser library-ification (Form t-compiler/wg-parser-library compiler-team#338)
- the final step is to overlay semantic info, so that references are colored the same way as the things they refer to (which includes "clicking on the name should open the name's definition" as a subtask). This is already available in rust-analyzer, but will take some time to percolate to rustdoc