10283: minor: simplify generics parsing r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2021-09-19 11:51:38 +00:00 committed by GitHub
commit bd2cd6a15f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 29 deletions

View File

@ -32,9 +32,6 @@ fn generic_arg(p: &mut Parser) {
// fn print_all<T: Iterator<Item, Item::Item, Item::<true>, Item: Display, Item<'a> = Item>>(printables: T) {}
IDENT if [T![<], T![=], T![:]].contains(&p.nth(1)) => {
let m = p.start();
let path_ty = p.start();
let path = p.start();
let path_seg = p.start();
name_ref(p);
opt_generic_arg_list(p, false);
match p.current() {
@ -42,35 +39,17 @@ fn generic_arg(p: &mut Parser) {
T![=] => {
p.bump_any();
types::type_(p);
path_seg.abandon(p);
path.abandon(p);
path_ty.abandon(p);
m.complete(p, ASSOC_TYPE_ARG);
}
T![:] if p.at(T![::]) => {
// NameRef::, this is a path type
path_seg.complete(p, PATH_SEGMENT);
let qual = path.complete(p, PATH);
paths::type_path_for_qualifier(p, qual);
path_ty.complete(p, PATH_TYPE);
m.complete(p, TYPE_ARG);
}
// NameRef<...>:
T![:] => {
T![:] if !p.at(T![::]) => {
generic_params::bounds(p);
path_seg.abandon(p);
path.abandon(p);
path_ty.abandon(p);
m.complete(p, ASSOC_TYPE_ARG);
}
// NameRef, this is a single segment path type
_ => {
path_seg.complete(p, PATH_SEGMENT);
path.complete(p, PATH);
path_ty.complete(p, PATH_TYPE);
m.complete(p, TYPE_ARG);
let m = m.complete(p, PATH_SEGMENT).precede(p).complete(p, PATH);
let m = paths::type_path_for_qualifier(p, m);
m.precede(p).complete(p, PATH_TYPE).precede(p).complete(p, TYPE_ARG);
}
}
}

View File

@ -27,7 +27,7 @@ pub(super) fn expr_path(p: &mut Parser) {
path(p, Mode::Expr)
}
pub(crate) fn type_path_for_qualifier(p: &mut Parser, qual: CompletedMarker) {
pub(crate) fn type_path_for_qualifier(p: &mut Parser, qual: CompletedMarker) -> CompletedMarker {
path_for_qualifier(p, Mode::Type, qual)
}
@ -42,10 +42,10 @@ fn path(p: &mut Parser, mode: Mode) {
let path = p.start();
path_segment(p, mode, true);
let qual = path.complete(p, PATH);
path_for_qualifier(p, mode, qual)
path_for_qualifier(p, mode, qual);
}
fn path_for_qualifier(p: &mut Parser, mode: Mode, mut qual: CompletedMarker) {
fn path_for_qualifier(p: &mut Parser, mode: Mode, mut qual: CompletedMarker) -> CompletedMarker {
loop {
let use_tree = matches!(p.nth(2), T![*] | T!['{']);
if p.at(T![::]) && !use_tree {
@ -55,7 +55,7 @@ fn path_for_qualifier(p: &mut Parser, mode: Mode, mut qual: CompletedMarker) {
let path = path.complete(p, PATH);
qual = path;
} else {
break;
return qual;
}
}
}