Parse range patterns in let statement with type annotation

This commit is contained in:
Ryo Yoshida 2022-08-09 00:00:22 +09:00
parent a81c7a2974
commit b14062aaec
No known key found for this signature in database
GPG Key ID: E25698A930586171
3 changed files with 32 additions and 5 deletions

View File

@ -103,6 +103,8 @@ fn pattern_single_r(p: &mut Parser<'_>, recovery_set: TokenSet) {
// ^
// `let 0 .. =`
// ^
// `let 0..: _ =`
// ^
// (1.., _)
// ^
// `Some(0 .. )`
@ -111,9 +113,12 @@ fn pattern_single_r(p: &mut Parser<'_>, recovery_set: TokenSet) {
// ^
// `[0..]`
// ^
if p.at(T![=]) | p.at(T![')']) | p.at(T![,]) | p.at(T!['}']) | p.at(T![']']) {
if matches!(p.current(), T![=] | T![,] | T![:] | T![')'] | T!['}'] | T![']']) {
// test half_open_range_pat
// fn f() { let 0 .. = 1u32; }
// fn f() {
// let 0 .. = 1u32;
// let 0..: _ = 1u32;
// }
} else {
atom_pat(p, recovery_set);
}

View File

@ -11,7 +11,7 @@ SOURCE_FILE
BLOCK_EXPR
STMT_LIST
L_CURLY "{"
WHITESPACE " "
WHITESPACE "\n "
LET_STMT
LET_KW "let"
WHITESPACE " "
@ -27,6 +27,25 @@ SOURCE_FILE
LITERAL
INT_NUMBER "1u32"
SEMICOLON ";"
WHITESPACE "\n "
LET_STMT
LET_KW "let"
WHITESPACE " "
RANGE_PAT
LITERAL_PAT
LITERAL
INT_NUMBER "0"
DOT2 ".."
COLON ":"
WHITESPACE " "
INFER_TYPE
UNDERSCORE "_"
WHITESPACE " "
EQ "="
WHITESPACE " "
LITERAL
INT_NUMBER "1u32"
SEMICOLON ";"
WHITESPACE "\n"
R_CURLY "}"
WHITESPACE "\n"

View File

@ -1 +1,4 @@
fn f() { let 0 .. = 1u32; }
fn f() {
let 0 .. = 1u32;
let 0..: _ = 1u32;
}