Skip to content

Commit bd2cd6a

Browse files
bors[bot]matklad
andauthored
Merge #10283
10283: minor: simplify generics parsing r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents e458f66 + 09531b7 commit bd2cd6a

File tree

2 files changed

+8
-29
lines changed

2 files changed

+8
-29
lines changed

crates/parser/src/grammar/generic_args.rs

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,45 +32,24 @@ fn generic_arg(p: &mut Parser) {
3232
// fn print_all<T: Iterator<Item, Item::Item, Item::<true>, Item: Display, Item<'a> = Item>>(printables: T) {}
3333
IDENT if [T![<], T![=], T![:]].contains(&p.nth(1)) => {
3434
let m = p.start();
35-
let path_ty = p.start();
36-
let path = p.start();
37-
let path_seg = p.start();
3835
name_ref(p);
3936
opt_generic_arg_list(p, false);
4037
match p.current() {
4138
// NameRef<...> =
4239
T![=] => {
4340
p.bump_any();
4441
types::type_(p);
45-
46-
path_seg.abandon(p);
47-
path.abandon(p);
48-
path_ty.abandon(p);
4942
m.complete(p, ASSOC_TYPE_ARG);
5043
}
51-
T![:] if p.at(T![::]) => {
52-
// NameRef::, this is a path type
53-
path_seg.complete(p, PATH_SEGMENT);
54-
let qual = path.complete(p, PATH);
55-
paths::type_path_for_qualifier(p, qual);
56-
path_ty.complete(p, PATH_TYPE);
57-
m.complete(p, TYPE_ARG);
58-
}
5944
// NameRef<...>:
60-
T![:] => {
45+
T![:] if !p.at(T![::]) => {
6146
generic_params::bounds(p);
62-
63-
path_seg.abandon(p);
64-
path.abandon(p);
65-
path_ty.abandon(p);
6647
m.complete(p, ASSOC_TYPE_ARG);
6748
}
68-
// NameRef, this is a single segment path type
6949
_ => {
70-
path_seg.complete(p, PATH_SEGMENT);
71-
path.complete(p, PATH);
72-
path_ty.complete(p, PATH_TYPE);
73-
m.complete(p, TYPE_ARG);
50+
let m = m.complete(p, PATH_SEGMENT).precede(p).complete(p, PATH);
51+
let m = paths::type_path_for_qualifier(p, m);
52+
m.precede(p).complete(p, PATH_TYPE).precede(p).complete(p, TYPE_ARG);
7453
}
7554
}
7655
}

crates/parser/src/grammar/paths.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(super) fn expr_path(p: &mut Parser) {
2727
path(p, Mode::Expr)
2828
}
2929

30-
pub(crate) fn type_path_for_qualifier(p: &mut Parser, qual: CompletedMarker) {
30+
pub(crate) fn type_path_for_qualifier(p: &mut Parser, qual: CompletedMarker) -> CompletedMarker {
3131
path_for_qualifier(p, Mode::Type, qual)
3232
}
3333

@@ -42,10 +42,10 @@ fn path(p: &mut Parser, mode: Mode) {
4242
let path = p.start();
4343
path_segment(p, mode, true);
4444
let qual = path.complete(p, PATH);
45-
path_for_qualifier(p, mode, qual)
45+
path_for_qualifier(p, mode, qual);
4646
}
4747

48-
fn path_for_qualifier(p: &mut Parser, mode: Mode, mut qual: CompletedMarker) {
48+
fn path_for_qualifier(p: &mut Parser, mode: Mode, mut qual: CompletedMarker) -> CompletedMarker {
4949
loop {
5050
let use_tree = matches!(p.nth(2), T![*] | T!['{']);
5151
if p.at(T![::]) && !use_tree {
@@ -55,7 +55,7 @@ fn path_for_qualifier(p: &mut Parser, mode: Mode, mut qual: CompletedMarker) {
5555
let path = path.complete(p, PATH);
5656
qual = path;
5757
} else {
58-
break;
58+
return qual;
5959
}
6060
}
6161
}

0 commit comments

Comments
 (0)