Skip to content

Commit bbd69e4

Browse files
committed
Add test for enum with fields
1 parent dece622 commit bbd69e4

File tree

4 files changed

+54
-37
lines changed

4 files changed

+54
-37
lines changed

compiler/rustc_parse/src/parser/item.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1754,12 +1754,7 @@ impl<'a> Parser<'a> {
17541754
ident: None,
17551755
vis,
17561756
id: DUMMY_NODE_ID,
1757-
ty: P(Ty {
1758-
id: DUMMY_NODE_ID,
1759-
kind: TyKind::Err,
1760-
span: DUMMY_SP,
1761-
tokens: None,
1762-
}),
1757+
ty: self.mk_ty(DUMMY_SP, TyKind::Err),
17631758
attrs,
17641759
is_placeholder: false,
17651760
});
+35-22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![no_main]
1+
// compile-flags: --crate-type=lib
22

33
macro_rules! field {
44
($name:ident:$type:ty) => {
@@ -13,9 +13,10 @@ macro_rules! variant {
1313
}
1414

1515
struct Struct {
16-
field!(bar:u128), //~ NOTE macros cannot expand to struct fields
17-
//~^ ERROR unexpected token: `!`
18-
//~^^ NOTE unexpected token after this
16+
field!(bar:u128),
17+
//~^ NOTE macros cannot expand to struct fields
18+
//~| ERROR unexpected token: `!`
19+
//~| NOTE unexpected token after this
1920
a: u32,
2021
b: u32,
2122
field!(recovers:()), //~ NOTE macros cannot expand to struct fields
@@ -24,34 +25,46 @@ struct Struct {
2425
}
2526

2627
enum EnumVariant {
27-
variant!(whoops), //~ NOTE macros cannot expand to enum variants
28-
//~^ ERROR unexpected token: `!`
29-
//~^^ NOTE unexpected token after this
28+
variant!(whoops),
29+
//~^ NOTE macros cannot expand to enum variants
30+
//~| ERROR unexpected token: `!`
31+
//~| NOTE unexpected token after this
3032
U32,
3133
F64,
32-
variant!(recovers), //~ NOTE macros cannot expand to enum variants
33-
//~^ ERROR unexpected token: `!`
34-
//~^^ NOTE unexpected token after this
34+
variant!(recovers),
35+
//~^ NOTE macros cannot expand to enum variants
36+
//~| ERROR unexpected token: `!`
37+
//~| NOTE unexpected token after this
38+
Data {
39+
field!(x:u32),
40+
//~^ NOTE macros cannot expand to struct fields
41+
//~| ERROR unexpected token: `!`
42+
//~| NOTE unexpected token after this
43+
}
3544
}
3645

3746
enum EnumVariantField {
3847
Named {
39-
field!(oopsies:()), //~ NOTE macros cannot expand to struct fields
40-
//~^ ERROR unexpected token: `!`
41-
//~^^ unexpected token after this
42-
field!(oopsies2:()), //~ NOTE macros cannot expand to struct fields
43-
//~^ ERROR unexpected token: `!`
44-
//~^^ unexpected token after this
48+
field!(oopsies:()),
49+
//~^ NOTE macros cannot expand to struct fields
50+
//~| ERROR unexpected token: `!`
51+
//~| unexpected token after this
52+
field!(oopsies2:()),
53+
//~^ NOTE macros cannot expand to struct fields
54+
//~| ERROR unexpected token: `!`
55+
//~| unexpected token after this
4556
},
4657
}
4758

4859
union Union {
4960
A: u32,
50-
field!(oopsies:()), //~ NOTE macros cannot expand to union fields
51-
//~^ ERROR unexpected token: `!`
52-
//~^^ unexpected token after this
61+
field!(oopsies:()),
62+
//~^ NOTE macros cannot expand to union fields
63+
//~| ERROR unexpected token: `!`
64+
//~| unexpected token after this
5365
B: u32,
54-
field!(recovers:()), //~ NOTE macros cannot expand to union fields
55-
//~^ ERROR unexpected token: `!`
56-
//~^^ unexpected token after this
66+
field!(recovers:()),
67+
//~^ NOTE macros cannot expand to union fields
68+
//~| ERROR unexpected token: `!`
69+
//~| unexpected token after this
5770
}

tests/ui/parser/macro/macro-expand-to-field.stderr

+15-7
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ LL | field!(bar:u128),
77
= note: macros cannot expand to struct fields
88

99
error: unexpected token: `!`
10-
--> $DIR/macro-expand-to-field.rs:21:10
10+
--> $DIR/macro-expand-to-field.rs:22:10
1111
|
1212
LL | field!(recovers:()),
1313
| ^ unexpected token after this
1414
|
1515
= note: macros cannot expand to struct fields
1616

1717
error: unexpected token: `!`
18-
--> $DIR/macro-expand-to-field.rs:27:12
18+
--> $DIR/macro-expand-to-field.rs:28:12
1919
|
2020
LL | variant!(whoops),
2121
| ^ unexpected token after this
2222
|
2323
= note: macros cannot expand to enum variants
2424

2525
error: unexpected token: `!`
26-
--> $DIR/macro-expand-to-field.rs:32:12
26+
--> $DIR/macro-expand-to-field.rs:34:12
2727
|
2828
LL | variant!(recovers),
2929
| ^ unexpected token after this
@@ -33,34 +33,42 @@ LL | variant!(recovers),
3333
error: unexpected token: `!`
3434
--> $DIR/macro-expand-to-field.rs:39:14
3535
|
36+
LL | field!(x:u32),
37+
| ^ unexpected token after this
38+
|
39+
= note: macros cannot expand to struct fields
40+
41+
error: unexpected token: `!`
42+
--> $DIR/macro-expand-to-field.rs:48:14
43+
|
3644
LL | field!(oopsies:()),
3745
| ^ unexpected token after this
3846
|
3947
= note: macros cannot expand to struct fields
4048

4149
error: unexpected token: `!`
42-
--> $DIR/macro-expand-to-field.rs:42:14
50+
--> $DIR/macro-expand-to-field.rs:52:14
4351
|
4452
LL | field!(oopsies2:()),
4553
| ^ unexpected token after this
4654
|
4755
= note: macros cannot expand to struct fields
4856

4957
error: unexpected token: `!`
50-
--> $DIR/macro-expand-to-field.rs:50:10
58+
--> $DIR/macro-expand-to-field.rs:61:10
5159
|
5260
LL | field!(oopsies:()),
5361
| ^ unexpected token after this
5462
|
5563
= note: macros cannot expand to union fields
5664

5765
error: unexpected token: `!`
58-
--> $DIR/macro-expand-to-field.rs:54:10
66+
--> $DIR/macro-expand-to-field.rs:66:10
5967
|
6068
LL | field!(recovers:()),
6169
| ^ unexpected token after this
6270
|
6371
= note: macros cannot expand to union fields
6472

65-
error: aborting due to 8 previous errors
73+
error: aborting due to 9 previous errors
6674

tests/ui/parser/macro/macro-expand-to-match-arm.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ fn main() {
88
let x = Some(1);
99
match x {
1010
Some(1) => {},
11-
arm!(None => {}), //~ NOTE macros cannot expand to match arms
12-
//~^ ERROR unexpected `,` in pattern
11+
arm!(None => {}),
12+
//~^ NOTE macros cannot expand to match arms
13+
//~| ERROR unexpected `,` in pattern
1314
// doesn't recover
1415
Some(2) => {},
1516
_ => {},

0 commit comments

Comments
 (0)