Skip to content

Commit

Permalink
Rely on regular "expected"/"found" parser error for fn
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Oct 25, 2020
1 parent 07a63e6 commit 040f568
Show file tree
Hide file tree
Showing 15 changed files with 36 additions and 31 deletions.
8 changes: 0 additions & 8 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Expand Up @@ -1550,14 +1550,6 @@ impl<'a> Parser<'a> {
}
}

pub(super) fn expected_semi_or_open_brace<T>(&mut self) -> PResult<'a, T> {
let token_str = super::token_descr(&self.token);
let msg = &format!("expected `;` or `{{`, found {}", token_str);
let mut err = self.struct_span_err(self.token.span, msg);
err.span_label(self.token.span, "expected `;` or `{`");
Err(err)
}

pub(super) fn eat_incorrect_doc_comment_for_param_type(&mut self) {
if let token::DocComment(..) = self.token.kind {
self.struct_span_err(
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_parse/src/parser/item.rs
Expand Up @@ -1551,10 +1551,9 @@ impl<'a> Parser<'a> {
attrs: &mut Vec<Attribute>,
sig_hi: &mut Span,
) -> PResult<'a, Option<P<Block>>> {
let (inner_attrs, body) = if self.check(&token::Semi) {
let (inner_attrs, body) = if self.eat(&token::Semi) {
// Include the trailing semicolon in the span of the signature
*sig_hi = self.token.span;
self.bump(); // `;`
*sig_hi = self.prev_token.span;
(Vec::new(), None)
} else if self.check(&token::OpenDelim(token::Brace)) || self.token.is_whole_block() {
self.parse_inner_attrs_and_block().map(|(attrs, body)| (attrs, Some(body)))?
Expand All @@ -1574,7 +1573,9 @@ impl<'a> Parser<'a> {
.emit();
(Vec::new(), Some(self.mk_block_err(span)))
} else {
return self.expected_semi_or_open_brace();
return self
.expected_one_of_not_found(&[], &[token::Semi, token::OpenDelim(token::Brace)])
.map(|_| None);
};
attrs.extend(inner_attrs);
Ok(body)
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-39616.rs
@@ -1,4 +1,4 @@
fn foo(a: [0; 1]) {} //~ ERROR expected type, found `0`
//~| ERROR expected `;` or `{`, found `]`
//~| ERROR expected one of `)`, `,`, `->`, `;`, `where`, or `{`, found `]`

fn main() {}
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-39616.stderr
Expand Up @@ -4,11 +4,11 @@ error: expected type, found `0`
LL | fn foo(a: [0; 1]) {}
| ^ expected type

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

error: aborting due to 2 previous errors

2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-58856-1.rs
Expand Up @@ -2,7 +2,7 @@ impl A {
//~^ ERROR cannot find type `A` in this scope
fn b(self>
//~^ ERROR expected one of `)`, `,`, or `:`, found `>`
//~| ERROR expected `;` or `{`, found `>`
//~| ERROR expected one of `->`, `;`, `where`, or `{`, found `>`
}

fn main() {}
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-58856-1.stderr
Expand Up @@ -6,14 +6,14 @@ LL | fn b(self>
| |
| unclosed delimiter

error: expected `;` or `{`, found `>`
error: expected one of `->`, `;`, `where`, or `{`, found `>`
--> $DIR/issue-58856-1.rs:3:14
|
LL | impl A {
| - while parsing this item list starting here
LL |
LL | fn b(self>
| ^ expected `;` or `{`
| ^ expected one of `->`, `;`, `where`, or `{`
...
LL | }
| - the item list ends here
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/parser/fn-colon-return-type.rs
@@ -0,0 +1,5 @@
fn foo(x: i32): i32 { //~ ERROR expected one of `->`, `;`, `where`, or `{`, found `:`
x
}

fn main() {}
8 changes: 8 additions & 0 deletions src/test/ui/parser/fn-colon-return-type.stderr
@@ -0,0 +1,8 @@
error: expected one of `->`, `;`, `where`, or `{`, found `:`
--> $DIR/fn-colon-return-type.rs:1:15
|
LL | fn foo(x: i32): i32 {
| ^ expected one of `->`, `;`, `where`, or `{`

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/parser/issue-24780.rs
Expand Up @@ -3,6 +3,6 @@
// expected one of ..., `>`, ... found `>`

fn foo() -> Vec<usize>> {
//~^ ERROR expected `;` or `{`, found `>`
//~^ ERROR expected one of `!`, `+`, `::`, `;`, `where`, or `{`, found `>`
Vec::new()
}
4 changes: 2 additions & 2 deletions src/test/ui/parser/issue-24780.stderr
@@ -1,8 +1,8 @@
error: expected `;` or `{`, found `>`
error: expected one of `!`, `+`, `::`, `;`, `where`, or `{`, found `>`
--> $DIR/issue-24780.rs:5:23
|
LL | fn foo() -> Vec<usize>> {
| ^ expected `;` or `{`
| ^ expected one of `!`, `+`, `::`, `;`, `where`, or `{`

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/parser/issue-6610.rs
@@ -1,3 +1,3 @@
trait Foo { fn a() } //~ ERROR expected `;` or `{`, found `}`
trait Foo { fn a() } //~ ERROR expected one of `->`, `;`, `where`, or `{`, found `}`

fn main() {}
4 changes: 2 additions & 2 deletions src/test/ui/parser/issue-6610.stderr
@@ -1,10 +1,10 @@
error: expected `;` or `{`, found `}`
error: expected one of `->`, `;`, `where`, or `{`, found `}`
--> $DIR/issue-6610.rs:1:20
|
LL | trait Foo { fn a() }
| - ^
| | |
| | expected `;` or `{`
| | expected one of `->`, `;`, `where`, or `{`
| | the item list ends here
| while parsing this item list starting here

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/missing_right_paren.stderr
Expand Up @@ -22,11 +22,11 @@ error: expected one of `:` or `|`, found `)`
LL | fn main((ؼ
| ^ expected one of `:` or `|`

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

error: aborting due to 4 previous errors

3 changes: 1 addition & 2 deletions src/test/ui/parser/not-a-pred.rs
@@ -1,6 +1,5 @@
// error-pattern: lt

fn f(a: isize, b: isize) : lt(a, b) { }
//~^ ERROR expected one of `->`, `;`, `where`, or `{`, found `:`

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

Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/parser/not-a-pred.stderr
@@ -1,8 +1,8 @@
error: expected `;` or `{`, found `:`
--> $DIR/not-a-pred.rs:3:26
error: expected one of `->`, `;`, `where`, or `{`, found `:`
--> $DIR/not-a-pred.rs:1:26
|
LL | fn f(a: isize, b: isize) : lt(a, b) { }
| ^ expected `;` or `{`
| ^ expected one of `->`, `;`, `where`, or `{`

error: aborting due to previous error

0 comments on commit 040f568

Please sign in to comment.