aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-04-29 01:16:22 +0100
committerJonas Schievink <[email protected]>2021-04-29 01:27:55 +0100
commitcaee3a2eebd514f5a2f5e68a9fcd4428fa34d41c (patch)
treea86dcceb9494cd243a2e1f6c10edd1c7be1f8fb5
parent49b219b1035e20143818d409404b5e6f19a7ad1d (diff)
Correctly parse negated literals as const args
-rw-r--r--crates/parser/src/grammar/type_args.rs9
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rast30
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rs1
3 files changed, 40 insertions, 0 deletions
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) {
59 expressions::literal(p); 59 expressions::literal(p);
60 m.complete(p, CONST_ARG); 60 m.complete(p, CONST_ARG);
61 } 61 }
62 // test const_generic_negated_literal
63 // fn f() { S::<-1> }
64 T![-] => {
65 let lm = p.start();
66 p.bump(T![-]);
67 expressions::literal(p);
68 lm.complete(p, PREFIX_EXPR);
69 m.complete(p, CONST_ARG);
70 }
62 _ => { 71 _ => {
63 types::type_(p); 72 types::type_(p);
64 m.complete(p, TYPE_ARG); 73 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 @@
1[email protected]
2 [email protected]
3 [email protected] "fn"
4 [email protected] " "
5 [email protected]
6 [email protected] "f"
7 [email protected]
8 [email protected] "("
9 [email protected] ")"
10 [email protected] " "
11 [email protected]
12 [email protected] "{"
13 [email protected] " "
14 [email protected]
15 [email protected]
16 [email protected]
17 [email protected]
18 [email protected] "S"
19 [email protected]
20 [email protected] "::"
21 [email protected] "<"
22 [email protected]
23 [email protected]
24 [email protected] "-"
25 [email protected]
26 [email protected] "1"
27 [email protected] ">"
28 [email protected] " "
29 [email protected] "}"
30 [email protected] "\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> }