Skip to content

Commit 040f568

Browse files
committed
Rely on regular "expected"/"found" parser error for fn
1 parent 07a63e6 commit 040f568

15 files changed

+36
-31
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1550,14 +1550,6 @@ impl<'a> Parser<'a> {
15501550
}
15511551
}
15521552

1553-
pub(super) fn expected_semi_or_open_brace<T>(&mut self) -> PResult<'a, T> {
1554-
let token_str = super::token_descr(&self.token);
1555-
let msg = &format!("expected `;` or `{{`, found {}", token_str);
1556-
let mut err = self.struct_span_err(self.token.span, msg);
1557-
err.span_label(self.token.span, "expected `;` or `{`");
1558-
Err(err)
1559-
}
1560-
15611553
pub(super) fn eat_incorrect_doc_comment_for_param_type(&mut self) {
15621554
if let token::DocComment(..) = self.token.kind {
15631555
self.struct_span_err(

compiler/rustc_parse/src/parser/item.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1551,10 +1551,9 @@ impl<'a> Parser<'a> {
15511551
attrs: &mut Vec<Attribute>,
15521552
sig_hi: &mut Span,
15531553
) -> PResult<'a, Option<P<Block>>> {
1554-
let (inner_attrs, body) = if self.check(&token::Semi) {
1554+
let (inner_attrs, body) = if self.eat(&token::Semi) {
15551555
// Include the trailing semicolon in the span of the signature
1556-
*sig_hi = self.token.span;
1557-
self.bump(); // `;`
1556+
*sig_hi = self.prev_token.span;
15581557
(Vec::new(), None)
15591558
} else if self.check(&token::OpenDelim(token::Brace)) || self.token.is_whole_block() {
15601559
self.parse_inner_attrs_and_block().map(|(attrs, body)| (attrs, Some(body)))?
@@ -1574,7 +1573,9 @@ impl<'a> Parser<'a> {
15741573
.emit();
15751574
(Vec::new(), Some(self.mk_block_err(span)))
15761575
} else {
1577-
return self.expected_semi_or_open_brace();
1576+
return self
1577+
.expected_one_of_not_found(&[], &[token::Semi, token::OpenDelim(token::Brace)])
1578+
.map(|_| None);
15781579
};
15791580
attrs.extend(inner_attrs);
15801581
Ok(body)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fn foo(a: [0; 1]) {} //~ ERROR expected type, found `0`
2-
//~| ERROR expected `;` or `{`, found `]`
2+
//~| ERROR expected one of `)`, `,`, `->`, `;`, `where`, or `{`, found `]`
33

44
fn main() {}

src/test/ui/issues/issue-39616.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ error: expected type, found `0`
44
LL | fn foo(a: [0; 1]) {}
55
| ^ expected type
66

7-
error: expected `;` or `{`, found `]`
7+
error: expected one of `)`, `,`, `->`, `;`, `where`, or `{`, found `]`
88
--> $DIR/issue-39616.rs:1:16
99
|
1010
LL | fn foo(a: [0; 1]) {}
11-
| ^ expected `;` or `{`
11+
| ^ expected one of `)`, `,`, `->`, `;`, `where`, or `{`
1212

1313
error: aborting due to 2 previous errors
1414

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ impl A {
22
//~^ ERROR cannot find type `A` in this scope
33
fn b(self>
44
//~^ ERROR expected one of `)`, `,`, or `:`, found `>`
5-
//~| ERROR expected `;` or `{`, found `>`
5+
//~| ERROR expected one of `->`, `;`, `where`, or `{`, found `>`
66
}
77

88
fn main() {}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ LL | fn b(self>
66
| |
77
| unclosed delimiter
88

9-
error: expected `;` or `{`, found `>`
9+
error: expected one of `->`, `;`, `where`, or `{`, found `>`
1010
--> $DIR/issue-58856-1.rs:3:14
1111
|
1212
LL | impl A {
1313
| - while parsing this item list starting here
1414
LL |
1515
LL | fn b(self>
16-
| ^ expected `;` or `{`
16+
| ^ expected one of `->`, `;`, `where`, or `{`
1717
...
1818
LL | }
1919
| - the item list ends here
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn foo(x: i32): i32 { //~ ERROR expected one of `->`, `;`, `where`, or `{`, found `:`
2+
x
3+
}
4+
5+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected one of `->`, `;`, `where`, or `{`, found `:`
2+
--> $DIR/fn-colon-return-type.rs:1:15
3+
|
4+
LL | fn foo(x: i32): i32 {
5+
| ^ expected one of `->`, `;`, `where`, or `{`
6+
7+
error: aborting due to previous error
8+

src/test/ui/parser/issue-24780.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
// expected one of ..., `>`, ... found `>`
44

55
fn foo() -> Vec<usize>> {
6-
//~^ ERROR expected `;` or `{`, found `>`
6+
//~^ ERROR expected one of `!`, `+`, `::`, `;`, `where`, or `{`, found `>`
77
Vec::new()
88
}

src/test/ui/parser/issue-24780.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: expected `;` or `{`, found `>`
1+
error: expected one of `!`, `+`, `::`, `;`, `where`, or `{`, found `>`
22
--> $DIR/issue-24780.rs:5:23
33
|
44
LL | fn foo() -> Vec<usize>> {
5-
| ^ expected `;` or `{`
5+
| ^ expected one of `!`, `+`, `::`, `;`, `where`, or `{`
66

77
error: aborting due to previous error
88

src/test/ui/parser/issue-6610.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
trait Foo { fn a() } //~ ERROR expected `;` or `{`, found `}`
1+
trait Foo { fn a() } //~ ERROR expected one of `->`, `;`, `where`, or `{`, found `}`
22

33
fn main() {}

src/test/ui/parser/issue-6610.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: expected `;` or `{`, found `}`
1+
error: expected one of `->`, `;`, `where`, or `{`, found `}`
22
--> $DIR/issue-6610.rs:1:20
33
|
44
LL | trait Foo { fn a() }
55
| - ^
66
| | |
7-
| | expected `;` or `{`
7+
| | expected one of `->`, `;`, `where`, or `{`
88
| | the item list ends here
99
| while parsing this item list starting here
1010

src/test/ui/parser/missing_right_paren.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ error: expected one of `:` or `|`, found `)`
2222
LL | fn main((ؼ
2323
| ^ expected one of `:` or `|`
2424

25-
error: expected `;` or `{`, found `<eof>`
25+
error: expected one of `->`, `;`, `where`, or `{`, found `<eof>`
2626
--> $DIR/missing_right_paren.rs:3:11
2727
|
2828
LL | fn main((ؼ
29-
| ^ expected `;` or `{`
29+
| ^ expected one of `->`, `;`, `where`, or `{`
3030

3131
error: aborting due to 4 previous errors
3232

src/test/ui/parser/not-a-pred.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// error-pattern: lt
2-
31
fn f(a: isize, b: isize) : lt(a, b) { }
2+
//~^ ERROR expected one of `->`, `;`, `where`, or `{`, found `:`
43

54
fn lt(a: isize, b: isize) { }
65

src/test/ui/parser/not-a-pred.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: expected `;` or `{`, found `:`
2-
--> $DIR/not-a-pred.rs:3:26
1+
error: expected one of `->`, `;`, `where`, or `{`, found `:`
2+
--> $DIR/not-a-pred.rs:1:26
33
|
44
LL | fn f(a: isize, b: isize) : lt(a, b) { }
5-
| ^ expected `;` or `{`
5+
| ^ expected one of `->`, `;`, `where`, or `{`
66

77
error: aborting due to previous error
88

0 commit comments

Comments
 (0)