mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 17:28:09 +00:00
trait items
This commit is contained in:
parent
2fb854ccda
commit
64a65a4ff4
7 changed files with 120 additions and 5 deletions
|
@ -14,7 +14,8 @@ fn const_or_static(p: &mut Parser, kw: SyntaxKind) {
|
|||
p.eat(MUT_KW); // TODO: validator to forbid const mut
|
||||
name(p);
|
||||
types::ascription(p);
|
||||
p.expect(EQ);
|
||||
expressions::expr(p);
|
||||
if p.eat(EQ) {
|
||||
expressions::expr(p);
|
||||
}
|
||||
p.expect(SEMI);
|
||||
}
|
||||
|
|
|
@ -240,7 +240,11 @@ fn fn_item(p: &mut Parser) {
|
|||
// fn foo<T>() where T: Copy {}
|
||||
type_params::where_clause(p);
|
||||
|
||||
expressions::block(p);
|
||||
// test fn_decl
|
||||
// trait T { fn foo(); }
|
||||
if !p.eat(SEMI) {
|
||||
expressions::block(p);
|
||||
}
|
||||
}
|
||||
|
||||
// test type_item
|
||||
|
@ -255,12 +259,17 @@ fn type_item(p: &mut Parser) {
|
|||
// type Result<T> = ();
|
||||
type_params::type_param_list(p);
|
||||
|
||||
if p.at(COLON) {
|
||||
type_params::bounds(p);
|
||||
}
|
||||
|
||||
// test type_item_where_clause
|
||||
// type Foo where Foo: Copy = ();
|
||||
type_params::where_clause(p);
|
||||
|
||||
p.expect(EQ);
|
||||
types::type_(p);
|
||||
if p.eat(EQ) {
|
||||
types::type_(p);
|
||||
}
|
||||
p.expect(SEMI);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,16 @@ pub(super) fn trait_item(p: &mut Parser) {
|
|||
}
|
||||
type_params::where_clause(p);
|
||||
p.expect(L_CURLY);
|
||||
// test trait_item_items
|
||||
// impl F {
|
||||
// type A: Clone;
|
||||
// const B: i32;
|
||||
// fn foo() {}
|
||||
// fn bar(&self);
|
||||
// }
|
||||
while !p.at(EOF) && !p.at(R_CURLY) {
|
||||
item_or_macro(p, true);
|
||||
}
|
||||
p.expect(R_CURLY);
|
||||
}
|
||||
|
||||
|
|
6
tests/data/parser/inline/0090_trait_item_items.rs
Normal file
6
tests/data/parser/inline/0090_trait_item_items.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
impl F {
|
||||
type A: Clone;
|
||||
const B: i32;
|
||||
fn foo() {}
|
||||
fn bar(&self);
|
||||
}
|
67
tests/data/parser/inline/0090_trait_item_items.txt
Normal file
67
tests/data/parser/inline/0090_trait_item_items.txt
Normal file
|
@ -0,0 +1,67 @@
|
|||
FILE@[0; 83)
|
||||
IMPL_ITEM@[0; 82)
|
||||
IMPL_KW@[0; 4)
|
||||
WHITESPACE@[4; 5)
|
||||
PATH_TYPE@[5; 6)
|
||||
PATH@[5; 6)
|
||||
PATH_SEGMENT@[5; 6)
|
||||
NAME_REF@[5; 6)
|
||||
IDENT@[5; 6) "F"
|
||||
WHITESPACE@[6; 7)
|
||||
L_CURLY@[7; 8)
|
||||
WHITESPACE@[8; 13)
|
||||
TYPE_ITEM@[13; 27)
|
||||
TYPE_KW@[13; 17)
|
||||
WHITESPACE@[17; 18)
|
||||
NAME@[18; 19)
|
||||
IDENT@[18; 19) "A"
|
||||
COLON@[19; 20)
|
||||
WHITESPACE@[20; 21)
|
||||
PATH@[21; 26)
|
||||
PATH_SEGMENT@[21; 26)
|
||||
NAME_REF@[21; 26)
|
||||
IDENT@[21; 26) "Clone"
|
||||
SEMI@[26; 27)
|
||||
WHITESPACE@[27; 32)
|
||||
CONST_ITEM@[32; 45)
|
||||
CONST_KW@[32; 37)
|
||||
WHITESPACE@[37; 38)
|
||||
NAME@[38; 39)
|
||||
IDENT@[38; 39) "B"
|
||||
COLON@[39; 40)
|
||||
WHITESPACE@[40; 41)
|
||||
PATH_TYPE@[41; 44)
|
||||
PATH@[41; 44)
|
||||
PATH_SEGMENT@[41; 44)
|
||||
NAME_REF@[41; 44)
|
||||
IDENT@[41; 44) "i32"
|
||||
SEMI@[44; 45)
|
||||
WHITESPACE@[45; 50)
|
||||
FN_ITEM@[50; 61)
|
||||
FN_KW@[50; 52)
|
||||
WHITESPACE@[52; 53)
|
||||
NAME@[53; 56)
|
||||
IDENT@[53; 56) "foo"
|
||||
PARAM_LIST@[56; 58)
|
||||
L_PAREN@[56; 57)
|
||||
R_PAREN@[57; 58)
|
||||
WHITESPACE@[58; 59)
|
||||
BLOCK_EXPR@[59; 61)
|
||||
L_CURLY@[59; 60)
|
||||
R_CURLY@[60; 61)
|
||||
WHITESPACE@[61; 66)
|
||||
FN_ITEM@[66; 80)
|
||||
FN_KW@[66; 68)
|
||||
WHITESPACE@[68; 69)
|
||||
NAME@[69; 72)
|
||||
IDENT@[69; 72) "bar"
|
||||
PARAM_LIST@[72; 79)
|
||||
L_PAREN@[72; 73)
|
||||
SELF_PARAM@[73; 78)
|
||||
AMP@[73; 74)
|
||||
SELF_KW@[74; 78)
|
||||
R_PAREN@[78; 79)
|
||||
SEMI@[79; 80)
|
||||
WHITESPACE@[80; 81)
|
||||
R_CURLY@[81; 82)
|
||||
WHITESPACE@[82; 83)
|
1
tests/data/parser/inline/0091_fn_decl.rs
Normal file
1
tests/data/parser/inline/0091_fn_decl.rs
Normal file
|
@ -0,0 +1 @@
|
|||
trait T { fn foo(); }
|
21
tests/data/parser/inline/0091_fn_decl.txt
Normal file
21
tests/data/parser/inline/0091_fn_decl.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
FILE@[0; 22)
|
||||
TRAIT_ITEM@[0; 21)
|
||||
TRAIT_KW@[0; 5)
|
||||
WHITESPACE@[5; 6)
|
||||
NAME@[6; 7)
|
||||
IDENT@[6; 7) "T"
|
||||
WHITESPACE@[7; 8)
|
||||
L_CURLY@[8; 9)
|
||||
WHITESPACE@[9; 10)
|
||||
FN_ITEM@[10; 19)
|
||||
FN_KW@[10; 12)
|
||||
WHITESPACE@[12; 13)
|
||||
NAME@[13; 16)
|
||||
IDENT@[13; 16) "foo"
|
||||
PARAM_LIST@[16; 18)
|
||||
L_PAREN@[16; 17)
|
||||
R_PAREN@[17; 18)
|
||||
SEMI@[18; 19)
|
||||
WHITESPACE@[19; 20)
|
||||
R_CURLY@[20; 21)
|
||||
WHITESPACE@[21; 22)
|
Loading…
Reference in a new issue