diff options
| author | bors <bors@rust-lang.org> | 2023-09-29 11:14:02 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-29 11:14:02 +0000 |
| commit | 50678e0da07a8d3e93733f7fc53c595d81f94925 (patch) | |
| tree | 959b133a60cdd02c20332bf4e75d58fe49c10704 | |
| parent | 87e2c310f9f1770aa09c1223ae4a5b7b8ce33360 (diff) | |
| parent | a382e649ca090b3ef9a6fe2f823d1a4282580f86 (diff) | |
| download | rust-50678e0da07a8d3e93733f7fc53c595d81f94925.tar.gz rust-50678e0da07a8d3e93733f7fc53c595d81f94925.zip | |
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.
3 files changed, 50 insertions, 1 deletions
diff --git a/crates/parser/src/grammar/params.rs b/crates/parser/src/grammar/params.rs index 74eae9151a2..846da28cb01 100644 --- a/crates/parser/src/grammar/params.rs +++ b/crates/parser/src/grammar/params.rs @@ -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![,]) { diff --git a/crates/parser/test_data/parser/inline/err/0023_empty_param_slot.rast b/crates/parser/test_data/parser/inline/err/0023_empty_param_slot.rast new file mode 100644 index 00000000000..39e35a81ee2 --- /dev/null +++ b/crates/parser/test_data/parser/inline/err/0023_empty_param_slot.rast @@ -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 diff --git a/crates/parser/test_data/parser/inline/err/0023_empty_param_slot.rs b/crates/parser/test_data/parser/inline/err/0023_empty_param_slot.rs new file mode 100644 index 00000000000..0adf7b8d2f0 --- /dev/null +++ b/crates/parser/test_data/parser/inline/err/0023_empty_param_slot.rs @@ -0,0 +1 @@ +fn f(y: i32, ,t: i32) {} |
