Auto merge of #15682 - Veykril:param-list-recov, r=Veykril

Recover better on missing parameter in param list

We should do the same for argument lists, but that is more tricky to fix.
This commit is contained in:
bors 2023-09-29 11:14:02 +00:00
commit 50678e0da0
3 changed files with 50 additions and 1 deletions

View file

@ -7,6 +7,9 @@ use super::*;
// fn b(x: i32) {}
// fn c(x: i32, ) {}
// fn d(x: i32, y: ()) {}
// test_err empty_param_slot
// fn f(y: i32, ,t: i32) {}
pub(super) fn param_list_fn_def(p: &mut Parser<'_>) {
list_(p, Flavor::FnDef);
}
@ -71,7 +74,11 @@ fn list_(p: &mut Parser<'_>, flavor: Flavor) {
if !p.at_ts(PARAM_FIRST.union(ATTRIBUTE_FIRST)) {
p.error("expected value parameter");
m.abandon(p);
break;
if p.eat(T![,]) {
continue;
} else {
break;
}
}
param(p, m, flavor);
if !p.at(T![,]) {

View file

@ -0,0 +1,41 @@
SOURCE_FILE
FN
FN_KW "fn"
WHITESPACE " "
NAME
IDENT "f"
PARAM_LIST
L_PAREN "("
PARAM
IDENT_PAT
NAME
IDENT "y"
COLON ":"
WHITESPACE " "
PATH_TYPE
PATH
PATH_SEGMENT
NAME_REF
IDENT "i32"
COMMA ","
WHITESPACE " "
COMMA ","
PARAM
IDENT_PAT
NAME
IDENT "t"
COLON ":"
WHITESPACE " "
PATH_TYPE
PATH
PATH_SEGMENT
NAME_REF
IDENT "i32"
R_PAREN ")"
WHITESPACE " "
BLOCK_EXPR
STMT_LIST
L_CURLY "{"
R_CURLY "}"
WHITESPACE "\n"
error 12: expected value parameter

View file

@ -0,0 +1 @@
fn f(y: i32, ,t: i32) {}