mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
Optimistically bail out of where clause loop if not at start of a type or lifetime
This commit is contained in:
parent
1aba42128f
commit
2b22f5fb43
2 changed files with 24 additions and 12 deletions
|
@ -105,27 +105,31 @@ pub(super) fn opt_where_clause(p: &mut Parser) {
|
||||||
let m = p.start();
|
let m = p.start();
|
||||||
p.bump();
|
p.bump();
|
||||||
|
|
||||||
if is_where_clause_end(p) {
|
while is_where_predicate(p) {
|
||||||
// Empty where clause
|
where_predicate(p);
|
||||||
} else {
|
|
||||||
loop {
|
|
||||||
where_predicate(p);
|
|
||||||
|
|
||||||
let comma = p.eat(COMMA);
|
let comma = p.eat(COMMA);
|
||||||
|
|
||||||
if is_where_clause_end(p) {
|
if is_where_clause_end(p) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !comma {
|
if !comma {
|
||||||
p.error("expected comma");
|
p.error("expected comma");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m.complete(p, WHERE_CLAUSE);
|
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 {
|
fn is_where_clause_end(p: &mut Parser) -> bool {
|
||||||
p.current() == L_CURLY || p.current() == SEMI || p.current() == EQ
|
p.current() == L_CURLY || p.current() == SEMI || p.current() == EQ
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
pub(super) fn ascription(p: &mut Parser) {
|
||||||
p.expect(COLON);
|
p.expect(COLON);
|
||||||
type_(p)
|
type_(p)
|
||||||
|
|
Loading…
Reference in a new issue