Add test for enum with fields

This commit is contained in:
Catherine Flores 2023-08-02 23:59:30 +00:00
parent dece622ee4
commit bbd69e4a4c
4 changed files with 54 additions and 37 deletions

View File

@ -1754,12 +1754,7 @@ impl<'a> Parser<'a> {
ident: None,
vis,
id: DUMMY_NODE_ID,
ty: P(Ty {
id: DUMMY_NODE_ID,
kind: TyKind::Err,
span: DUMMY_SP,
tokens: None,
}),
ty: self.mk_ty(DUMMY_SP, TyKind::Err),
attrs,
is_placeholder: false,
});

View File

@ -1,4 +1,4 @@
#![no_main]
// compile-flags: --crate-type=lib
macro_rules! field {
($name:ident:$type:ty) => {
@ -13,9 +13,10 @@ macro_rules! variant {
}
struct Struct {
field!(bar:u128), //~ NOTE macros cannot expand to struct fields
//~^ ERROR unexpected token: `!`
//~^^ NOTE unexpected token after this
field!(bar:u128),
//~^ NOTE macros cannot expand to struct fields
//~| ERROR unexpected token: `!`
//~| NOTE unexpected token after this
a: u32,
b: u32,
field!(recovers:()), //~ NOTE macros cannot expand to struct fields
@ -24,34 +25,46 @@ struct Struct {
}
enum EnumVariant {
variant!(whoops), //~ NOTE macros cannot expand to enum variants
//~^ ERROR unexpected token: `!`
//~^^ NOTE unexpected token after this
variant!(whoops),
//~^ NOTE macros cannot expand to enum variants
//~| ERROR unexpected token: `!`
//~| NOTE unexpected token after this
U32,
F64,
variant!(recovers), //~ NOTE macros cannot expand to enum variants
//~^ ERROR unexpected token: `!`
//~^^ NOTE unexpected token after this
variant!(recovers),
//~^ NOTE macros cannot expand to enum variants
//~| ERROR unexpected token: `!`
//~| NOTE unexpected token after this
Data {
field!(x:u32),
//~^ NOTE macros cannot expand to struct fields
//~| ERROR unexpected token: `!`
//~| NOTE unexpected token after this
}
}
enum EnumVariantField {
Named {
field!(oopsies:()), //~ NOTE macros cannot expand to struct fields
//~^ ERROR unexpected token: `!`
//~^^ unexpected token after this
field!(oopsies2:()), //~ NOTE macros cannot expand to struct fields
//~^ ERROR unexpected token: `!`
//~^^ unexpected token after this
field!(oopsies:()),
//~^ NOTE macros cannot expand to struct fields
//~| ERROR unexpected token: `!`
//~| unexpected token after this
field!(oopsies2:()),
//~^ NOTE macros cannot expand to struct fields
//~| ERROR unexpected token: `!`
//~| unexpected token after this
},
}
union Union {
A: u32,
field!(oopsies:()), //~ NOTE macros cannot expand to union fields
//~^ ERROR unexpected token: `!`
//~^^ unexpected token after this
field!(oopsies:()),
//~^ NOTE macros cannot expand to union fields
//~| ERROR unexpected token: `!`
//~| unexpected token after this
B: u32,
field!(recovers:()), //~ NOTE macros cannot expand to union fields
//~^ ERROR unexpected token: `!`
//~^^ unexpected token after this
field!(recovers:()),
//~^ NOTE macros cannot expand to union fields
//~| ERROR unexpected token: `!`
//~| unexpected token after this
}

View File

@ -7,7 +7,7 @@ LL | field!(bar:u128),
= note: macros cannot expand to struct fields
error: unexpected token: `!`
--> $DIR/macro-expand-to-field.rs:21:10
--> $DIR/macro-expand-to-field.rs:22:10
|
LL | field!(recovers:()),
| ^ unexpected token after this
@ -15,7 +15,7 @@ LL | field!(recovers:()),
= note: macros cannot expand to struct fields
error: unexpected token: `!`
--> $DIR/macro-expand-to-field.rs:27:12
--> $DIR/macro-expand-to-field.rs:28:12
|
LL | variant!(whoops),
| ^ unexpected token after this
@ -23,7 +23,7 @@ LL | variant!(whoops),
= note: macros cannot expand to enum variants
error: unexpected token: `!`
--> $DIR/macro-expand-to-field.rs:32:12
--> $DIR/macro-expand-to-field.rs:34:12
|
LL | variant!(recovers),
| ^ unexpected token after this
@ -33,13 +33,21 @@ LL | variant!(recovers),
error: unexpected token: `!`
--> $DIR/macro-expand-to-field.rs:39:14
|
LL | field!(x:u32),
| ^ unexpected token after this
|
= note: macros cannot expand to struct fields
error: unexpected token: `!`
--> $DIR/macro-expand-to-field.rs:48:14
|
LL | field!(oopsies:()),
| ^ unexpected token after this
|
= note: macros cannot expand to struct fields
error: unexpected token: `!`
--> $DIR/macro-expand-to-field.rs:42:14
--> $DIR/macro-expand-to-field.rs:52:14
|
LL | field!(oopsies2:()),
| ^ unexpected token after this
@ -47,7 +55,7 @@ LL | field!(oopsies2:()),
= note: macros cannot expand to struct fields
error: unexpected token: `!`
--> $DIR/macro-expand-to-field.rs:50:10
--> $DIR/macro-expand-to-field.rs:61:10
|
LL | field!(oopsies:()),
| ^ unexpected token after this
@ -55,12 +63,12 @@ LL | field!(oopsies:()),
= note: macros cannot expand to union fields
error: unexpected token: `!`
--> $DIR/macro-expand-to-field.rs:54:10
--> $DIR/macro-expand-to-field.rs:66:10
|
LL | field!(recovers:()),
| ^ unexpected token after this
|
= note: macros cannot expand to union fields
error: aborting due to 8 previous errors
error: aborting due to 9 previous errors

View File

@ -8,8 +8,9 @@ fn main() {
let x = Some(1);
match x {
Some(1) => {},
arm!(None => {}), //~ NOTE macros cannot expand to match arms
//~^ ERROR unexpected `,` in pattern
arm!(None => {}),
//~^ NOTE macros cannot expand to match arms
//~| ERROR unexpected `,` in pattern
// doesn't recover
Some(2) => {},
_ => {},