Skip to content

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

Closed

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

Activity

  1. added
    T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.
    A-rustdoc-uiArea: Rustdoc UI (generated HTML)
    C-bugCategory: This is a bug.
    on May 7, 2021
  2. ThePuzzlemaker commented on May 7, 2021

    @ThePuzzlemaker
    ContributorAuthor

    Hm, now that I think about it, this might be a bit harder to solve than I initially thought, as weak keywords require a bit of syntactic context to find out whether they're being used as keywords or not. Thus, the logic for weak keywords will probably have to be further up the chain than get_real_ident_class. I'll try what I can to get this to work, but if I can't get a working solution I'll either put something on Zulip or release assignment of this issue.

  3. removed their assignment
    on Sep 6, 2021
  4. added a commit that references this issue on Sep 29, 2021
  5. added a commit that references this issue on Sep 30, 2021
  6. GuillaumeGomez commented on Feb 19, 2022

    @GuillaumeGomez
    Member

    The union keyword highlighting has been fixed in #87428. Please open another issue for the other "weak" keywords so we can fix them as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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