Unnamed repository; edit this file 'description' to name the repository.
Merge #10283
10283: minor: simplify generics parsing r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
bors[bot] 2021-09-19
parent e458f66 · parent 09531b7 · commit bd2cd6a
-rw-r--r--crates/parser/src/grammar/generic_args.rs29
-rw-r--r--crates/parser/src/grammar/paths.rs8
2 files changed, 8 insertions, 29 deletions
diff --git a/crates/parser/src/grammar/generic_args.rs b/crates/parser/src/grammar/generic_args.rs
index b409baed4d..d8ddf95f59 100644
--- a/crates/parser/src/grammar/generic_args.rs
+++ b/crates/parser/src/grammar/generic_args.rs
@@ -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);
}
}
}
diff --git a/crates/parser/src/grammar/paths.rs b/crates/parser/src/grammar/paths.rs
index e51dc38f97..05a52c984a 100644
--- a/crates/parser/src/grammar/paths.rs
+++ b/crates/parser/src/grammar/paths.rs
@@ -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;
}
}
}