Skip to content

Split MacArgs in two.#104559

Merged
bors merged 1 commit intorust-lang:masterfrom
nnethercote:split-MacArgs
Nov 22, 2022
Merged

Split MacArgs in two.#104559
bors merged 1 commit intorust-lang:masterfrom
nnethercote:split-MacArgs

Conversation

@nnethercote
Copy link
Copy Markdown
Contributor

MacArgs is an enum with three variants: Empty, Delimited, and Eq. It's used in two ways:

  • For representing attribute macro arguments (e.g. in AttrItem), where all three variants are used.
  • For representing function-like macros (e.g. in MacCall and MacroDef), where only the Delimited variant is used.

In other words, MacArgs is used in two quite different places due to them having partial overlap. I find this makes the code hard to read. It also leads to various unreachable code paths, and allows invalid values (such as accidentally using MacArgs::Empty in a MacCall).

This commit splits MacArgs in two:

  • DelimArgs is a new struct just for the "delimited arguments" case. It is now used in MacCall and MacroDef.
  • AttrArgs is a renaming of the old MacArgs enum for the attribute macro case. Its Delimited variant now contains a DelimArgs.

Various other related things are renamed as well.

These changes make the code clearer, avoids several unreachable paths, and disallows the invalid values.

r? @petrochenkov

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

Labels

perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants