Optimistically bail out of where clause loop if not at start of a type or lifetime

This commit is contained in:
Erlend Tobiassen 2019-01-22 13:17:10 +01:00
parent 1aba42128f
commit 2b22f5fb43
2 changed files with 24 additions and 12 deletions

View file

@ -105,27 +105,31 @@ pub(super) fn opt_where_clause(p: &mut Parser) {
let m = p.start();
p.bump();
if is_where_clause_end(p) {
// Empty where clause
} else {
loop {
where_predicate(p);
while is_where_predicate(p) {
where_predicate(p);
let comma = p.eat(COMMA);
let comma = p.eat(COMMA);
if is_where_clause_end(p) {
break;
}
if is_where_clause_end(p) {
break;
}
if !comma {
p.error("expected comma");
}
if !comma {
p.error("expected comma");
}
}
m.complete(p, WHERE_CLAUSE);
}
fn is_where_predicate(p: &mut Parser) -> bool {
match p.current() {
LIFETIME => true,
IMPL_KW => false,
_ => types::is_type_start(p),
}
}
fn is_where_clause_end(p: &mut Parser) -> bool {
p.current() == L_CURLY || p.current() == SEMI || p.current() == EQ
}

View file

@ -36,6 +36,14 @@ fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) {
}
}
pub(super) fn is_type_start(p: &mut Parser) -> bool {
match p.current() {
L_PAREN | EXCL | STAR | L_BRACK | AMP | UNDERSCORE | FN_KW | FOR_KW | IMPL_KW | DYN_KW
| L_ANGLE => true,
_ => paths::is_path_start(p),
}
}
pub(super) fn ascription(p: &mut Parser) {
p.expect(COLON);
type_(p)