minor: simplify

This commit is contained in:
Aleksey Kladov 2021-09-19 14:32:02 +03:00
parent 0005678649
commit 09531b703d
2 changed files with 7 additions and 20 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) {} // 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)) => { IDENT if [T![<], T![=], T![:]].contains(&p.nth(1)) => {
let m = p.start(); let m = p.start();
let path_ty = p.start();
let path = p.start();
let path_seg = p.start();
name_ref(p); name_ref(p);
opt_generic_arg_list(p, false); opt_generic_arg_list(p, false);
match p.current() { match p.current() {
@ -42,27 +39,17 @@ fn generic_arg(p: &mut Parser) {
T![=] => { T![=] => {
p.bump_any(); p.bump_any();
types::type_(p); types::type_(p);
path_seg.abandon(p);
path.abandon(p);
path_ty.abandon(p);
m.complete(p, ASSOC_TYPE_ARG); m.complete(p, ASSOC_TYPE_ARG);
} }
// NameRef<...>: // NameRef<...>:
T![:] if !p.at(T![::]) => { T![:] if !p.at(T![::]) => {
generic_params::bounds(p); generic_params::bounds(p);
path_seg.abandon(p);
path.abandon(p);
path_ty.abandon(p);
m.complete(p, ASSOC_TYPE_ARG); m.complete(p, ASSOC_TYPE_ARG);
} }
_ => { _ => {
path_seg.complete(p, PATH_SEGMENT); let m = m.complete(p, PATH_SEGMENT).precede(p).complete(p, PATH);
let qual = path.complete(p, PATH); let m = paths::type_path_for_qualifier(p, m);
paths::type_path_for_qualifier(p, qual); m.precede(p).complete(p, PATH_TYPE).precede(p).complete(p, TYPE_ARG);
path_ty.complete(p, PATH_TYPE);
m.complete(p, TYPE_ARG);
} }
} }
} }

View file

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