fix: Parse cfg_attr and cfg specially#21965
Conversation
6756a7b to
5b8512e
Compare
This allows us to simplify expansion of cfg_attr in `expand_cfg_attr()`, and also fixes a bunch of bugs like expansion of `doc = macro!()` inside `cfg_attr`.
5b8512e to
bb17dbe
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
This does have the side effect of highlighting cfg and cfg_attr as keywords now which has me wonder: Should we special case this in highlighting to go back to attribute highlighting OR double down on all builtin attributes, treating them specially as a whole (and think about highlighting for them separately, be it as keywords or not) 🤔 |
| #[doc(alias = "WEAK_KEYWORDS")] | ||
| const CONTEXTUAL_KEYWORDS: &[&str] = | ||
| &["macro_rules", "union", "default", "raw", "dyn", "auto", "yeet", "safe", "bikeshed"]; | ||
| const CONTEXTUAL_KEYWORDS: &[&str] = &[ | ||
| "macro_rules", | ||
| "union", | ||
| "default", | ||
| "raw", | ||
| "dyn", | ||
| "auto", | ||
| "yeet", | ||
| "safe", | ||
| "bikeshed", | ||
| "cfg_attr", | ||
| "cfg", | ||
| ]; | ||
| // keywords we use for special macro expansions | ||
| const CONTEXTUAL_BUILTIN_KEYWORDS: &[&str] = &[ | ||
| "asm", |
There was a problem hiding this comment.
Also realized technically cfg_attr and cfg should go into CONTEXTUAL_BUILTIN_KEYWORDS, it doesn't differ in behavior, but they are not actual contextual keywords as far as the language definition goes.
This allows us to simplify expansion of cfg_attr in
expand_cfg_attr(), and also fixes a bunch of bugs like expansion ofdoc = macro!()insidecfg_attr.