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.
2022-04-28 15:52:01 -05:00
|
|
|
error: unexpected expression: `(7u32)`
|
2020-11-07 07:09:40 -06:00
|
|
|
--> $DIR/key-value-expansion.rs:21:6
|
2020-09-27 08:52:51 -05:00
|
|
|
|
|
|
|
|
LL | bug!((column!()));
|
2020-11-07 07:09:40 -06:00
|
|
|
| ^^^^^^^^^^^
|
2020-09-27 08:52:51 -05:00
|
|
|
|
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.
2022-04-28 15:52:01 -05:00
|
|
|
error: unexpected expression: `"bug" + "found"`
|
2020-11-07 07:09:40 -06:00
|
|
|
--> $DIR/key-value-expansion.rs:27:14
|
2020-09-27 08:52:51 -05:00
|
|
|
|
|
2020-11-07 07:09:40 -06:00
|
|
|
LL | bug!("bug" + stringify!(found));
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
2020-09-27 08:52:51 -05:00
|
|
|
...
|
|
|
|
LL | bug!();
|
2021-10-14 13:28:28 -05:00
|
|
|
| ------ in this macro invocation
|
2020-09-27 08:52:51 -05:00
|
|
|
|
|
2021-02-13 13:52:25 -06:00
|
|
|
= note: this error originates in the macro `bug` (in Nightly builds, run with -Z macro-backtrace for more info)
|
2020-09-27 08:52:51 -05:00
|
|
|
|
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.
2022-04-28 15:52:01 -05:00
|
|
|
error: unexpected expression: `{
|
2022-01-21 03:34:06 -06:00
|
|
|
let res =
|
|
|
|
::alloc::fmt::format(::core::fmt::Arguments::new_v1(&[""],
|
|
|
|
&[::core::fmt::ArgumentV1::new_display(&"u8")]));
|
|
|
|
res
|
|
|
|
}.as_str()`
|
2020-11-07 07:09:40 -06:00
|
|
|
--> $DIR/key-value-expansion.rs:48:23
|
2020-09-27 08:52:51 -05:00
|
|
|
|
|
2020-11-07 07:09:40 -06:00
|
|
|
LL | doc_comment! {format!("{coor}", coor = stringify!($t1)).as_str()}
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
2020-09-27 08:52:51 -05:00
|
|
|
...
|
|
|
|
LL | some_macro!(u8);
|
2021-10-14 13:28:28 -05:00
|
|
|
| --------------- in this macro invocation
|
2020-09-27 08:52:51 -05:00
|
|
|
|
|
2021-02-13 13:52:25 -06:00
|
|
|
= note: this error originates in the macro `some_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
|
2020-09-27 08:52:51 -05:00
|
|
|
|
|
|
|
error: aborting due to 3 previous errors
|
|
|
|
|