diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-04-29 06:52:01 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-05-05 07:06:12 +1000 |
| commit | 99f5945f85342e1eff8d31507410ddd66ea94d64 (patch) | |
| tree | 6594fd89e3820be4bfa2b6d99ec0447c4fc1c1ff /src/test/ui/attributes | |
| parent | ae5f67f9e8a560c66d1c4afea1750d21f1d093e7 (diff) | |
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/attributes')
| -rw-r--r-- | src/test/ui/attributes/issue-90873.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/attributes/issue-90873.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/attributes/key-value-expansion-on-mac.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/attributes/key-value-expansion-on-mac.stderr | 2 | ||||
| -rw-r--r-- | src/test/ui/attributes/key-value-expansion.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/attributes/key-value-expansion.stderr | 6 |
6 files changed, 13 insertions, 13 deletions
diff --git a/src/test/ui/attributes/issue-90873.rs b/src/test/ui/attributes/issue-90873.rs index 0f62d415308..1411f61744d 100644 --- a/src/test/ui/attributes/issue-90873.rs +++ b/src/test/ui/attributes/issue-90873.rs @@ -1,9 +1,9 @@ #![u=||{static d=||1;}] -//~^ unexpected token +//~^ unexpected expression //~| cannot find attribute `u` in this scope //~| missing type for `static` item #![a={impl std::ops::Neg for i8 {}}] -//~^ ERROR unexpected token +//~^ ERROR unexpected expression //~| ERROR cannot find attribute `a` in this scope //~| ERROR `main` function not found in crate `issue_90873` diff --git a/src/test/ui/attributes/issue-90873.stderr b/src/test/ui/attributes/issue-90873.stderr index fbdc05ef6f0..0852bb7ca8b 100644 --- a/src/test/ui/attributes/issue-90873.stderr +++ b/src/test/ui/attributes/issue-90873.stderr @@ -1,4 +1,4 @@ -error: unexpected token: `|| +error: unexpected expression: `|| { static d: _ = || 1; }` @@ -7,7 +7,7 @@ error: unexpected token: `|| LL | #![u=||{static d=||1;}] | ^^^^^^^^^^^^^^^^^ -error: unexpected token: `{ +error: unexpected expression: `{ impl std::ops::Neg for i8 {} }` --> $DIR/issue-90873.rs:6:6 diff --git a/src/test/ui/attributes/key-value-expansion-on-mac.rs b/src/test/ui/attributes/key-value-expansion-on-mac.rs index 95bc1c04961..c1d68d8cda9 100644 --- a/src/test/ui/attributes/key-value-expansion-on-mac.rs +++ b/src/test/ui/attributes/key-value-expansion-on-mac.rs @@ -7,8 +7,8 @@ macro_rules! bar { // FIXME?: `bar` here expands before `stringify` has a chance to expand. // `#[rustc_dummy = ...]` is validated and dropped during expansion of `bar`, -// the "unexpected token" errors comes from the validation. -#[rustc_dummy = stringify!(b)] //~ ERROR unexpected token: `stringify!(b)` +// the "unexpected expression" errors comes from the validation. +#[rustc_dummy = stringify!(b)] //~ ERROR unexpected expression: `stringify!(b)` bar!(); fn main() {} diff --git a/src/test/ui/attributes/key-value-expansion-on-mac.stderr b/src/test/ui/attributes/key-value-expansion-on-mac.stderr index fa9ea543765..64ab892d997 100644 --- a/src/test/ui/attributes/key-value-expansion-on-mac.stderr +++ b/src/test/ui/attributes/key-value-expansion-on-mac.stderr @@ -1,4 +1,4 @@ -error: unexpected token: `stringify!(b)` +error: unexpected expression: `stringify!(b)` --> $DIR/key-value-expansion-on-mac.rs:11:17 | LL | #[rustc_dummy = stringify!(b)] diff --git a/src/test/ui/attributes/key-value-expansion.rs b/src/test/ui/attributes/key-value-expansion.rs index 08121413ee9..83d601e5e3a 100644 --- a/src/test/ui/attributes/key-value-expansion.rs +++ b/src/test/ui/attributes/key-value-expansion.rs @@ -18,13 +18,13 @@ macro_rules! bug { // Any expressions containing macro call `X` that's more complex than `X` itself. // Parentheses will work. -bug!((column!())); //~ ERROR unexpected token: `(7u32)` +bug!((column!())); //~ ERROR unexpected expression: `(7u32)` // Original test case. macro_rules! bug { () => { - bug!("bug" + stringify!(found)); //~ ERROR unexpected token: `"bug" + "found"` + bug!("bug" + stringify!(found)); //~ ERROR unexpected expression: `"bug" + "found"` }; ($test:expr) => { #[doc = $test] @@ -46,7 +46,7 @@ macro_rules! doc_comment { macro_rules! some_macro { ($t1: ty) => { doc_comment! {format!("{coor}", coor = stringify!($t1)).as_str()} - //~^ ERROR unexpected token: `{ + //~^ ERROR unexpected expression: `{ }; } diff --git a/src/test/ui/attributes/key-value-expansion.stderr b/src/test/ui/attributes/key-value-expansion.stderr index 1b7cb76b553..1b776322aaa 100644 --- a/src/test/ui/attributes/key-value-expansion.stderr +++ b/src/test/ui/attributes/key-value-expansion.stderr @@ -1,10 +1,10 @@ -error: unexpected token: `(7u32)` +error: unexpected expression: `(7u32)` --> $DIR/key-value-expansion.rs:21:6 | LL | bug!((column!())); | ^^^^^^^^^^^ -error: unexpected token: `"bug" + "found"` +error: unexpected expression: `"bug" + "found"` --> $DIR/key-value-expansion.rs:27:14 | LL | bug!("bug" + stringify!(found)); @@ -15,7 +15,7 @@ LL | bug!(); | = note: this error originates in the macro `bug` (in Nightly builds, run with -Z macro-backtrace for more info) -error: unexpected token: `{ +error: unexpected expression: `{ let res = ::alloc::fmt::format(::core::fmt::Arguments::new_v1(&[""], &[::core::fmt::ArgumentV1::new_display(&"u8")])); |
