mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 01:17:27 +00:00
Merge #1884
1884: Add indexing to record_field_pat r=matklad a=kjeremy Fixes #1870 Co-authored-by: kjeremy <kjeremy@gmail.com>
This commit is contained in:
commit
3575f7c4a2
3 changed files with 91 additions and 2 deletions
|
@ -168,6 +168,7 @@ fn record_field_pat_list(p: &mut Parser) {
|
|||
T![.] if p.at(T![..]) => p.bump(T![..]),
|
||||
|
||||
IDENT if p.nth(1) == T![:] => record_field_pat(p),
|
||||
INT_NUMBER if p.nth(1) == T![:] => record_field_pat(p),
|
||||
T!['{'] => error_block(p, "expected ident"),
|
||||
T![box] => {
|
||||
box_pat(p);
|
||||
|
@ -184,12 +185,21 @@ fn record_field_pat_list(p: &mut Parser) {
|
|||
m.complete(p, RECORD_FIELD_PAT_LIST);
|
||||
}
|
||||
|
||||
// test record_field_pat
|
||||
// fn foo() {
|
||||
// let S { 0: 1 } = ();
|
||||
// let S { x: 1 } = ();
|
||||
// }
|
||||
fn record_field_pat(p: &mut Parser) {
|
||||
assert!(p.at(IDENT));
|
||||
assert!(p.at(IDENT) || p.at(INT_NUMBER));
|
||||
assert!(p.nth(1) == T![:]);
|
||||
|
||||
let m = p.start();
|
||||
name(p);
|
||||
|
||||
if !p.eat(INT_NUMBER) {
|
||||
name(p)
|
||||
}
|
||||
|
||||
p.bump_any();
|
||||
pattern(p);
|
||||
m.complete(p, RECORD_FIELD_PAT);
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
fn foo() {
|
||||
let S { 0: 1 } = ();
|
||||
let S { x: 1 } = ();
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
SOURCE_FILE@[0; 63)
|
||||
FN_DEF@[0; 62)
|
||||
FN_KW@[0; 2) "fn"
|
||||
WHITESPACE@[2; 3) " "
|
||||
NAME@[3; 6)
|
||||
IDENT@[3; 6) "foo"
|
||||
PARAM_LIST@[6; 8)
|
||||
L_PAREN@[6; 7) "("
|
||||
R_PAREN@[7; 8) ")"
|
||||
WHITESPACE@[8; 9) " "
|
||||
BLOCK_EXPR@[9; 62)
|
||||
BLOCK@[9; 62)
|
||||
L_CURLY@[9; 10) "{"
|
||||
WHITESPACE@[10; 15) "\n "
|
||||
LET_STMT@[15; 35)
|
||||
LET_KW@[15; 18) "let"
|
||||
WHITESPACE@[18; 19) " "
|
||||
RECORD_PAT@[19; 29)
|
||||
PATH@[19; 20)
|
||||
PATH_SEGMENT@[19; 20)
|
||||
NAME_REF@[19; 20)
|
||||
IDENT@[19; 20) "S"
|
||||
WHITESPACE@[20; 21) " "
|
||||
RECORD_FIELD_PAT_LIST@[21; 29)
|
||||
L_CURLY@[21; 22) "{"
|
||||
WHITESPACE@[22; 23) " "
|
||||
RECORD_FIELD_PAT@[23; 27)
|
||||
INT_NUMBER@[23; 24) "0"
|
||||
COLON@[24; 25) ":"
|
||||
WHITESPACE@[25; 26) " "
|
||||
LITERAL_PAT@[26; 27)
|
||||
LITERAL@[26; 27)
|
||||
INT_NUMBER@[26; 27) "1"
|
||||
WHITESPACE@[27; 28) " "
|
||||
R_CURLY@[28; 29) "}"
|
||||
WHITESPACE@[29; 30) " "
|
||||
EQ@[30; 31) "="
|
||||
WHITESPACE@[31; 32) " "
|
||||
TUPLE_EXPR@[32; 34)
|
||||
L_PAREN@[32; 33) "("
|
||||
R_PAREN@[33; 34) ")"
|
||||
SEMI@[34; 35) ";"
|
||||
WHITESPACE@[35; 40) "\n "
|
||||
LET_STMT@[40; 60)
|
||||
LET_KW@[40; 43) "let"
|
||||
WHITESPACE@[43; 44) " "
|
||||
RECORD_PAT@[44; 54)
|
||||
PATH@[44; 45)
|
||||
PATH_SEGMENT@[44; 45)
|
||||
NAME_REF@[44; 45)
|
||||
IDENT@[44; 45) "S"
|
||||
WHITESPACE@[45; 46) " "
|
||||
RECORD_FIELD_PAT_LIST@[46; 54)
|
||||
L_CURLY@[46; 47) "{"
|
||||
WHITESPACE@[47; 48) " "
|
||||
RECORD_FIELD_PAT@[48; 52)
|
||||
NAME@[48; 49)
|
||||
IDENT@[48; 49) "x"
|
||||
COLON@[49; 50) ":"
|
||||
WHITESPACE@[50; 51) " "
|
||||
LITERAL_PAT@[51; 52)
|
||||
LITERAL@[51; 52)
|
||||
INT_NUMBER@[51; 52) "1"
|
||||
WHITESPACE@[52; 53) " "
|
||||
R_CURLY@[53; 54) "}"
|
||||
WHITESPACE@[54; 55) " "
|
||||
EQ@[55; 56) "="
|
||||
WHITESPACE@[56; 57) " "
|
||||
TUPLE_EXPR@[57; 59)
|
||||
L_PAREN@[57; 58) "("
|
||||
R_PAREN@[58; 59) ")"
|
||||
SEMI@[59; 60) ";"
|
||||
WHITESPACE@[60; 61) "\n"
|
||||
R_CURLY@[61; 62) "}"
|
||||
WHITESPACE@[62; 63) "\n"
|
Loading…
Reference in a new issue