Allow types to the left of : in where predicates.

This commit is contained in:
Erlend Tobiassen 2019-01-22 01:11:35 +01:00
parent b59334e67a
commit 1059ec74e2

View file

@ -104,22 +104,32 @@ 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) {
// Empty where clause
} else {
loop { loop {
if !(paths::is_path_start(p) where_predicate(p);
|| p.current() == LIFETIME
|| p.current() == FOR_KW let comma = p.eat(COMMA);
|| p.current() == L_ANGLE)
{ if is_where_clause_end(p) {
break; break;
} }
where_predicate(p);
if p.current() != L_CURLY && p.current() != SEMI && p.current() != EQ { if !comma {
p.expect(COMMA); p.error("expected comma")
} }
} }
}
m.complete(p, WHERE_CLAUSE); 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) { fn where_predicate(p: &mut Parser) {
let m = p.start(); let m = p.start();
match p.current() { match p.current() {
@ -131,20 +141,13 @@ fn where_predicate(p: &mut Parser) {
p.error("expected colon"); p.error("expected colon");
} }
} }
IMPL_KW => {
p.error("expected lifetime or type");
return;
}
_ => { _ => {
// test where_pred_for types::type_(p);
// 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");
}
if p.at(COLON) { if p.at(COLON) {
bounds(p); bounds(p);
} else { } else {