Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/parser/src/grammar/generic_args.rs')
| -rw-r--r-- | crates/parser/src/grammar/generic_args.rs | 46 |
1 files changed, 17 insertions, 29 deletions
diff --git a/crates/parser/src/grammar/generic_args.rs b/crates/parser/src/grammar/generic_args.rs index cd75d20a42..3b9444a6ff 100644 --- a/crates/parser/src/grammar/generic_args.rs +++ b/crates/parser/src/grammar/generic_args.rs @@ -26,15 +26,12 @@ pub(super) fn opt_generic_arg_list(p: &mut Parser, colon_colon_required: bool) { // test type_arg // type A = B<'static, i32, 1, { 2 }, Item=u64, true, false>; fn generic_arg(p: &mut Parser) { - let m = p.start(); match p.current() { - LIFETIME_IDENT => { - lifetime(p); - m.complete(p, LIFETIME_ARG); - } + LIFETIME_IDENT => lifetime_arg(p), // test associated_type_bounds // 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(); @@ -78,37 +75,22 @@ fn generic_arg(p: &mut Parser) { } } } - T!['{'] => { - expressions::block_expr(p); - m.complete(p, CONST_ARG); - } - k if k.is_literal() => { - expressions::literal(p); - m.complete(p, CONST_ARG); - } - T![true] | T![false] => { - expressions::literal(p); - m.complete(p, CONST_ARG); - } // test const_generic_negated_literal // fn f() { S::<-1> } - T![-] => { - let lm = p.start(); - p.bump(T![-]); - expressions::literal(p); - lm.complete(p, PREFIX_EXPR); - m.complete(p, CONST_ARG); - } - _ => { - types::type_(p); - m.complete(p, TYPE_ARG); - } + T!['{'] | T![true] | T![false] | T![-] => const_arg(p), + k if k.is_literal() => const_arg(p), + _ => type_arg(p), } } +fn lifetime_arg(p: &mut Parser) { + let m = p.start(); + lifetime(p); + m.complete(p, LIFETIME_ARG); +} + pub(super) fn const_arg(p: &mut Parser) { let m = p.start(); - // FIXME: duplicates the code above match p.current() { T!['{'] => { expressions::block_expr(p); @@ -137,3 +119,9 @@ pub(super) fn const_arg(p: &mut Parser) { } } } + +fn type_arg(p: &mut Parser) { + let m = p.start(); + types::type_(p); + m.complete(p, TYPE_ARG); +} |