mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
Allow types to the left of : in where predicates.
This commit is contained in:
parent
b59334e67a
commit
1059ec74e2
1 changed files with 27 additions and 24 deletions
|
@ -104,22 +104,32 @@ pub(super) fn opt_where_clause(p: &mut Parser) {
|
|||
}
|
||||
let m = p.start();
|
||||
p.bump();
|
||||
loop {
|
||||
if !(paths::is_path_start(p)
|
||||
|| p.current() == LIFETIME
|
||||
|| p.current() == FOR_KW
|
||||
|| p.current() == L_ANGLE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
where_predicate(p);
|
||||
if p.current() != L_CURLY && p.current() != SEMI && p.current() != EQ {
|
||||
p.expect(COMMA);
|
||||
|
||||
if is_where_clause_end(p) {
|
||||
// Empty where clause
|
||||
} else {
|
||||
loop {
|
||||
where_predicate(p);
|
||||
|
||||
let comma = p.eat(COMMA);
|
||||
|
||||
if is_where_clause_end(p) {
|
||||
break;
|
||||
}
|
||||
|
||||
if !comma {
|
||||
p.error("expected comma")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m.complete(p, WHERE_CLAUSE);
|
||||
}
|
||||
|
||||
fn is_where_clause_end(p: &mut Parser) -> bool {
|
||||
p.current() == L_CURLY || p.current() == SEMI || p.current() == EQ
|
||||
}
|
||||
|
||||
fn where_predicate(p: &mut Parser) {
|
||||
let m = p.start();
|
||||
match p.current() {
|
||||
|
@ -131,20 +141,13 @@ fn where_predicate(p: &mut Parser) {
|
|||
p.error("expected colon");
|
||||
}
|
||||
}
|
||||
IMPL_KW => {
|
||||
p.error("expected lifetime or type");
|
||||
return;
|
||||
}
|
||||
_ => {
|
||||
// test where_pred_for
|
||||
// fn test<F>()
|
||||
// where
|
||||
// for<'a> F: Fn(&'a str)
|
||||
// { }
|
||||
if p.at(FOR_KW) {
|
||||
types::for_binder(p);
|
||||
}
|
||||
if paths::is_path_start(p) || p.at(L_ANGLE) {
|
||||
types::path_type_(p, false);
|
||||
} else {
|
||||
p.error("expected a type");
|
||||
}
|
||||
types::type_(p);
|
||||
|
||||
if p.at(COLON) {
|
||||
bounds(p);
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue