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, ident: None,
vis, vis,
id: DUMMY_NODE_ID, id: DUMMY_NODE_ID,
ty: P(Ty { ty: self.mk_ty(DUMMY_SP, TyKind::Err),
id: DUMMY_NODE_ID,
kind: TyKind::Err,
span: DUMMY_SP,
tokens: None,
}),
attrs, attrs,
is_placeholder: false, is_placeholder: false,
}); });

View File

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

View File

@ -7,7 +7,7 @@ LL | field!(bar:u128),
= note: macros cannot expand to struct fields = note: macros cannot expand to struct fields
error: unexpected token: `!` error: unexpected token: `!`
--> $DIR/macro-expand-to-field.rs:21:10 --> $DIR/macro-expand-to-field.rs:22:10
| |
LL | field!(recovers:()), LL | field!(recovers:()),
| ^ unexpected token after this | ^ unexpected token after this
@ -15,7 +15,7 @@ LL | field!(recovers:()),
= note: macros cannot expand to struct fields = note: macros cannot expand to struct fields
error: unexpected token: `!` error: unexpected token: `!`
--> $DIR/macro-expand-to-field.rs:27:12 --> $DIR/macro-expand-to-field.rs:28:12
| |
LL | variant!(whoops), LL | variant!(whoops),
| ^ unexpected token after this | ^ unexpected token after this
@ -23,7 +23,7 @@ LL | variant!(whoops),
= note: macros cannot expand to enum variants = note: macros cannot expand to enum variants
error: unexpected token: `!` error: unexpected token: `!`
--> $DIR/macro-expand-to-field.rs:32:12 --> $DIR/macro-expand-to-field.rs:34:12
| |
LL | variant!(recovers), LL | variant!(recovers),
| ^ unexpected token after this | ^ unexpected token after this
@ -33,13 +33,21 @@ LL | variant!(recovers),
error: unexpected token: `!` error: unexpected token: `!`
--> $DIR/macro-expand-to-field.rs:39:14 --> $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:()), LL | field!(oopsies:()),
| ^ unexpected token after this | ^ unexpected token after this
| |
= note: macros cannot expand to struct fields = note: macros cannot expand to struct fields
error: unexpected token: `!` error: unexpected token: `!`
--> $DIR/macro-expand-to-field.rs:42:14 --> $DIR/macro-expand-to-field.rs:52:14
| |
LL | field!(oopsies2:()), LL | field!(oopsies2:()),
| ^ unexpected token after this | ^ unexpected token after this
@ -47,7 +55,7 @@ LL | field!(oopsies2:()),
= note: macros cannot expand to struct fields = note: macros cannot expand to struct fields
error: unexpected token: `!` error: unexpected token: `!`
--> $DIR/macro-expand-to-field.rs:50:10 --> $DIR/macro-expand-to-field.rs:61:10
| |
LL | field!(oopsies:()), LL | field!(oopsies:()),
| ^ unexpected token after this | ^ unexpected token after this
@ -55,12 +63,12 @@ LL | field!(oopsies:()),
= note: macros cannot expand to union fields = note: macros cannot expand to union fields
error: unexpected token: `!` error: unexpected token: `!`
--> $DIR/macro-expand-to-field.rs:54:10 --> $DIR/macro-expand-to-field.rs:66:10
| |
LL | field!(recovers:()), LL | field!(recovers:()),
| ^ unexpected token after this | ^ unexpected token after this
| |
= note: macros cannot expand to union fields = 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); let x = Some(1);
match x { match x {
Some(1) => {}, Some(1) => {},
arm!(None => {}), //~ NOTE macros cannot expand to match arms arm!(None => {}),
//~^ ERROR unexpected `,` in pattern //~^ NOTE macros cannot expand to match arms
//~| ERROR unexpected `,` in pattern
// doesn't recover // doesn't recover
Some(2) => {}, Some(2) => {},
_ => {}, _ => {},