Unnamed repository; edit this file 'description' to name the repository.
| -rw-r--r-- | crates/parser/src/grammar/generic_args.rs | 46 | ||||
| -rw-r--r-- | crates/syntax/test_data/parser/err/0049_double_fish.rast | 115 | ||||
| -rw-r--r-- | crates/syntax/test_data/parser/err/0049_double_fish.rs | 7 |
3 files changed, 139 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); +} diff --git a/crates/syntax/test_data/parser/err/0049_double_fish.rast b/crates/syntax/test_data/parser/err/0049_double_fish.rast new file mode 100644 index 0000000000..aced9884ac --- /dev/null +++ b/crates/syntax/test_data/parser/err/0049_double_fish.rast @@ -0,0 +1,115 @@ + [email protected] "fn" + [email protected] " " + [email protected] "f" + [email protected] "(" + [email protected] ")" + [email protected] " " + [email protected] "{" + [email protected] "\n " + [email protected] "S" + [email protected] "::" + [email protected] "<" + [email protected] "Item" + [email protected] "::" + [email protected] "<" + [email protected] "lol" + [email protected] ">" + [email protected] "::" + [email protected] "<" + [email protected] "nope" + [email protected] ">" + [email protected] ">" + [email protected] ";" + [email protected] "\n" + [email protected] "}" + [email protected] "\n\n" + [email protected] "fn" + [email protected] " " + [email protected] "g" + [email protected] "(" + [email protected] ")" + [email protected] " " + [email protected] "{" + [email protected] "\n " + [email protected] "let" + [email protected] " " + [email protected] "_" + [email protected] ":" + [email protected] " " + [email protected] "Item" + [email protected] "::" + [email protected] "<" + [email protected] "lol" + [email protected] ">" + [email protected] "::" + [email protected] "<" + [email protected] "nope" + [email protected] ">" + [email protected] " " + [email protected] "=" + [email protected] " " + [email protected] "(" + [email protected] ")" + [email protected] ";" + [email protected] "\n" + [email protected] "}" + [email protected] "\n" +error 75..75: expected identifier +error 76..76: expected SEMICOLON +error 82..82: expected expression +error 83..83: expected SEMICOLON diff --git a/crates/syntax/test_data/parser/err/0049_double_fish.rs b/crates/syntax/test_data/parser/err/0049_double_fish.rs new file mode 100644 index 0000000000..31c12bfff9 --- /dev/null +++ b/crates/syntax/test_data/parser/err/0049_double_fish.rs @@ -0,0 +1,7 @@ +fn f() { + S::<Item::<lol>::<nope>>; +} + +fn g() { + let _: Item::<lol>::<nope> = (); +} |