about summary refs log tree commit diff
path: root/src/test/ui/malformed
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2022-04-29 06:52:01 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2022-05-05 07:06:12 +1000
commit99f5945f85342e1eff8d31507410ddd66ea94d64 (patch)
tree6594fd89e3820be4bfa2b6d99ec0447c4fc1c1ff /src/test/ui/malformed
parentae5f67f9e8a560c66d1c4afea1750d21f1d093e7 (diff)
downloadrust-99f5945f85342e1eff8d31507410ddd66ea94d64.tar.gz
rust-99f5945f85342e1eff8d31507410ddd66ea94d64.zip
Overhaul `MacArgs::Eq`.
The value in `MacArgs::Eq` is currently represented as a `Token`.
Because of `TokenKind::Interpolated`, `Token` can be either a token or
an arbitrary AST fragment. In practice, a `MacArgs::Eq` starts out as a
literal or macro call AST fragment, and then is later lowered to a
literal token. But this is very non-obvious. `Token` is a much more
general type than what is needed.

This commit restricts things, by introducing a new type `MacArgsEqKind`
that is either an AST expression (pre-lowering) or an AST literal
(post-lowering). The downside is that the code is a bit more verbose in
a few places. The benefit is that makes it much clearer what the
possibilities are (though also shorter in some other places). Also, it
removes one use of `TokenKind::Interpolated`, taking us a step closer to
removing that variant, which will let us make `Token` impl `Copy` and
remove many "handle Interpolated" code paths in the parser.

Things to note:
- Error messages have improved. Messages like this:
  ```
  unexpected token: `"bug" + "found"`
  ```
  now say "unexpected expression", which makes more sense. Although
  arbitrary expressions can exist within tokens thanks to
  `TokenKind::Interpolated`, that's not obvious to anyone who doesn't
  know compiler internals.
- In `parse_mac_args_common`, we no longer need to collect tokens for
  the value expression.
Diffstat (limited to 'src/test/ui/malformed')
-rw-r--r--src/test/ui/malformed/malformed-interpolated.rs4
-rw-r--r--src/test/ui/malformed/malformed-interpolated.stderr4
2 files changed, 4 insertions, 4 deletions
diff --git a/src/test/ui/malformed/malformed-interpolated.rs b/src/test/ui/malformed/malformed-interpolated.rs
index b962447e7ed..0d84e723fc3 100644
--- a/src/test/ui/malformed/malformed-interpolated.rs
+++ b/src/test/ui/malformed/malformed-interpolated.rs
@@ -10,7 +10,7 @@ macro_rules! check {
 check!("0"); // OK
 check!(0); // OK
 check!(0u8); //~ ERROR suffixed literals are not allowed in attributes
-check!(-0); //~ ERROR unexpected token: `-0`
-check!(0 + 0); //~ ERROR unexpected token: `0 + 0`
+check!(-0); //~ ERROR unexpected expression: `-0`
+check!(0 + 0); //~ ERROR unexpected expression: `0 + 0`
 
 fn main() {}
diff --git a/src/test/ui/malformed/malformed-interpolated.stderr b/src/test/ui/malformed/malformed-interpolated.stderr
index 4b9332ddd01..c24d9f15388 100644
--- a/src/test/ui/malformed/malformed-interpolated.stderr
+++ b/src/test/ui/malformed/malformed-interpolated.stderr
@@ -6,13 +6,13 @@ LL | check!(0u8);
    |
    = help: instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.)
 
-error: unexpected token: `-0`
+error: unexpected expression: `-0`
   --> $DIR/malformed-interpolated.rs:13:8
    |
 LL | check!(-0);
    |        ^^
 
-error: unexpected token: `0 + 0`
+error: unexpected expression: `0 + 0`
   --> $DIR/malformed-interpolated.rs:14:8
    |
 LL | check!(0 + 0);