Merge #2779
2779: Parse trait aliases r=matklad a=kiljacken Implements the needed changes to correctly parse trait aliases. This is my first change in the parser code, so would appreciate a comment on whether this is the right way to go about it. Co-authored-by: Emil Lauridsen <mine809@gmail.com>
This commit is contained in:
commit
b77a7e29a5
@ -10,6 +10,16 @@ pub(super) fn trait_def(p: &mut Parser) {
|
||||
p.bump(T![trait]);
|
||||
name_r(p, ITEM_RECOVERY_SET);
|
||||
type_params::opt_type_param_list(p);
|
||||
// test trait_alias
|
||||
// trait Z<U> = T<U>;
|
||||
// trait Z<U> = T<U> where U: Copy;
|
||||
// trait Z<U> = where Self: T<U>;
|
||||
if p.eat(T![=]) {
|
||||
type_params::bounds_without_colon(p);
|
||||
type_params::opt_where_clause(p);
|
||||
p.expect(T![;]);
|
||||
return;
|
||||
}
|
||||
if p.at(T![:]) {
|
||||
type_params::bounds(p);
|
||||
}
|
||||
|
@ -0,0 +1,3 @@
|
||||
trait Z<U> = T<U>;
|
||||
trait Z<U> = T<U> where U: Copy;
|
||||
trait Z<U> = where Self: T<U>;
|
128
crates/ra_syntax/test_data/parser/inline/ok/0151_trait_alias.txt
Normal file
128
crates/ra_syntax/test_data/parser/inline/ok/0151_trait_alias.txt
Normal file
@ -0,0 +1,128 @@
|
||||
SOURCE_FILE@[0; 83)
|
||||
TRAIT_DEF@[0; 18)
|
||||
TRAIT_KW@[0; 5) "trait"
|
||||
WHITESPACE@[5; 6) " "
|
||||
NAME@[6; 7)
|
||||
IDENT@[6; 7) "Z"
|
||||
TYPE_PARAM_LIST@[7; 10)
|
||||
L_ANGLE@[7; 8) "<"
|
||||
TYPE_PARAM@[8; 9)
|
||||
NAME@[8; 9)
|
||||
IDENT@[8; 9) "U"
|
||||
R_ANGLE@[9; 10) ">"
|
||||
WHITESPACE@[10; 11) " "
|
||||
EQ@[11; 12) "="
|
||||
WHITESPACE@[12; 13) " "
|
||||
TYPE_BOUND_LIST@[13; 17)
|
||||
TYPE_BOUND@[13; 17)
|
||||
PATH_TYPE@[13; 17)
|
||||
PATH@[13; 17)
|
||||
PATH_SEGMENT@[13; 17)
|
||||
NAME_REF@[13; 14)
|
||||
IDENT@[13; 14) "T"
|
||||
TYPE_ARG_LIST@[14; 17)
|
||||
L_ANGLE@[14; 15) "<"
|
||||
TYPE_ARG@[15; 16)
|
||||
PATH_TYPE@[15; 16)
|
||||
PATH@[15; 16)
|
||||
PATH_SEGMENT@[15; 16)
|
||||
NAME_REF@[15; 16)
|
||||
IDENT@[15; 16) "U"
|
||||
R_ANGLE@[16; 17) ">"
|
||||
SEMI@[17; 18) ";"
|
||||
WHITESPACE@[18; 19) "\n"
|
||||
TRAIT_DEF@[19; 51)
|
||||
TRAIT_KW@[19; 24) "trait"
|
||||
WHITESPACE@[24; 25) " "
|
||||
NAME@[25; 26)
|
||||
IDENT@[25; 26) "Z"
|
||||
TYPE_PARAM_LIST@[26; 29)
|
||||
L_ANGLE@[26; 27) "<"
|
||||
TYPE_PARAM@[27; 28)
|
||||
NAME@[27; 28)
|
||||
IDENT@[27; 28) "U"
|
||||
R_ANGLE@[28; 29) ">"
|
||||
WHITESPACE@[29; 30) " "
|
||||
EQ@[30; 31) "="
|
||||
WHITESPACE@[31; 32) " "
|
||||
TYPE_BOUND_LIST@[32; 36)
|
||||
TYPE_BOUND@[32; 36)
|
||||
PATH_TYPE@[32; 36)
|
||||
PATH@[32; 36)
|
||||
PATH_SEGMENT@[32; 36)
|
||||
NAME_REF@[32; 33)
|
||||
IDENT@[32; 33) "T"
|
||||
TYPE_ARG_LIST@[33; 36)
|
||||
L_ANGLE@[33; 34) "<"
|
||||
TYPE_ARG@[34; 35)
|
||||
PATH_TYPE@[34; 35)
|
||||
PATH@[34; 35)
|
||||
PATH_SEGMENT@[34; 35)
|
||||
NAME_REF@[34; 35)
|
||||
IDENT@[34; 35) "U"
|
||||
R_ANGLE@[35; 36) ">"
|
||||
WHITESPACE@[36; 37) " "
|
||||
WHERE_CLAUSE@[37; 50)
|
||||
WHERE_KW@[37; 42) "where"
|
||||
WHITESPACE@[42; 43) " "
|
||||
WHERE_PRED@[43; 50)
|
||||
PATH_TYPE@[43; 44)
|
||||
PATH@[43; 44)
|
||||
PATH_SEGMENT@[43; 44)
|
||||
NAME_REF@[43; 44)
|
||||
IDENT@[43; 44) "U"
|
||||
COLON@[44; 45) ":"
|
||||
WHITESPACE@[45; 46) " "
|
||||
TYPE_BOUND_LIST@[46; 50)
|
||||
TYPE_BOUND@[46; 50)
|
||||
PATH_TYPE@[46; 50)
|
||||
PATH@[46; 50)
|
||||
PATH_SEGMENT@[46; 50)
|
||||
NAME_REF@[46; 50)
|
||||
IDENT@[46; 50) "Copy"
|
||||
SEMI@[50; 51) ";"
|
||||
WHITESPACE@[51; 52) "\n"
|
||||
TRAIT_DEF@[52; 82)
|
||||
TRAIT_KW@[52; 57) "trait"
|
||||
WHITESPACE@[57; 58) " "
|
||||
NAME@[58; 59)
|
||||
IDENT@[58; 59) "Z"
|
||||
TYPE_PARAM_LIST@[59; 62)
|
||||
L_ANGLE@[59; 60) "<"
|
||||
TYPE_PARAM@[60; 61)
|
||||
NAME@[60; 61)
|
||||
IDENT@[60; 61) "U"
|
||||
R_ANGLE@[61; 62) ">"
|
||||
WHITESPACE@[62; 63) " "
|
||||
EQ@[63; 64) "="
|
||||
WHITESPACE@[64; 65) " "
|
||||
TYPE_BOUND_LIST@[65; 65)
|
||||
WHERE_CLAUSE@[65; 81)
|
||||
WHERE_KW@[65; 70) "where"
|
||||
WHITESPACE@[70; 71) " "
|
||||
WHERE_PRED@[71; 81)
|
||||
PATH_TYPE@[71; 75)
|
||||
PATH@[71; 75)
|
||||
PATH_SEGMENT@[71; 75)
|
||||
NAME_REF@[71; 75)
|
||||
IDENT@[71; 75) "Self"
|
||||
COLON@[75; 76) ":"
|
||||
WHITESPACE@[76; 77) " "
|
||||
TYPE_BOUND_LIST@[77; 81)
|
||||
TYPE_BOUND@[77; 81)
|
||||
PATH_TYPE@[77; 81)
|
||||
PATH@[77; 81)
|
||||
PATH_SEGMENT@[77; 81)
|
||||
NAME_REF@[77; 78)
|
||||
IDENT@[77; 78) "T"
|
||||
TYPE_ARG_LIST@[78; 81)
|
||||
L_ANGLE@[78; 79) "<"
|
||||
TYPE_ARG@[79; 80)
|
||||
PATH_TYPE@[79; 80)
|
||||
PATH@[79; 80)
|
||||
PATH_SEGMENT@[79; 80)
|
||||
NAME_REF@[79; 80)
|
||||
IDENT@[79; 80) "U"
|
||||
R_ANGLE@[80; 81) ">"
|
||||
SEMI@[81; 82) ";"
|
||||
WHITESPACE@[82; 83) "\n"
|
Loading…
Reference in New Issue
Block a user