reduce code duplication

This commit is contained in:
Aleksey Kladov 2018-11-05 11:39:35 +03:00
parent 9d29c717ac
commit 6502bd2c96
2 changed files with 19 additions and 21 deletions

View File

@ -126,26 +126,15 @@ fn where_predicate(p: &mut Parser) {
p.error("expected colon");
}
}
// test where_pred_for
// fn test<F>()
// where
// for<'a> F: Fn(&'a str)
// { }
FOR_KW => {
p.bump();
if p.at(L_ANGLE) {
type_param_list(p);
types::path_type(p);
if p.at(COLON) {
bounds(p);
} else {
p.error("expected colon");
}
} else {
p.error("expected `<`");
}
}
_ => {
// test where_pred_for
// fn test<F>()
// where
// for<'a> F: Fn(&'a str)
// { }
if p.at(FOR_KW) {
types::for_binder(p);
}
types::path_type(p);
if p.at(COLON) {
bounds(p);

View File

@ -188,13 +188,22 @@ fn fn_pointer_type(p: &mut Parser) {
m.complete(p, FN_POINTER_TYPE);
}
pub(super) fn for_binder(p: &mut Parser) {
assert!(p.at(FOR_KW));
p.bump();
if p.at(L_ANGLE) {
type_params::opt_type_param_list(p);
} else {
p.error("expected `<`");
}
}
// test for_type
// type A = for<'a> fn() -> ();
pub(super) fn for_type(p: &mut Parser) {
assert!(p.at(FOR_KW));
let m = p.start();
p.bump();
type_params::opt_type_param_list(p);
for_binder(p);
match p.current() {
FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p),
_ if paths::is_path_start(p) => path_type_(p, false),