diff options
Diffstat (limited to 'crates')
3 files changed, 141 insertions, 0 deletions
diff --git a/crates/ra_parser/src/grammar/items/traits.rs b/crates/ra_parser/src/grammar/items/traits.rs index 964fd3041..03dae3cdb 100644 --- a/crates/ra_parser/src/grammar/items/traits.rs +++ b/crates/ra_parser/src/grammar/items/traits.rs | |||
@@ -10,6 +10,16 @@ pub(super) fn trait_def(p: &mut Parser) { | |||
10 | p.bump(T![trait]); | 10 | p.bump(T![trait]); |
11 | name_r(p, ITEM_RECOVERY_SET); | 11 | name_r(p, ITEM_RECOVERY_SET); |
12 | type_params::opt_type_param_list(p); | 12 | type_params::opt_type_param_list(p); |
13 | // test trait_alias | ||
14 | // trait Z<U> = T<U>; | ||
15 | // trait Z<U> = T<U> where U: Copy; | ||
16 | // trait Z<U> = where Self: T<U>; | ||
17 | if p.eat(T![=]) { | ||
18 | type_params::bounds_without_colon(p); | ||
19 | type_params::opt_where_clause(p); | ||
20 | p.expect(T![;]); | ||
21 | return; | ||
22 | } | ||
13 | if p.at(T![:]) { | 23 | if p.at(T![:]) { |
14 | type_params::bounds(p); | 24 | type_params::bounds(p); |
15 | } | 25 | } |
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0151_trait_alias.rs b/crates/ra_syntax/test_data/parser/inline/ok/0151_trait_alias.rs new file mode 100644 index 000000000..4bd428ee4 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0151_trait_alias.rs | |||
@@ -0,0 +1,3 @@ | |||
1 | trait Z<U> = T<U>; | ||
2 | trait Z<U> = T<U> where U: Copy; | ||
3 | trait Z<U> = where Self: T<U>; | ||
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0151_trait_alias.txt b/crates/ra_syntax/test_data/parser/inline/ok/0151_trait_alias.txt new file mode 100644 index 000000000..de1536ef0 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0151_trait_alias.txt | |||
@@ -0,0 +1,128 @@ | |||
1 | SOURCE_FILE@[0; 83) | ||
2 | TRAIT_DEF@[0; 18) | ||
3 | TRAIT_KW@[0; 5) "trait" | ||
4 | WHITESPACE@[5; 6) " " | ||
5 | NAME@[6; 7) | ||
6 | IDENT@[6; 7) "Z" | ||
7 | TYPE_PARAM_LIST@[7; 10) | ||
8 | L_ANGLE@[7; 8) "<" | ||
9 | TYPE_PARAM@[8; 9) | ||
10 | NAME@[8; 9) | ||
11 | IDENT@[8; 9) "U" | ||
12 | R_ANGLE@[9; 10) ">" | ||
13 | WHITESPACE@[10; 11) " " | ||
14 | EQ@[11; 12) "=" | ||
15 | WHITESPACE@[12; 13) " " | ||
16 | TYPE_BOUND_LIST@[13; 17) | ||
17 | TYPE_BOUND@[13; 17) | ||
18 | PATH_TYPE@[13; 17) | ||
19 | PATH@[13; 17) | ||
20 | PATH_SEGMENT@[13; 17) | ||
21 | NAME_REF@[13; 14) | ||
22 | IDENT@[13; 14) "T" | ||
23 | TYPE_ARG_LIST@[14; 17) | ||
24 | L_ANGLE@[14; 15) "<" | ||
25 | TYPE_ARG@[15; 16) | ||
26 | PATH_TYPE@[15; 16) | ||
27 | PATH@[15; 16) | ||
28 | PATH_SEGMENT@[15; 16) | ||
29 | NAME_REF@[15; 16) | ||
30 | IDENT@[15; 16) "U" | ||
31 | R_ANGLE@[16; 17) ">" | ||
32 | SEMI@[17; 18) ";" | ||
33 | WHITESPACE@[18; 19) "\n" | ||
34 | TRAIT_DEF@[19; 51) | ||
35 | TRAIT_KW@[19; 24) "trait" | ||
36 | WHITESPACE@[24; 25) " " | ||
37 | NAME@[25; 26) | ||
38 | IDENT@[25; 26) "Z" | ||
39 | TYPE_PARAM_LIST@[26; 29) | ||
40 | L_ANGLE@[26; 27) "<" | ||
41 | TYPE_PARAM@[27; 28) | ||
42 | NAME@[27; 28) | ||
43 | IDENT@[27; 28) "U" | ||
44 | R_ANGLE@[28; 29) ">" | ||
45 | WHITESPACE@[29; 30) " " | ||
46 | EQ@[30; 31) "=" | ||
47 | WHITESPACE@[31; 32) " " | ||
48 | TYPE_BOUND_LIST@[32; 36) | ||
49 | TYPE_BOUND@[32; 36) | ||
50 | PATH_TYPE@[32; 36) | ||
51 | PATH@[32; 36) | ||
52 | PATH_SEGMENT@[32; 36) | ||
53 | NAME_REF@[32; 33) | ||
54 | IDENT@[32; 33) "T" | ||
55 | TYPE_ARG_LIST@[33; 36) | ||
56 | L_ANGLE@[33; 34) "<" | ||
57 | TYPE_ARG@[34; 35) | ||
58 | PATH_TYPE@[34; 35) | ||
59 | PATH@[34; 35) | ||
60 | PATH_SEGMENT@[34; 35) | ||
61 | NAME_REF@[34; 35) | ||
62 | IDENT@[34; 35) "U" | ||
63 | R_ANGLE@[35; 36) ">" | ||
64 | WHITESPACE@[36; 37) " " | ||
65 | WHERE_CLAUSE@[37; 50) | ||
66 | WHERE_KW@[37; 42) "where" | ||
67 | WHITESPACE@[42; 43) " " | ||
68 | WHERE_PRED@[43; 50) | ||
69 | PATH_TYPE@[43; 44) | ||
70 | PATH@[43; 44) | ||
71 | PATH_SEGMENT@[43; 44) | ||
72 | NAME_REF@[43; 44) | ||
73 | IDENT@[43; 44) "U" | ||
74 | COLON@[44; 45) ":" | ||
75 | WHITESPACE@[45; 46) " " | ||
76 | TYPE_BOUND_LIST@[46; 50) | ||
77 | TYPE_BOUND@[46; 50) | ||
78 | PATH_TYPE@[46; 50) | ||
79 | PATH@[46; 50) | ||
80 | PATH_SEGMENT@[46; 50) | ||
81 | NAME_REF@[46; 50) | ||
82 | IDENT@[46; 50) "Copy" | ||
83 | SEMI@[50; 51) ";" | ||
84 | WHITESPACE@[51; 52) "\n" | ||
85 | TRAIT_DEF@[52; 82) | ||
86 | TRAIT_KW@[52; 57) "trait" | ||
87 | WHITESPACE@[57; 58) " " | ||
88 | NAME@[58; 59) | ||
89 | IDENT@[58; 59) "Z" | ||
90 | TYPE_PARAM_LIST@[59; 62) | ||
91 | L_ANGLE@[59; 60) "<" | ||
92 | TYPE_PARAM@[60; 61) | ||
93 | NAME@[60; 61) | ||
94 | IDENT@[60; 61) "U" | ||
95 | R_ANGLE@[61; 62) ">" | ||
96 | WHITESPACE@[62; 63) " " | ||
97 | EQ@[63; 64) "=" | ||
98 | WHITESPACE@[64; 65) " " | ||
99 | TYPE_BOUND_LIST@[65; 65) | ||
100 | WHERE_CLAUSE@[65; 81) | ||
101 | WHERE_KW@[65; 70) "where" | ||
102 | WHITESPACE@[70; 71) " " | ||
103 | WHERE_PRED@[71; 81) | ||
104 | PATH_TYPE@[71; 75) | ||
105 | PATH@[71; 75) | ||
106 | PATH_SEGMENT@[71; 75) | ||
107 | NAME_REF@[71; 75) | ||
108 | IDENT@[71; 75) "Self" | ||
109 | COLON@[75; 76) ":" | ||
110 | WHITESPACE@[76; 77) " " | ||
111 | TYPE_BOUND_LIST@[77; 81) | ||
112 | TYPE_BOUND@[77; 81) | ||
113 | PATH_TYPE@[77; 81) | ||
114 | PATH@[77; 81) | ||
115 | PATH_SEGMENT@[77; 81) | ||
116 | NAME_REF@[77; 78) | ||
117 | IDENT@[77; 78) "T" | ||
118 | TYPE_ARG_LIST@[78; 81) | ||
119 | L_ANGLE@[78; 79) "<" | ||
120 | TYPE_ARG@[79; 80) | ||
121 | PATH_TYPE@[79; 80) | ||
122 | PATH@[79; 80) | ||
123 | PATH_SEGMENT@[79; 80) | ||
124 | NAME_REF@[79; 80) | ||
125 | IDENT@[79; 80) "U" | ||
126 | R_ANGLE@[80; 81) ">" | ||
127 | SEMI@[81; 82) ";" | ||
128 | WHITESPACE@[82; 83) "\n" | ||