Skip to content

async and other Rust 2018+ keywords not recognized as so in Rustdoc highlighting #80004

Closed
@ThePuzzlemaker

Description

@ThePuzzlemaker

I tried this code:

/// ```rust ignore
/// fn foo(bar: &dyn Baz);
/// async fn quux() {
///     qaz.frobnify().await;
/// }
/// fn bar() {
///     let mut a = 0;
///     abstract blah; /// is a reserved keyword
/// }
/// ```
fn foo() {}

I expected to see this happen: async and other Rust 2018+ keywords are highlighted as my project is set to edition = "2018" in its Cargo.toml

Instead, this happened: They were not highlighted, but regular keywords (including reserved ones) were.
image

I believe that the reason why this is happening is this snippet in librustdoc:

TokenKind::Ident => match text {
"ref" | "mut" => Class::RefKeyWord,
"self" | "Self" => Class::Self_,
"false" | "true" => Class::Bool,
"Option" | "Result" => Class::PreludeTy,
"Some" | "None" | "Ok" | "Err" => Class::PreludeVal,
// Keywords are also included in the identifier set.
_ if Ident::from_str(text).is_reserved() => Class::KeyWord,
_ if self.in_macro_nonterminal => {
self.in_macro_nonterminal = false;
Class::MacroNonTerminal
}
_ => Class::Ident,
},

In this case, Ident::from_str will only create a dummy span (which isn't set to 2018 edition), so is_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:

rustc 1.48.0 (7eac88abb 2020-11-16)
binary: rustc
commit-hash: 7eac88abb2e57e752f3302f02be5f3ce3d7adfb4
commit-date: 2020-11-16
host: x86_64-unknown-linux-gnu
release: 1.48.0
LLVM version: 11.0

nightly:

rustc 1.50.0-nightly (7efc097c4 2020-12-12)
binary: rustc
commit-hash: 7efc097c4fe6e97f54a44cee91c56189e9ddb41c
commit-date: 2020-12-12
host: x86_64-unknown-linux-gnu
release: 1.50.0-nightly

Backtrace is not applicable.

Metadata

Metadata

Labels

A-async-awaitArea: Async & AwaitA-rustdoc-uiArea: Rustdoc UI (generated HTML)AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions