Move parsing a single TYPE_BOUND to a separate function

This commit is contained in:
Ville Penttinen 2019-03-30 17:23:54 +02:00
parent bfc2ac90c8
commit e3f9d6555b

View file

@ -80,9 +80,19 @@ fn lifetime_bounds(p: &mut Parser) {
} }
pub(super) fn bounds_without_colon(p: &mut Parser) { pub(super) fn bounds_without_colon(p: &mut Parser) {
let outer = p.start(); let m = p.start();
loop {
let inner = p.start(); while type_bound(p) {
if !p.eat(PLUS) {
break;
}
}
m.complete(p, TYPE_BOUND_LIST);
}
fn type_bound(p: &mut Parser) -> bool {
let m = p.start();
let has_paren = p.eat(L_PAREN); let has_paren = p.eat(L_PAREN);
p.eat(QUESTION); p.eat(QUESTION);
match p.current() { match p.current() {
@ -90,19 +100,16 @@ pub(super) fn bounds_without_colon(p: &mut Parser) {
FOR_KW => types::for_type(p), FOR_KW => types::for_type(p),
_ if paths::is_path_start(p) => types::path_type_(p, false), _ if paths::is_path_start(p) => types::path_type_(p, false),
_ => { _ => {
inner.abandon(p); m.abandon(p);
break; return false;
} }
} }
if has_paren { if has_paren {
p.expect(R_PAREN); p.expect(R_PAREN);
} }
inner.complete(p, TYPE_BOUND); m.complete(p, TYPE_BOUND);
if !p.eat(PLUS) {
break; true
}
}
outer.complete(p, TYPE_BOUND_LIST);
} }
// test where_clause // test where_clause