about summary refs log tree commit diff
path: root/src/expr.rs
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2022-11-18 11:24:21 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2022-11-22 09:04:15 +1100
commit1343ffd564fbaed96e800a125e3d2b43de09beea (patch)
treec05d1607c909b73e0e1c7d1e4270d0beb0c2d863 /src/expr.rs
parent4a4addc5980e95e4f7883f2d56aedcd08626ba73 (diff)
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.
Diffstat (limited to 'src/expr.rs')
-rw-r--r--src/expr.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/expr.rs b/src/expr.rs
index aba1c484bf1..d5611082f01 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -1341,7 +1341,7 @@ pub(crate) fn can_be_overflowed_expr(
         }
         ast::ExprKind::MacCall(ref mac) => {
             match (
-                rustc_ast::ast::MacDelimiter::from_token(mac.args.delim().unwrap()),
+                rustc_ast::ast::MacDelimiter::from_token(mac.args.delim.to_token()),
                 context.config.overflow_delimited_expr(),
             ) {
                 (Some(ast::MacDelimiter::Bracket), true)