mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
Fix some parser bugs
This commit is contained in:
parent
d1eceefeb8
commit
9149fd2c0c
9 changed files with 213 additions and 15 deletions
|
@ -62,7 +62,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) {
|
|||
}
|
||||
SELF_KW | SUPER_KW => p.bump(),
|
||||
_ => {
|
||||
p.error("expected identifier");
|
||||
p.err_and_bump("expected identifier");
|
||||
}
|
||||
};
|
||||
segment.complete(p, PATH_SEGMENT);
|
||||
|
|
|
@ -60,6 +60,7 @@ fn atom_pat(p: &mut Parser) -> Option<CompletedMarker> {
|
|||
// let Bar(..) = ();
|
||||
// }
|
||||
fn path_pat(p: &mut Parser) -> CompletedMarker {
|
||||
assert!(paths::is_path_start(p));
|
||||
let m = p.start();
|
||||
paths::expr_path(p);
|
||||
let kind = match p.current() {
|
||||
|
@ -116,8 +117,11 @@ fn struct_pat_fields(p: &mut Parser) {
|
|||
p.bump();
|
||||
pattern(p);
|
||||
}
|
||||
_ => {
|
||||
REF_KW | MUT_KW | IDENT => {
|
||||
bind_pat(p, false);
|
||||
},
|
||||
_ => {
|
||||
p.err_and_bump("expected ident");
|
||||
}
|
||||
}
|
||||
if !p.at(R_CURLY) {
|
||||
|
|
|
@ -121,7 +121,12 @@ fn where_predicate(p: &mut Parser) {
|
|||
lifetime_bounds(p)
|
||||
} else {
|
||||
types::path_type(p);
|
||||
bounds(p);
|
||||
if p.at(COLON) {
|
||||
bounds(p);
|
||||
} else {
|
||||
p.error("expected colon")
|
||||
}
|
||||
|
||||
}
|
||||
m.complete(p, WHERE_PRED);
|
||||
}
|
||||
|
|
|
@ -166,8 +166,11 @@ fn fn_pointer_type(p: &mut Parser) {
|
|||
p.error("expected `fn`");
|
||||
return;
|
||||
}
|
||||
|
||||
params::param_list_opt_patterns(p);
|
||||
if p.at(L_PAREN) {
|
||||
params::param_list_opt_patterns(p);
|
||||
} else {
|
||||
p.error("expected parameters")
|
||||
}
|
||||
// test fn_pointer_type_with_ret
|
||||
// type F = fn() -> ();
|
||||
fn_ret_type(p);
|
||||
|
|
|
@ -1,20 +1,16 @@
|
|||
FILE@[0; 12)
|
||||
USE_ITEM@[0; 9)
|
||||
USE_ITEM@[0; 12)
|
||||
USE_KW@[0; 3)
|
||||
WHITESPACE@[3; 4)
|
||||
USE_TREE@[4; 9)
|
||||
PATH@[4; 9)
|
||||
USE_TREE@[4; 11)
|
||||
PATH@[4; 11)
|
||||
PATH@[4; 7)
|
||||
PATH_SEGMENT@[4; 7)
|
||||
NAME_REF@[4; 7)
|
||||
IDENT@[4; 7) "foo"
|
||||
COLONCOLON@[7; 9)
|
||||
err: `expected identifier`
|
||||
err: `expected SEMI`
|
||||
err: `expected an item`
|
||||
PATH_SEGMENT@[9; 9)
|
||||
ERROR@[9; 11)
|
||||
INT_NUMBER@[9; 11) "92"
|
||||
err: `expected an item`
|
||||
ERROR@[11; 12)
|
||||
PATH_SEGMENT@[9; 11)
|
||||
ERROR@[9; 11)
|
||||
INT_NUMBER@[9; 11) "92"
|
||||
SEMI@[11; 12)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
fn foo<T>() where T {}
|
|
@ -0,0 +1,31 @@
|
|||
FILE@[0; 23)
|
||||
FUNCTION@[0; 22)
|
||||
FN_KW@[0; 2)
|
||||
WHITESPACE@[2; 3)
|
||||
NAME@[3; 6)
|
||||
IDENT@[3; 6) "foo"
|
||||
TYPE_PARAM_LIST@[6; 9)
|
||||
L_ANGLE@[6; 7)
|
||||
TYPE_PARAM@[7; 8)
|
||||
NAME@[7; 8)
|
||||
IDENT@[7; 8) "T"
|
||||
R_ANGLE@[8; 9)
|
||||
PARAM_LIST@[9; 11)
|
||||
L_PAREN@[9; 10)
|
||||
R_PAREN@[10; 11)
|
||||
WHITESPACE@[11; 12)
|
||||
WHERE_CLAUSE@[12; 19)
|
||||
WHERE_KW@[12; 17)
|
||||
WHITESPACE@[17; 18)
|
||||
WHERE_PRED@[18; 19)
|
||||
PATH_TYPE@[18; 19)
|
||||
PATH@[18; 19)
|
||||
PATH_SEGMENT@[18; 19)
|
||||
NAME_REF@[18; 19)
|
||||
IDENT@[18; 19) "T"
|
||||
err: `expected colon`
|
||||
WHITESPACE@[19; 20)
|
||||
BLOCK_EXPR@[20; 22)
|
||||
L_CURLY@[20; 21)
|
||||
R_CURLY@[21; 22)
|
||||
WHITESPACE@[22; 23)
|
11
crates/libsyntax2/tests/data/parser/ok/0030_traits.rs
Normal file
11
crates/libsyntax2/tests/data/parser/ok/0030_traits.rs
Normal file
|
@ -0,0 +1,11 @@
|
|||
pub trait WriteMessage {
|
||||
fn write_message(&FrontendMessage);
|
||||
}
|
||||
|
||||
trait Runnable {
|
||||
fn handler();
|
||||
}
|
||||
|
||||
trait TraitWithExpr {
|
||||
fn fn_with_expr(x: [i32; 1]);
|
||||
}
|
147
crates/libsyntax2/tests/data/parser/ok/0030_traits.txt
Normal file
147
crates/libsyntax2/tests/data/parser/ok/0030_traits.txt
Normal file
|
@ -0,0 +1,147 @@
|
|||
FILE@[0; 164)
|
||||
TRAIT@[0; 164)
|
||||
VISIBILITY@[0; 3)
|
||||
PUB_KW@[0; 3)
|
||||
WHITESPACE@[3; 4)
|
||||
TRAIT_KW@[4; 9)
|
||||
WHITESPACE@[9; 10)
|
||||
NAME@[10; 22)
|
||||
IDENT@[10; 22) "WriteMessage"
|
||||
WHITESPACE@[22; 23)
|
||||
L_CURLY@[23; 24)
|
||||
WHITESPACE@[24; 29)
|
||||
FUNCTION@[29; 164)
|
||||
FN_KW@[29; 31)
|
||||
WHITESPACE@[31; 32)
|
||||
NAME@[32; 45)
|
||||
IDENT@[32; 45) "write_message"
|
||||
PARAM_LIST@[45; 164)
|
||||
L_PAREN@[45; 46)
|
||||
PARAM@[46; 63)
|
||||
REF_PAT@[46; 62)
|
||||
AMP@[46; 47)
|
||||
BIND_PAT@[47; 62)
|
||||
NAME@[47; 62)
|
||||
IDENT@[47; 62) "FrontendMessage"
|
||||
err: `expected COLON`
|
||||
err: `expected type`
|
||||
ERROR@[62; 63)
|
||||
R_PAREN@[62; 63)
|
||||
err: `expected COMMA`
|
||||
err: `expected pattern`
|
||||
PARAM@[63; 66)
|
||||
ERROR@[63; 64)
|
||||
SEMI@[63; 64)
|
||||
err: `expected COLON`
|
||||
WHITESPACE@[64; 65)
|
||||
err: `expected type`
|
||||
ERROR@[65; 66)
|
||||
R_CURLY@[65; 66)
|
||||
err: `expected COMMA`
|
||||
WHITESPACE@[66; 68)
|
||||
err: `expected pattern`
|
||||
PARAM@[68; 82)
|
||||
ERROR@[68; 73)
|
||||
TRAIT_KW@[68; 73)
|
||||
err: `expected COLON`
|
||||
WHITESPACE@[73; 74)
|
||||
PATH_TYPE@[74; 82)
|
||||
PATH@[74; 82)
|
||||
PATH_SEGMENT@[74; 82)
|
||||
NAME_REF@[74; 82)
|
||||
IDENT@[74; 82) "Runnable"
|
||||
err: `expected COMMA`
|
||||
WHITESPACE@[82; 83)
|
||||
err: `expected pattern`
|
||||
PARAM@[83; 91)
|
||||
ERROR@[83; 84)
|
||||
L_CURLY@[83; 84)
|
||||
err: `expected COLON`
|
||||
WHITESPACE@[84; 89)
|
||||
FN_POINTER_TYPE@[89; 91)
|
||||
FN_KW@[89; 91)
|
||||
err: `expected parameters`
|
||||
err: `expected COMMA`
|
||||
WHITESPACE@[91; 92)
|
||||
PARAM@[92; 102)
|
||||
TUPLE_STRUCT_PAT@[92; 101)
|
||||
PATH@[92; 99)
|
||||
PATH_SEGMENT@[92; 99)
|
||||
NAME_REF@[92; 99)
|
||||
IDENT@[92; 99) "handler"
|
||||
L_PAREN@[99; 100)
|
||||
R_PAREN@[100; 101)
|
||||
err: `expected COLON`
|
||||
err: `expected type`
|
||||
ERROR@[101; 102)
|
||||
SEMI@[101; 102)
|
||||
err: `expected COMMA`
|
||||
WHITESPACE@[102; 103)
|
||||
err: `expected pattern`
|
||||
PARAM@[103; 111)
|
||||
ERROR@[103; 104)
|
||||
R_CURLY@[103; 104)
|
||||
err: `expected COLON`
|
||||
WHITESPACE@[104; 106)
|
||||
err: `expected type`
|
||||
ERROR@[106; 111)
|
||||
TRAIT_KW@[106; 111)
|
||||
err: `expected COMMA`
|
||||
WHITESPACE@[111; 112)
|
||||
PARAM@[112; 164)
|
||||
STRUCT_PAT@[112; 163)
|
||||
PATH@[112; 125)
|
||||
PATH_SEGMENT@[112; 125)
|
||||
NAME_REF@[112; 125)
|
||||
IDENT@[112; 125) "TraitWithExpr"
|
||||
WHITESPACE@[125; 126)
|
||||
L_CURLY@[126; 127)
|
||||
WHITESPACE@[127; 132)
|
||||
err: `expected ident`
|
||||
ERROR@[132; 134)
|
||||
FN_KW@[132; 134)
|
||||
err: `expected COMMA`
|
||||
WHITESPACE@[134; 135)
|
||||
BIND_PAT@[135; 147)
|
||||
NAME@[135; 147)
|
||||
IDENT@[135; 147) "fn_with_expr"
|
||||
err: `expected COMMA`
|
||||
err: `expected ident`
|
||||
ERROR@[147; 148)
|
||||
L_PAREN@[147; 148)
|
||||
err: `expected COMMA`
|
||||
IDENT@[148; 149) "x"
|
||||
COLON@[149; 150)
|
||||
WHITESPACE@[150; 151)
|
||||
SLICE_PAT@[151; 159)
|
||||
L_BRACK@[151; 152)
|
||||
BIND_PAT@[152; 155)
|
||||
NAME@[152; 155)
|
||||
IDENT@[152; 155) "i32"
|
||||
err: `expected COMMA`
|
||||
err: `expected pattern`
|
||||
ERROR@[155; 156)
|
||||
SEMI@[155; 156)
|
||||
err: `expected COMMA`
|
||||
WHITESPACE@[156; 157)
|
||||
LITERAL@[157; 158)
|
||||
INT_NUMBER@[157; 158) "1"
|
||||
R_BRACK@[158; 159)
|
||||
err: `expected COMMA`
|
||||
err: `expected ident`
|
||||
ERROR@[159; 160)
|
||||
R_PAREN@[159; 160)
|
||||
err: `expected COMMA`
|
||||
err: `expected ident`
|
||||
ERROR@[160; 161)
|
||||
SEMI@[160; 161)
|
||||
WHITESPACE@[161; 162)
|
||||
R_CURLY@[162; 163)
|
||||
err: `expected COLON`
|
||||
WHITESPACE@[163; 164)
|
||||
err: `expected type`
|
||||
err: `expected COMMA`
|
||||
err: `expected R_PAREN`
|
||||
err: `expected block`
|
||||
err: `expected R_CURLY`
|
||||
ERROR@[164; 164)
|
Loading…
Reference in a new issue