Skip to content

union and other weak keywords are not highlighted correctly in rustdoc code blocks #85016

Closed
@ThePuzzlemaker

Description

@ThePuzzlemaker

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:

/// ```rust ignore
/// async fn quux() {} // rust 2018+ keyword, fixed in #80226
///
/// #[repr(C)]
/// union ExampleUnion { // weak keyword, not working
///     foo: u8,
///     bar: u16
/// }
///
/// fn bar () {
///     let mut a = 0;
///     abstract blah; // reserved keyword, working
/// }
pub fn foo() {}

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 code

Instead, this happened: They were not highlighted, but regular keywords including reserved ones and edition 2018+ ones (fixed in #80266) were.
image

The issue is here, because Ident::is_reserved does not check for weak keyword status:

fn get_real_ident_class(text: &str, edition: Edition) -> Class {
match text {
"ref" | "mut" => Class::RefKeyWord,
"self" | "Self" => Class::Self_,
"false" | "true" => Class::Bool,
_ if Symbol::intern(text).is_reserved(|| edition) => Class::KeyWord,
_ => Class::Ident,
}
}

Meta

Tested

rustc --version --verbose:
stable:

rustc 1.52.0 (88f19c6da 2021-05-03)
binary: rustc
commit-hash: 88f19c6dab716c6281af7602e30f413e809c5974
commit-date: 2021-05-03
host: x86_64-unknown-linux-gnu
release: 1.52.0
LLVM version: 12.0.0

nightly:

rustc 1.54.0-nightly (bacf770f2 2021-05-05)
binary: rustc
commit-hash: bacf770f2983a52f31e3537db5f0fe1ef2eaa874
commit-date: 2021-05-05
host: x86_64-unknown-linux-gnu
release: 1.54.0-nightly
LLVM version: 12.0.0

Backtrace is not applicable.

@rustbot claim
@rustbot modify labels: +A-rustdoc +A-rustdoc-ui +C-bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-rustdoc-uiArea: Rustdoc UI (generated HTML)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