Skip to content

Commit a05c83b

Browse files
committed
parse: use parse_item_common in parse_assoc_item_.
1 parent a63f35d commit a05c83b

38 files changed

+668
-286
lines changed

src/librustc_expand/expand.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -865,15 +865,15 @@ pub fn parse_ast_fragment<'a>(
865865
}
866866
AstFragmentKind::TraitItems => {
867867
let mut items = SmallVec::new();
868-
while this.token != token::Eof {
869-
items.push(this.parse_trait_item(&mut false)?);
868+
while let Some(item) = this.parse_trait_item()? {
869+
items.extend(item);
870870
}
871871
AstFragment::TraitItems(items)
872872
}
873873
AstFragmentKind::ImplItems => {
874874
let mut items = SmallVec::new();
875-
while this.token != token::Eof {
876-
items.push(this.parse_impl_item(&mut false)?);
875+
while let Some(item) = this.parse_impl_item()? {
876+
items.extend(item);
877877
}
878878
AstFragment::ImplItems(items)
879879
}

src/librustc_parse/parser/item.rs

Lines changed: 72 additions & 144 deletions
Large diffs are not rendered by default.

src/test/ui/async-await/no-unsafe-async.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
error: expected one of `extern` or `fn`, found keyword `async`
22
--> $DIR/no-unsafe-async.rs:7:12
33
|
4+
LL | impl S {
5+
| - while parsing this item list starting here
6+
LL | #[cfg(FALSE)]
47
LL | unsafe async fn g() {}
58
| ^^^^^ expected one of `extern` or `fn`
9+
LL | }
10+
| - the item list ends here
611

712
error: expected one of `extern` or `fn`, found keyword `async`
813
--> $DIR/no-unsafe-async.rs:11:8

src/test/ui/did_you_mean/issue-40006.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
impl dyn A { //~ ERROR missing
1+
impl dyn A {
22
Y
3-
}
3+
} //~ ERROR expected one of `!` or `::`, found `}`
44

55
struct S;
66

7-
trait X { //~ ERROR missing
8-
X() {}
7+
trait X {
8+
X() {} //~ ERROR expected one of `!` or `::`, found `(`
99
fn xxx() { ### }
1010
L = M;
1111
Z = { 2 + 3 };
1212
::Y ();
1313
}
1414

15-
trait A { //~ ERROR missing
16-
X() {}
15+
trait A {
16+
X() {} //~ ERROR expected one of `!` or `::`, found `(`
1717
}
1818
trait B {
1919
fn xxx() { ### } //~ ERROR expected
2020
}
21-
trait C { //~ ERROR missing `fn`, `type`, `const`, or `static` for item declaration
22-
L = M;
21+
trait C {
22+
L = M; //~ ERROR expected one of `!` or `::`, found `=`
2323
}
24-
trait D { //~ ERROR missing `fn`, `type`, `const`, or `static` for item declaration
25-
Z = { 2 + 3 };
24+
trait D {
25+
Z = { 2 + 3 }; //~ ERROR expected one of `!` or `::`, found `=`
2626
}
2727
trait E {
2828
::Y (); //~ ERROR expected one of

src/test/ui/did_you_mean/issue-40006.stderr

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,88 @@
1-
error: missing `fn`, `type`, `const`, or `static` for item declaration
2-
--> $DIR/issue-40006.rs:1:13
1+
error: expected one of `!` or `::`, found `}`
2+
--> $DIR/issue-40006.rs:3:1
33
|
4-
LL | impl dyn A {
5-
| _____________^
6-
LL | | Y
7-
| |____^ missing `fn`, `type`, `const`, or `static`
4+
LL | impl dyn A {
5+
| - while parsing this item list starting here
6+
LL | Y
7+
| - expected one of `!` or `::`
8+
LL | }
9+
| ^
10+
| |
11+
| unexpected token
12+
| the item list ends here
813

9-
error: missing `fn`, `type`, `const`, or `static` for item declaration
10-
--> $DIR/issue-40006.rs:7:10
14+
error: expected one of `!` or `::`, found `(`
15+
--> $DIR/issue-40006.rs:8:6
1116
|
12-
LL | trait X {
13-
| __________^
14-
LL | | X() {}
15-
| |____^ missing `fn`, `type`, `const`, or `static`
17+
LL | trait X {
18+
| - while parsing this item list starting here
19+
LL | X() {}
20+
| ^ expected one of `!` or `::`
21+
...
22+
LL | }
23+
| - the item list ends here
1624

17-
error: missing `fn`, `type`, `const`, or `static` for item declaration
18-
--> $DIR/issue-40006.rs:15:10
25+
error: expected one of `!` or `::`, found `(`
26+
--> $DIR/issue-40006.rs:16:6
1927
|
20-
LL | trait A {
21-
| __________^
22-
LL | | X() {}
23-
| |____^ missing `fn`, `type`, `const`, or `static`
28+
LL | trait A {
29+
| - while parsing this item list starting here
30+
LL | X() {}
31+
| ^ expected one of `!` or `::`
32+
LL | }
33+
| - the item list ends here
2434

2535
error: expected `[`, found `#`
2636
--> $DIR/issue-40006.rs:19:17
2737
|
2838
LL | fn xxx() { ### }
2939
| ^ expected `[`
3040

31-
error: missing `fn`, `type`, `const`, or `static` for item declaration
32-
--> $DIR/issue-40006.rs:21:10
41+
error: expected one of `!` or `::`, found `=`
42+
--> $DIR/issue-40006.rs:22:7
3343
|
34-
LL | trait C {
35-
| __________^
36-
LL | | L = M;
37-
| |____^ missing `fn`, `type`, `const`, or `static`
44+
LL | trait C {
45+
| - while parsing this item list starting here
46+
LL | L = M;
47+
| ^ expected one of `!` or `::`
48+
LL | }
49+
| - the item list ends here
3850

39-
error: missing `fn`, `type`, `const`, or `static` for item declaration
40-
--> $DIR/issue-40006.rs:24:10
51+
error: expected one of `!` or `::`, found `=`
52+
--> $DIR/issue-40006.rs:25:7
4153
|
42-
LL | trait D {
43-
| __________^
44-
LL | | Z = { 2 + 3 };
45-
| |____^ missing `fn`, `type`, `const`, or `static`
54+
LL | trait D {
55+
| - while parsing this item list starting here
56+
LL | Z = { 2 + 3 };
57+
| ^ expected one of `!` or `::`
58+
LL | }
59+
| - the item list ends here
4660

4761
error: expected one of `!` or `::`, found `(`
4862
--> $DIR/issue-40006.rs:28:9
4963
|
64+
LL | trait E {
65+
| - while parsing this item list starting here
5066
LL | ::Y ();
5167
| ^ expected one of `!` or `::`
68+
LL | }
69+
| - the item list ends here
5270

53-
error: missing `fn`, `type`, `const`, or `static` for item declaration
71+
error: missing `fn` for method definition
5472
--> $DIR/issue-40006.rs:32:8
5573
|
74+
LL | impl S {
75+
| - while parsing this item list starting here
5676
LL | pub hello_method(&self) {
57-
| ^ missing `fn`, `type`, `const`, or `static`
77+
| ^
78+
...
79+
LL | }
80+
| - the item list ends here
81+
|
82+
help: add `fn` here to parse `hello_method` as a public method
83+
|
84+
LL | pub fn hello_method(&self) {
85+
| ^^
5886

5987
error[E0599]: no method named `hello_method` found for struct `S` in the current scope
6088
--> $DIR/issue-40006.rs:38:7
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
error: expected one of `>`, `const`, identifier, or lifetime, found `,`
22
--> $DIR/empty_generics.rs:5:14
33
|
4+
LL | trait Foo {
5+
| - while parsing this item list starting here
46
LL | type Bar<,>;
57
| ^ expected one of `>`, `const`, identifier, or lifetime
8+
LL |
9+
LL | }
10+
| - the item list ends here
611

712
error: aborting due to previous error
813

src/test/ui/issues/issue-58856-1.stderr

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ LL | fn b(self>
99
error: expected `;` or `{`, found `>`
1010
--> $DIR/issue-58856-1.rs:3:14
1111
|
12+
LL | impl A {
13+
| - while parsing this item list starting here
14+
LL |
1215
LL | fn b(self>
1316
| ^ expected `;` or `{`
17+
...
18+
LL | }
19+
| - the item list ends here
1420

1521
error[E0412]: cannot find type `A` in this scope
1622
--> $DIR/issue-58856-1.rs:1:6

src/test/ui/issues/issue-58856-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ impl Howness for () {
99
Empty
1010
}
1111
}
12-
//~^ ERROR expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`,
12+
//~^ ERROR non-item in item list
1313

1414
fn main() {}

src/test/ui/issues/issue-58856-2.stderr

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ LL | fn how_are_you(&self -> Empty {
77
| | help: `)` may belong here
88
| unclosed delimiter
99

10-
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `static`, `type`, `unsafe`, `}`, or identifier, found `)`
10+
error: non-item in item list
1111
--> $DIR/issue-58856-2.rs:11:1
1212
|
13-
LL | }
14-
| - expected one of 12 possible tokens
13+
LL | impl Howness for () {
14+
| - item list starts here
15+
...
1516
LL | }
16-
| ^ unexpected token
17+
| ^
18+
| |
19+
| non-item starts here
20+
| item list ends here
1721

1822
error[E0407]: method `how_are_you` is not a member of trait `Howness`
1923
--> $DIR/issue-58856-2.rs:6:5

src/test/ui/issues/issue-60075.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ trait T {
44
fn qux() -> Option<usize> {
55
let _ = if true {
66
});
7-
//~^ ERROR expected one of `async`
8-
//~| ERROR expected one of `.`, `;`, `?`, `else`, or an operator, found `}`
7+
//~^ ERROR non-item in item list
8+
//~| ERROR mismatched closing delimiter: `)`
9+
//~| ERROR expected one of `.`, `;`
910
Some(4)
1011
}

0 commit comments

Comments
 (0)