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: `||
|
2021-11-21 09:16:02 -06:00
|
|
|
{
|
|
|
|
static d: _ = || 1;
|
|
|
|
}`
|
|
|
|
--> $DIR/issue-90873.rs:1:6
|
|
|
|
|
|
|
|
|
LL | #![u=||{static d=||1;}]
|
|
|
|
| ^^^^^^^^^^^^^^^^^
|
|
|
|
|
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: `{
|
2021-12-01 13:45:14 -06:00
|
|
|
impl std::ops::Neg for i8 {}
|
2021-11-24 16:07:13 -06:00
|
|
|
}`
|
2022-01-20 18:15:39 -06:00
|
|
|
--> $DIR/issue-90873.rs:6:6
|
2021-11-24 16:07:13 -06:00
|
|
|
|
|
|
|
|
LL | #![a={impl std::ops::Neg for i8 {}}]
|
|
|
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
2021-11-21 09:16:02 -06:00
|
|
|
error: cannot find attribute `u` in this scope
|
|
|
|
--> $DIR/issue-90873.rs:1:4
|
|
|
|
|
|
|
|
|
LL | #![u=||{static d=||1;}]
|
|
|
|
| ^
|
|
|
|
|
2021-11-24 16:07:13 -06:00
|
|
|
error: cannot find attribute `a` in this scope
|
2022-01-20 18:15:39 -06:00
|
|
|
--> $DIR/issue-90873.rs:6:4
|
2021-11-24 16:07:13 -06:00
|
|
|
|
|
|
|
|
LL | #![a={impl std::ops::Neg for i8 {}}]
|
|
|
|
| ^
|
|
|
|
|
2021-11-21 09:16:02 -06:00
|
|
|
error[E0601]: `main` function not found in crate `issue_90873`
|
2022-01-20 18:15:39 -06:00
|
|
|
--> $DIR/issue-90873.rs:6:37
|
2021-11-21 09:16:02 -06:00
|
|
|
|
|
2022-01-20 18:15:39 -06:00
|
|
|
LL | #![a={impl std::ops::Neg for i8 {}}]
|
|
|
|
| ^ consider adding a `main` function to `$DIR/issue-90873.rs`
|
2021-11-21 09:16:02 -06:00
|
|
|
|
|
|
|
error: missing type for `static` item
|
2022-08-05 06:41:42 -05:00
|
|
|
--> $DIR/issue-90873.rs:1:17
|
2021-11-21 09:16:02 -06:00
|
|
|
|
|
|
|
|
LL | #![u=||{static d=||1;}]
|
2022-08-05 06:41:42 -05:00
|
|
|
| ^ help: provide a type for the item: `: <type>`
|
2021-11-21 09:16:02 -06:00
|
|
|
|
2021-11-24 16:07:13 -06:00
|
|
|
error: aborting due to 6 previous errors
|
2021-11-21 09:16:02 -06:00
|
|
|
|
|
|
|
For more information about this error, try `rustc --explain E0601`.
|