Skip to content

fix: Parse cfg_attr and cfg specially#21965

Merged
ChayimFriedman2 merged 1 commit intorust-lang:masterfrom
ChayimFriedman2:refactor-cfg-attr
Apr 11, 2026
Merged

fix: Parse cfg_attr and cfg specially#21965
ChayimFriedman2 merged 1 commit intorust-lang:masterfrom
ChayimFriedman2:refactor-cfg-attr

Conversation

@ChayimFriedman2
Copy link
Copy Markdown
Contributor

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.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 6, 2026
Copy link
Copy Markdown
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I like this change a lot!

View changes since this review

@Veykril Veykril added this pull request to the merge queue Apr 11, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 11, 2026
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`.
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 11, 2026

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.

@ChayimFriedman2 ChayimFriedman2 added this pull request to the merge queue Apr 11, 2026
Merged via the queue into rust-lang:master with commit 09dc7ac Apr 11, 2026
17 checks passed
@ChayimFriedman2 ChayimFriedman2 deleted the refactor-cfg-attr branch April 11, 2026 20:35
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 11, 2026
@Veykril
Copy link
Copy Markdown
Member

Veykril commented Apr 12, 2026

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) 🤔

Comment on lines 113 to 129
#[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",
Copy link
Copy Markdown
Member

@Veykril Veykril Apr 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View changes since the review

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants