-
Notifications
You must be signed in to change notification settings - Fork 13.4k
async
and other Rust 2018+ keywords not recognized as so in Rustdoc highlighting
#80004
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
@rustbot label +T-rustdoc +A-rustdoc-ui +A-async-await |
@ThePuzzlemaker I think you have the right idea, though someone from the Rustdoc team might also be able to help with the details (cc @jyn514). A PR would be welcome! Feel free to claim the issue with |
@rustbot claim |
Yup, that looks right, good catch! The only tricky thing will be passing in a span in to |
@rustbot release-assignment |
@ThePuzzlemaker where did you get stuck? I might be able to help. |
@ThePuzzlemaker you need to follow the call chain up until you get to somewhere that has a Session. If nothing else, run_renderer has one, but I bet you can get it a lot more easily if you find a function with a context of some kind; then just pass the session as an argument until it gets to where it needs to be. (Alternatively, you could just pass the edition instead.) |
I guess if I just add it to the |
Wait, I'm confused - |
I mean |
It looks like you can change the edition of a code block so I'll just do something like this:
|
Hm, looks like I'm stuck again. I was able to pass an |
I guess I could make a function |
…yn514,petrochenkov Highlight edition-specific keywords correctly in code blocks, accounting for code block edition modifiers Previously, edition-specific keywords (such as `async` and `await`) were not highlighted in code blocks, regardless of what edition was set. With this PR, this issue is fixed. Now, the following behavior happens: - When a code block is explicitly set to edition X, keywords from edition X are highlighted - When a code block is explicitly set to a version that does not contain those keywords from edition X (e.g. edition Y), keywords from edition X are **not** highlighted - When a code block has no explicit edition, keywords from the edition passed via `--edition` to rustdoc are highlighted For example, a project set with `edition = "2015"` in its `Cargo.toml` would not highlight `async`/`await` unless the code block was set to `edition2018`. Additionally, a project set with `edition = "2018"` in its `Cargo.toml` *would* highlight `async`/`await` unless the code block was set to a version that did not contain those keywords (e.g. `edition2015`). This PR fixes rust-lang#80004. r? `@jyn514`
…yn514,petrochenkov Highlight edition-specific keywords correctly in code blocks, accounting for code block edition modifiers Previously, edition-specific keywords (such as `async` and `await`) were not highlighted in code blocks, regardless of what edition was set. With this PR, this issue is fixed. Now, the following behavior happens: - When a code block is explicitly set to edition X, keywords from edition X are highlighted - When a code block is explicitly set to a version that does not contain those keywords from edition X (e.g. edition Y), keywords from edition X are **not** highlighted - When a code block has no explicit edition, keywords from the edition passed via `--edition` to rustdoc are highlighted For example, a project set with `edition = "2015"` in its `Cargo.toml` would not highlight `async`/`await` unless the code block was set to `edition2018`. Additionally, a project set with `edition = "2018"` in its `Cargo.toml` *would* highlight `async`/`await` unless the code block was set to a version that did not contain those keywords (e.g. `edition2015`). This PR fixes rust-lang#80004. r? ```@jyn514```
Uh oh!
There was an error while loading. Please reload this page.
I tried this code:
I expected to see this happen:
async
and other Rust 2018+ keywords are highlighted as my project is set toedition = "2018"
in itsCargo.toml
Instead, this happened: They were not highlighted, but regular keywords (including reserved ones) were.

I believe that the reason why this is happening is this snippet in librustdoc:
rust/src/librustdoc/html/highlight.rs
Lines 292 to 305 in eb4fc71
In this case,
Ident::from_str
will only create a dummy span (which isn't set to 2018 edition), sois_reserved
does not include 2018+ keywords.I would be willing to try to work on a PR to fix this issue if it is deemed worthy.
Meta
Tested
rustc --version --verbose
:stable:
nightly:
Backtrace is not applicable.
The text was updated successfully, but these errors were encountered: