diff options
author | Erlend Tobiassen <[email protected]> | 2019-01-22 12:17:10 +0000 |
---|---|---|
committer | Erlend Tobiassen <[email protected]> | 2019-01-22 12:17:10 +0000 |
commit | 2b22f5fb4398378d999db98ea270ceb415dfff22 (patch) | |
tree | 8b22ab009aaa53c904d12131468fe754f69d44d4 /crates/ra_syntax/src | |
parent | 1aba42128f79993a092a8c0b3747acdc8f1b1be7 (diff) |
Optimistically bail out of where clause loop if not at start of a type or lifetime
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/grammar/type_params.rs | 28 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar/types.rs | 8 |
2 files changed, 24 insertions, 12 deletions
diff --git a/crates/ra_syntax/src/grammar/type_params.rs b/crates/ra_syntax/src/grammar/type_params.rs index f33ec10f5..a7eacf97a 100644 --- a/crates/ra_syntax/src/grammar/type_params.rs +++ b/crates/ra_syntax/src/grammar/type_params.rs | |||
@@ -105,27 +105,31 @@ pub(super) fn opt_where_clause(p: &mut Parser) { | |||
105 | let m = p.start(); | 105 | let m = p.start(); |
106 | p.bump(); | 106 | p.bump(); |
107 | 107 | ||
108 | if is_where_clause_end(p) { | 108 | while is_where_predicate(p) { |
109 | // Empty where clause | 109 | where_predicate(p); |
110 | } else { | ||
111 | loop { | ||
112 | where_predicate(p); | ||
113 | 110 | ||
114 | let comma = p.eat(COMMA); | 111 | let comma = p.eat(COMMA); |
115 | 112 | ||
116 | if is_where_clause_end(p) { | 113 | if is_where_clause_end(p) { |
117 | break; | 114 | break; |
118 | } | 115 | } |
119 | 116 | ||
120 | if !comma { | 117 | if !comma { |
121 | p.error("expected comma"); | 118 | p.error("expected comma"); |
122 | } | ||
123 | } | 119 | } |
124 | } | 120 | } |
125 | 121 | ||
126 | m.complete(p, WHERE_CLAUSE); | 122 | m.complete(p, WHERE_CLAUSE); |
127 | } | 123 | } |
128 | 124 | ||
125 | fn is_where_predicate(p: &mut Parser) -> bool { | ||
126 | match p.current() { | ||
127 | LIFETIME => true, | ||
128 | IMPL_KW => false, | ||
129 | _ => types::is_type_start(p), | ||
130 | } | ||
131 | } | ||
132 | |||
129 | fn is_where_clause_end(p: &mut Parser) -> bool { | 133 | fn is_where_clause_end(p: &mut Parser) -> bool { |
130 | p.current() == L_CURLY || p.current() == SEMI || p.current() == EQ | 134 | p.current() == L_CURLY || p.current() == SEMI || p.current() == EQ |
131 | } | 135 | } |
diff --git a/crates/ra_syntax/src/grammar/types.rs b/crates/ra_syntax/src/grammar/types.rs index 21d89d83b..83a54c190 100644 --- a/crates/ra_syntax/src/grammar/types.rs +++ b/crates/ra_syntax/src/grammar/types.rs | |||
@@ -36,6 +36,14 @@ fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) { | |||
36 | } | 36 | } |
37 | } | 37 | } |
38 | 38 | ||
39 | pub(super) fn is_type_start(p: &mut Parser) -> bool { | ||
40 | match p.current() { | ||
41 | L_PAREN | EXCL | STAR | L_BRACK | AMP | UNDERSCORE | FN_KW | FOR_KW | IMPL_KW | DYN_KW | ||
42 | | L_ANGLE => true, | ||
43 | _ => paths::is_path_start(p), | ||
44 | } | ||
45 | } | ||
46 | |||
39 | pub(super) fn ascription(p: &mut Parser) { | 47 | pub(super) fn ascription(p: &mut Parser) { |
40 | p.expect(COLON); | 48 | p.expect(COLON); |
41 | type_(p) | 49 | type_(p) |