diff options
-rw-r--r-- | crates/ra_parser/src/grammar/expressions.rs | 2 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/expressions/atom.rs | 2 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/items.rs | 4 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/items/use_item.rs | 2 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/paths.rs | 6 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/patterns.rs | 4 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/type_params.rs | 2 | ||||
-rw-r--r-- | crates/ra_parser/src/grammar/types.rs | 7 | ||||
-rw-r--r-- | crates/ra_syntax/test_data/parser/inline/ok/0081_for_type.rs | 1 | ||||
-rw-r--r-- | crates/ra_syntax/test_data/parser/inline/ok/0081_for_type.txt | 83 |
10 files changed, 100 insertions, 13 deletions
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index 742076c1a..0495f34ae 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs | |||
@@ -554,7 +554,7 @@ fn arg_list(p: &mut Parser) { | |||
554 | // let _ = format!(); | 554 | // let _ = format!(); |
555 | // } | 555 | // } |
556 | fn path_expr(p: &mut Parser, r: Restrictions) -> (CompletedMarker, BlockLike) { | 556 | fn path_expr(p: &mut Parser, r: Restrictions) -> (CompletedMarker, BlockLike) { |
557 | assert!(paths::is_path_start(p) || p.at(T![<])); | 557 | assert!(paths::is_path_start(p)); |
558 | let m = p.start(); | 558 | let m = p.start(); |
559 | paths::expr_path(p); | 559 | paths::expr_path(p); |
560 | match p.current() { | 560 | match p.current() { |
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index 50c70b3b3..bc942ae01 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs | |||
@@ -62,7 +62,7 @@ pub(super) fn atom_expr(p: &mut Parser, r: Restrictions) -> Option<(CompletedMar | |||
62 | if let Some(m) = literal(p) { | 62 | if let Some(m) = literal(p) { |
63 | return Some((m, BlockLike::NotBlock)); | 63 | return Some((m, BlockLike::NotBlock)); |
64 | } | 64 | } |
65 | if paths::is_path_start(p) || p.at(T![<]) { | 65 | if paths::is_path_start(p) { |
66 | return Some(path_expr(p, r)); | 66 | return Some(path_expr(p, r)); |
67 | } | 67 | } |
68 | let la = p.nth(1); | 68 | let la = p.nth(1); |
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 543af7c4b..b7da44758 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs | |||
@@ -49,7 +49,7 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool, flavor: ItemF | |||
49 | } | 49 | } |
50 | Err(m) => m, | 50 | Err(m) => m, |
51 | }; | 51 | }; |
52 | if paths::is_path_start(p) { | 52 | if paths::is_use_path_start(p) { |
53 | match macro_call(p) { | 53 | match macro_call(p) { |
54 | BlockLike::Block => (), | 54 | BlockLike::Block => (), |
55 | BlockLike::NotBlock => { | 55 | BlockLike::NotBlock => { |
@@ -378,7 +378,7 @@ pub(crate) fn mod_item_list(p: &mut Parser) { | |||
378 | } | 378 | } |
379 | 379 | ||
380 | fn macro_call(p: &mut Parser) -> BlockLike { | 380 | fn macro_call(p: &mut Parser) -> BlockLike { |
381 | assert!(paths::is_path_start(p)); | 381 | assert!(paths::is_use_path_start(p)); |
382 | paths::use_path(p); | 382 | paths::use_path(p); |
383 | macro_call_after_excl(p) | 383 | macro_call_after_excl(p) |
384 | } | 384 | } |
diff --git a/crates/ra_parser/src/grammar/items/use_item.rs b/crates/ra_parser/src/grammar/items/use_item.rs index c3a0b4410..c0c7d0ec6 100644 --- a/crates/ra_parser/src/grammar/items/use_item.rs +++ b/crates/ra_parser/src/grammar/items/use_item.rs | |||
@@ -65,7 +65,7 @@ fn use_tree(p: &mut Parser) { | |||
65 | // use crate::Item; | 65 | // use crate::Item; |
66 | // use self::some::Struct; | 66 | // use self::some::Struct; |
67 | // use crate_name::some_item; | 67 | // use crate_name::some_item; |
68 | _ if paths::is_path_start(p) => { | 68 | _ if paths::is_use_path_start(p) => { |
69 | paths::use_path(p); | 69 | paths::use_path(p); |
70 | match p.current() { | 70 | match p.current() { |
71 | T![as] => { | 71 | T![as] => { |
diff --git a/crates/ra_parser/src/grammar/paths.rs b/crates/ra_parser/src/grammar/paths.rs index 3537b0da1..07eb53b0c 100644 --- a/crates/ra_parser/src/grammar/paths.rs +++ b/crates/ra_parser/src/grammar/paths.rs | |||
@@ -4,6 +4,10 @@ pub(super) const PATH_FIRST: TokenSet = | |||
4 | token_set![IDENT, SELF_KW, SUPER_KW, CRATE_KW, COLONCOLON, L_ANGLE]; | 4 | token_set![IDENT, SELF_KW, SUPER_KW, CRATE_KW, COLONCOLON, L_ANGLE]; |
5 | 5 | ||
6 | pub(super) fn is_path_start(p: &Parser) -> bool { | 6 | pub(super) fn is_path_start(p: &Parser) -> bool { |
7 | is_use_path_start(p) || p.at(T![<]) | ||
8 | } | ||
9 | |||
10 | pub(super) fn is_use_path_start(p: &Parser) -> bool { | ||
7 | match p.current() { | 11 | match p.current() { |
8 | IDENT | T![self] | T![super] | T![crate] | T![::] => true, | 12 | IDENT | T![self] | T![super] | T![crate] | T![::] => true, |
9 | _ => false, | 13 | _ => false, |
@@ -58,7 +62,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) { | |||
58 | if first && p.eat(T![<]) { | 62 | if first && p.eat(T![<]) { |
59 | types::type_(p); | 63 | types::type_(p); |
60 | if p.eat(T![as]) { | 64 | if p.eat(T![as]) { |
61 | if is_path_start(p) { | 65 | if is_use_path_start(p) { |
62 | types::path_type(p); | 66 | types::path_type(p); |
63 | } else { | 67 | } else { |
64 | p.error("expected a trait"); | 68 | p.error("expected a trait"); |
diff --git a/crates/ra_parser/src/grammar/patterns.rs b/crates/ra_parser/src/grammar/patterns.rs index 46034942a..df6000707 100644 --- a/crates/ra_parser/src/grammar/patterns.rs +++ b/crates/ra_parser/src/grammar/patterns.rs | |||
@@ -65,7 +65,7 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> { | |||
65 | { | 65 | { |
66 | return Some(bind_pat(p, true)); | 66 | return Some(bind_pat(p, true)); |
67 | } | 67 | } |
68 | if paths::is_path_start(p) { | 68 | if paths::is_use_path_start(p) { |
69 | return Some(path_pat(p)); | 69 | return Some(path_pat(p)); |
70 | } | 70 | } |
71 | 71 | ||
@@ -118,7 +118,7 @@ fn literal_pat(p: &mut Parser) -> CompletedMarker { | |||
118 | // let Bar(..) = (); | 118 | // let Bar(..) = (); |
119 | // } | 119 | // } |
120 | fn path_pat(p: &mut Parser) -> CompletedMarker { | 120 | fn path_pat(p: &mut Parser) -> CompletedMarker { |
121 | assert!(paths::is_path_start(p)); | 121 | assert!(paths::is_use_path_start(p)); |
122 | let m = p.start(); | 122 | let m = p.start(); |
123 | paths::expr_path(p); | 123 | paths::expr_path(p); |
124 | let kind = match p.current() { | 124 | let kind = match p.current() { |
diff --git a/crates/ra_parser/src/grammar/type_params.rs b/crates/ra_parser/src/grammar/type_params.rs index ef59b59d3..d739df727 100644 --- a/crates/ra_parser/src/grammar/type_params.rs +++ b/crates/ra_parser/src/grammar/type_params.rs | |||
@@ -101,7 +101,7 @@ fn type_bound(p: &mut Parser) -> bool { | |||
101 | match p.current() { | 101 | match p.current() { |
102 | LIFETIME => p.bump(), | 102 | LIFETIME => p.bump(), |
103 | T![for] => types::for_type(p), | 103 | T![for] => types::for_type(p), |
104 | _ if paths::is_path_start(p) => types::path_type_(p, false), | 104 | _ if paths::is_use_path_start(p) => types::path_type_(p, false), |
105 | _ => { | 105 | _ => { |
106 | m.abandon(p); | 106 | m.abandon(p); |
107 | return false; | 107 | return false; |
diff --git a/crates/ra_parser/src/grammar/types.rs b/crates/ra_parser/src/grammar/types.rs index c0b722569..29d173305 100644 --- a/crates/ra_parser/src/grammar/types.rs +++ b/crates/ra_parser/src/grammar/types.rs | |||
@@ -29,7 +29,7 @@ fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) { | |||
29 | T![dyn ] => dyn_trait_type(p), | 29 | T![dyn ] => dyn_trait_type(p), |
30 | // Some path types are not allowed to have bounds (no plus) | 30 | // Some path types are not allowed to have bounds (no plus) |
31 | T![<] => path_type_(p, allow_bounds), | 31 | T![<] => path_type_(p, allow_bounds), |
32 | _ if paths::is_path_start(p) => path_or_macro_type_(p, allow_bounds), | 32 | _ if paths::is_use_path_start(p) => path_or_macro_type_(p, allow_bounds), |
33 | _ => { | 33 | _ => { |
34 | p.err_recover("expected type", TYPE_RECOVERY_SET); | 34 | p.err_recover("expected type", TYPE_RECOVERY_SET); |
35 | } | 35 | } |
@@ -205,6 +205,7 @@ pub(super) fn for_binder(p: &mut Parser) { | |||
205 | // type A = for<'a> fn() -> (); | 205 | // type A = for<'a> fn() -> (); |
206 | // fn foo<T>(_t: &T) where for<'a> &'a T: Iterator {} | 206 | // fn foo<T>(_t: &T) where for<'a> &'a T: Iterator {} |
207 | // fn bar<T>(_t: &T) where for<'a> &'a mut T: Iterator {} | 207 | // fn bar<T>(_t: &T) where for<'a> &'a mut T: Iterator {} |
208 | // fn baz<T>(_t: &T) where for<'a> <&'a T as Baz>::Foo: Iterator {} | ||
208 | pub(super) fn for_type(p: &mut Parser) { | 209 | pub(super) fn for_type(p: &mut Parser) { |
209 | assert!(p.at(T![for])); | 210 | assert!(p.at(T![for])); |
210 | let m = p.start(); | 211 | let m = p.start(); |
@@ -251,7 +252,7 @@ pub(super) fn path_type(p: &mut Parser) { | |||
251 | // type A = foo!(); | 252 | // type A = foo!(); |
252 | // type B = crate::foo!(); | 253 | // type B = crate::foo!(); |
253 | fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) { | 254 | fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) { |
254 | assert!(paths::is_path_start(p) || p.at(T![<])); | 255 | assert!(paths::is_path_start(p)); |
255 | let m = p.start(); | 256 | let m = p.start(); |
256 | paths::type_path(p); | 257 | paths::type_path(p); |
257 | 258 | ||
@@ -270,7 +271,7 @@ fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) { | |||
270 | } | 271 | } |
271 | 272 | ||
272 | pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) { | 273 | pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) { |
273 | assert!(paths::is_path_start(p) || p.at(T![<])); | 274 | assert!(paths::is_path_start(p)); |
274 | let m = p.start(); | 275 | let m = p.start(); |
275 | paths::type_path(p); | 276 | paths::type_path(p); |
276 | 277 | ||
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0081_for_type.rs b/crates/ra_syntax/test_data/parser/inline/ok/0081_for_type.rs index 7cde5c532..d6774d438 100644 --- a/crates/ra_syntax/test_data/parser/inline/ok/0081_for_type.rs +++ b/crates/ra_syntax/test_data/parser/inline/ok/0081_for_type.rs | |||
@@ -1,3 +1,4 @@ | |||
1 | type A = for<'a> fn() -> (); | 1 | type A = for<'a> fn() -> (); |
2 | fn foo<T>(_t: &T) where for<'a> &'a T: Iterator {} | 2 | fn foo<T>(_t: &T) where for<'a> &'a T: Iterator {} |
3 | fn bar<T>(_t: &T) where for<'a> &'a mut T: Iterator {} | 3 | fn bar<T>(_t: &T) where for<'a> &'a mut T: Iterator {} |
4 | fn baz<T>(_t: &T) where for<'a> <&'a T as Baz>::Foo: Iterator {} | ||
diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0081_for_type.txt b/crates/ra_syntax/test_data/parser/inline/ok/0081_for_type.txt index 599cf9452..c12ce4ddb 100644 --- a/crates/ra_syntax/test_data/parser/inline/ok/0081_for_type.txt +++ b/crates/ra_syntax/test_data/parser/inline/ok/0081_for_type.txt | |||
@@ -1,4 +1,4 @@ | |||
1 | SOURCE_FILE@[0; 135) | 1 | SOURCE_FILE@[0; 200) |
2 | TYPE_ALIAS_DEF@[0; 28) | 2 | TYPE_ALIAS_DEF@[0; 28) |
3 | TYPE_KW@[0; 4) "type" | 3 | TYPE_KW@[0; 4) "type" |
4 | WHITESPACE@[4; 5) " " | 4 | WHITESPACE@[4; 5) " " |
@@ -157,3 +157,84 @@ SOURCE_FILE@[0; 135) | |||
157 | L_CURLY@[132; 133) "{" | 157 | L_CURLY@[132; 133) "{" |
158 | R_CURLY@[133; 134) "}" | 158 | R_CURLY@[133; 134) "}" |
159 | WHITESPACE@[134; 135) "\n" | 159 | WHITESPACE@[134; 135) "\n" |
160 | FN_DEF@[135; 199) | ||
161 | FN_KW@[135; 137) "fn" | ||
162 | WHITESPACE@[137; 138) " " | ||
163 | NAME@[138; 141) | ||
164 | IDENT@[138; 141) "baz" | ||
165 | TYPE_PARAM_LIST@[141; 144) | ||
166 | L_ANGLE@[141; 142) "<" | ||
167 | TYPE_PARAM@[142; 143) | ||
168 | NAME@[142; 143) | ||
169 | IDENT@[142; 143) "T" | ||
170 | R_ANGLE@[143; 144) ">" | ||
171 | PARAM_LIST@[144; 152) | ||
172 | L_PAREN@[144; 145) "(" | ||
173 | PARAM@[145; 151) | ||
174 | BIND_PAT@[145; 147) | ||
175 | NAME@[145; 147) | ||
176 | IDENT@[145; 147) "_t" | ||
177 | COLON@[147; 148) ":" | ||
178 | WHITESPACE@[148; 149) " " | ||
179 | REFERENCE_TYPE@[149; 151) | ||
180 | AMP@[149; 150) "&" | ||
181 | PATH_TYPE@[150; 151) | ||
182 | PATH@[150; 151) | ||
183 | PATH_SEGMENT@[150; 151) | ||
184 | NAME_REF@[150; 151) | ||
185 | IDENT@[150; 151) "T" | ||
186 | R_PAREN@[151; 152) ")" | ||
187 | WHITESPACE@[152; 153) " " | ||
188 | WHERE_CLAUSE@[153; 196) | ||
189 | WHERE_KW@[153; 158) "where" | ||
190 | WHITESPACE@[158; 159) " " | ||
191 | WHERE_PRED@[159; 196) | ||
192 | FOR_TYPE@[159; 186) | ||
193 | FOR_KW@[159; 162) "for" | ||
194 | TYPE_PARAM_LIST@[162; 166) | ||
195 | L_ANGLE@[162; 163) "<" | ||
196 | LIFETIME_PARAM@[163; 165) | ||
197 | LIFETIME@[163; 165) "\'a" | ||
198 | R_ANGLE@[165; 166) ">" | ||
199 | WHITESPACE@[166; 167) " " | ||
200 | PATH_TYPE@[167; 186) | ||
201 | PATH@[167; 186) | ||
202 | PATH@[167; 181) | ||
203 | PATH_SEGMENT@[167; 181) | ||
204 | L_ANGLE@[167; 168) "<" | ||
205 | REFERENCE_TYPE@[168; 173) | ||
206 | AMP@[168; 169) "&" | ||
207 | LIFETIME@[169; 171) "\'a" | ||
208 | WHITESPACE@[171; 172) " " | ||
209 | PATH_TYPE@[172; 173) | ||
210 | PATH@[172; 173) | ||
211 | PATH_SEGMENT@[172; 173) | ||
212 | NAME_REF@[172; 173) | ||
213 | IDENT@[172; 173) "T" | ||
214 | WHITESPACE@[173; 174) " " | ||
215 | AS_KW@[174; 176) "as" | ||
216 | WHITESPACE@[176; 177) " " | ||
217 | PATH_TYPE@[177; 180) | ||
218 | PATH@[177; 180) | ||
219 | PATH_SEGMENT@[177; 180) | ||
220 | NAME_REF@[177; 180) | ||
221 | IDENT@[177; 180) "Baz" | ||
222 | R_ANGLE@[180; 181) ">" | ||
223 | COLONCOLON@[181; 183) "::" | ||
224 | PATH_SEGMENT@[183; 186) | ||
225 | NAME_REF@[183; 186) | ||
226 | IDENT@[183; 186) "Foo" | ||
227 | COLON@[186; 187) ":" | ||
228 | WHITESPACE@[187; 188) " " | ||
229 | TYPE_BOUND_LIST@[188; 196) | ||
230 | TYPE_BOUND@[188; 196) | ||
231 | PATH_TYPE@[188; 196) | ||
232 | PATH@[188; 196) | ||
233 | PATH_SEGMENT@[188; 196) | ||
234 | NAME_REF@[188; 196) | ||
235 | IDENT@[188; 196) "Iterator" | ||
236 | WHITESPACE@[196; 197) " " | ||
237 | BLOCK@[197; 199) | ||
238 | L_CURLY@[197; 198) "{" | ||
239 | R_CURLY@[198; 199) "}" | ||
240 | WHITESPACE@[199; 200) "\n" | ||