From caee3a2eebd514f5a2f5e68a9fcd4428fa34d41c Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 29 Apr 2021 02:16:22 +0200 Subject: Correctly parse negated literals as const args --- crates/parser/src/grammar/type_args.rs | 9 +++++++ .../ok/0164_const_generic_negated_literal.rast | 30 ++++++++++++++++++++++ .../ok/0164_const_generic_negated_literal.rs | 1 + 3 files changed, 40 insertions(+) create mode 100644 crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rast create mode 100644 crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rs diff --git a/crates/parser/src/grammar/type_args.rs b/crates/parser/src/grammar/type_args.rs index 42cd426bd..56266b8d4 100644 --- a/crates/parser/src/grammar/type_args.rs +++ b/crates/parser/src/grammar/type_args.rs @@ -59,6 +59,15 @@ fn generic_arg(p: &mut Parser) { 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); diff --git a/crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rast b/crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rast new file mode 100644 index 000000000..b20e523dc --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rast @@ -0,0 +1,30 @@ +SOURCE_FILE@0..19 + FN@0..18 + FN_KW@0..2 "fn" + WHITESPACE@2..3 " " + NAME@3..4 + IDENT@3..4 "f" + PARAM_LIST@4..6 + L_PAREN@4..5 "(" + R_PAREN@5..6 ")" + WHITESPACE@6..7 " " + BLOCK_EXPR@7..18 + L_CURLY@7..8 "{" + WHITESPACE@8..9 " " + PATH_EXPR@9..16 + PATH@9..16 + PATH_SEGMENT@9..16 + NAME_REF@9..10 + IDENT@9..10 "S" + GENERIC_ARG_LIST@10..16 + COLON2@10..12 "::" + L_ANGLE@12..13 "<" + CONST_ARG@13..15 + PREFIX_EXPR@13..15 + MINUS@13..14 "-" + LITERAL@14..15 + INT_NUMBER@14..15 "1" + R_ANGLE@15..16 ">" + WHITESPACE@16..17 " " + R_CURLY@17..18 "}" + WHITESPACE@18..19 "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rs b/crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rs new file mode 100644 index 000000000..8a81d05cd --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rs @@ -0,0 +1 @@ +fn f() { S::<-1> } -- cgit v1.2.3