Description
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.
The issue is here, because Ident::is_reserved
does not check for weak keyword status:
rust/src/librustdoc/html/highlight.rs
Lines 139 to 147 in 8db7973
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
ThePuzzlemaker commentedon May 7, 2021
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.Rollup merge of rust-lang#87428 - GuillaumeGomez:union-highlighting, …
Rollup merge of rust-lang#87428 - GuillaumeGomez:union-highlighting, …
GuillaumeGomez commentedon Feb 19, 2022
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.