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,10 +105,7 @@ 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 {
|
||||
while is_where_predicate(p) {
|
||||
where_predicate(p);
|
||||
|
||||
let comma = p.eat(COMMA);
|
||||
|
@ -121,11 +118,18 @@ pub(super) fn opt_where_clause(p: &mut Parser) {
|
|||
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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue