]> git.lizzy.rs Git - rust.git/commit
Split `MacArgs` in two.
authorNicholas Nethercote <n.nethercote@gmail.com>
Fri, 18 Nov 2022 00:24:21 +0000 (11:24 +1100)
committerNicholas Nethercote <n.nethercote@gmail.com>
Mon, 21 Nov 2022 22:04:15 +0000 (09:04 +1100)
commit3e3a4192d8cda0c308ea87b2e8f6f1e8dcc74739
tree5cbe2cba5da6a3eabde9d310eb7c0ac5aaa1d83c
parent1cbc45942d5c0f6eb5d94e3b10762ba541958035
Split `MacArgs` in two.

`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.
33 files changed:
compiler/rustc_ast/src/ast.rs
compiler/rustc_ast/src/attr/mod.rs
compiler/rustc_ast/src/mut_visit.rs
compiler/rustc_ast/src/visit.rs
compiler/rustc_ast_lowering/src/expr.rs
compiler/rustc_ast_lowering/src/item.rs
compiler/rustc_ast_lowering/src/lib.rs
compiler/rustc_ast_pretty/src/pprust/state.rs
compiler/rustc_builtin_macros/src/assert.rs
compiler/rustc_builtin_macros/src/assert/context.rs
compiler/rustc_builtin_macros/src/edition_panic.rs
compiler/rustc_expand/src/expand.rs
compiler/rustc_expand/src/mbe/macro_rules.rs
compiler/rustc_expand/src/parse/tests.rs
compiler/rustc_expand/src/placeholders.rs
compiler/rustc_lint/src/builtin.rs
compiler/rustc_metadata/src/rmeta/mod.rs
compiler/rustc_middle/src/ty/parameterized.rs
compiler/rustc_parse/src/lib.rs
compiler/rustc_parse/src/parser/expr.rs
compiler/rustc_parse/src/parser/item.rs
compiler/rustc_parse/src/parser/mod.rs
compiler/rustc_parse/src/parser/pat.rs
compiler/rustc_parse/src/parser/stmt.rs
compiler/rustc_parse/src/parser/ty.rs
compiler/rustc_parse/src/validate_attr.rs
src/librustdoc/clean/utils.rs
src/tools/clippy/clippy_lints/src/crate_in_macro_def.rs
src/tools/clippy/clippy_utils/src/ast_utils.rs
src/tools/rustfmt/src/expr.rs
src/tools/rustfmt/src/macros.rs
src/tools/rustfmt/src/parse/macros/asm.rs
src/tools/rustfmt/src/parse/macros/cfg_if.rs