diff options
Diffstat (limited to 'crates/ra_syntax/src/grammar/types.rs')
-rw-r--r-- | crates/ra_syntax/src/grammar/types.rs | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/crates/ra_syntax/src/grammar/types.rs b/crates/ra_syntax/src/grammar/types.rs index ed2718e73..811d399d4 100644 --- a/crates/ra_syntax/src/grammar/types.rs +++ b/crates/ra_syntax/src/grammar/types.rs | |||
@@ -11,6 +11,14 @@ pub(super) const TYPE_FIRST: TokenSet = token_set_union![ | |||
11 | const TYPE_RECOVERY_SET: TokenSet = token_set![R_PAREN, COMMA]; | 11 | const TYPE_RECOVERY_SET: TokenSet = token_set![R_PAREN, COMMA]; |
12 | 12 | ||
13 | pub(super) fn type_(p: &mut Parser) { | 13 | pub(super) fn type_(p: &mut Parser) { |
14 | type_with_bounds_cond(p, true); | ||
15 | } | ||
16 | |||
17 | pub(super) fn type_no_bounds(p: &mut Parser) { | ||
18 | type_with_bounds_cond(p, false); | ||
19 | } | ||
20 | |||
21 | fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) { | ||
14 | match p.current() { | 22 | match p.current() { |
15 | L_PAREN => paren_or_tuple_type(p), | 23 | L_PAREN => paren_or_tuple_type(p), |
16 | EXCL => never_type(p), | 24 | EXCL => never_type(p), |
@@ -22,8 +30,9 @@ pub(super) fn type_(p: &mut Parser) { | |||
22 | FOR_KW => for_type(p), | 30 | FOR_KW => for_type(p), |
23 | IMPL_KW => impl_trait_type(p), | 31 | IMPL_KW => impl_trait_type(p), |
24 | DYN_KW => dyn_trait_type(p), | 32 | DYN_KW => dyn_trait_type(p), |
25 | L_ANGLE => path_type(p), | 33 | // Some path types are not allowed to have bounds (no plus) |
26 | _ if paths::is_path_start(p) => path_type(p), | 34 | L_ANGLE => path_type_(p, allow_bounds), |
35 | _ if paths::is_path_start(p) => path_type_(p, allow_bounds), | ||
27 | _ => { | 36 | _ => { |
28 | p.err_recover("expected type", TYPE_RECOVERY_SET); | 37 | p.err_recover("expected type", TYPE_RECOVERY_SET); |
29 | } | 38 | } |
@@ -35,10 +44,6 @@ pub(super) fn ascription(p: &mut Parser) { | |||
35 | type_(p) | 44 | type_(p) |
36 | } | 45 | } |
37 | 46 | ||
38 | fn type_no_plus(p: &mut Parser) { | ||
39 | type_(p); | ||
40 | } | ||
41 | |||
42 | fn paren_or_tuple_type(p: &mut Parser) { | 47 | fn paren_or_tuple_type(p: &mut Parser) { |
43 | assert!(p.at(L_PAREN)); | 48 | assert!(p.at(L_PAREN)); |
44 | let m = p.start(); | 49 | let m = p.start(); |
@@ -101,7 +106,7 @@ fn pointer_type(p: &mut Parser) { | |||
101 | } | 106 | } |
102 | }; | 107 | }; |
103 | 108 | ||
104 | type_no_plus(p); | 109 | type_no_bounds(p); |
105 | m.complete(p, POINTER_TYPE); | 110 | m.complete(p, POINTER_TYPE); |
106 | } | 111 | } |
107 | 112 | ||
@@ -147,7 +152,7 @@ fn reference_type(p: &mut Parser) { | |||
147 | p.bump(); | 152 | p.bump(); |
148 | p.eat(LIFETIME); | 153 | p.eat(LIFETIME); |
149 | p.eat(MUT_KW); | 154 | p.eat(MUT_KW); |
150 | type_no_plus(p); | 155 | type_no_bounds(p); |
151 | m.complete(p, REFERENCE_TYPE); | 156 | m.complete(p, REFERENCE_TYPE); |
152 | } | 157 | } |
153 | 158 | ||