Skip to content

Commit 25adc5e

Browse files
committed
minor: reduce duplication
1 parent 7729473 commit 25adc5e

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

crates/parser/src/grammar/generic_args.rs

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ pub(super) fn opt_generic_arg_list(p: &mut Parser, colon_colon_required: bool) {
2626
// test type_arg
2727
// type A = B<'static, i32, 1, { 2 }, Item=u64, true, false>;
2828
fn generic_arg(p: &mut Parser) {
29-
let m = p.start();
3029
match p.current() {
3130
LIFETIME_IDENT => {
31+
let m = p.start();
3232
lifetime(p);
3333
m.complete(p, LIFETIME_ARG);
3434
}
3535
// test associated_type_bounds
3636
// fn print_all<T: Iterator<Item, Item::Item, Item::<true>, Item: Display, Item<'a> = Item>>(printables: T) {}
3737
IDENT if [T![<], T![=], T![:]].contains(&p.nth(1)) => {
38+
let m = p.start();
3839
let path_ty = p.start();
3940
let path = p.start();
4041
let path_seg = p.start();
@@ -78,28 +79,12 @@ fn generic_arg(p: &mut Parser) {
7879
}
7980
}
8081
}
81-
T!['{'] => {
82-
expressions::block_expr(p);
83-
m.complete(p, CONST_ARG);
84-
}
85-
k if k.is_literal() => {
86-
expressions::literal(p);
87-
m.complete(p, CONST_ARG);
88-
}
89-
T![true] | T![false] => {
90-
expressions::literal(p);
91-
m.complete(p, CONST_ARG);
92-
}
9382
// test const_generic_negated_literal
9483
// fn f() { S::<-1> }
95-
T![-] => {
96-
let lm = p.start();
97-
p.bump(T![-]);
98-
expressions::literal(p);
99-
lm.complete(p, PREFIX_EXPR);
100-
m.complete(p, CONST_ARG);
101-
}
84+
T!['{'] | T![true] | T![false] | T![-] => const_arg(p),
85+
k if k.is_literal() => const_arg(p),
10286
_ => {
87+
let m = p.start();
10388
types::type_(p);
10489
m.complete(p, TYPE_ARG);
10590
}
@@ -108,7 +93,6 @@ fn generic_arg(p: &mut Parser) {
10893

10994
pub(super) fn const_arg(p: &mut Parser) {
11095
let m = p.start();
111-
// FIXME: duplicates the code above
11296
match p.current() {
11397
T!['{'] => {
11498
expressions::block_expr(p);

0 commit comments

Comments
 (0)