aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_syntax/src/grammar/type_params.rs28
-rw-r--r--crates/ra_syntax/src/grammar/types.rs8
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
125fn 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
129fn is_where_clause_end(p: &mut Parser) -> bool { 133fn 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
39pub(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
39pub(super) fn ascription(p: &mut Parser) { 47pub(super) fn ascription(p: &mut Parser) {
40 p.expect(COLON); 48 p.expect(COLON);
41 type_(p) 49 type_(p)