Skip to content

Commit 9d19948

Browse files
Merge #8684
8684: Correctly parse negated literals as const args r=jonas-schievink a=jonas-schievink Previously we didn't accept `S::<-0>;` bors r+ Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2 parents 49b219b + caee3a2 commit 9d19948

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

crates/parser/src/grammar/type_args.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ fn generic_arg(p: &mut Parser) {
5959
expressions::literal(p);
6060
m.complete(p, CONST_ARG);
6161
}
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+
}
6271
_ => {
6372
types::type_(p);
6473
m.complete(p, TYPE_ARG);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
SOURCE_FILE@0..19
2+
FN@0..18
3+
FN_KW@0..2 "fn"
4+
WHITESPACE@2..3 " "
5+
NAME@3..4
6+
IDENT@3..4 "f"
7+
PARAM_LIST@4..6
8+
L_PAREN@4..5 "("
9+
R_PAREN@5..6 ")"
10+
WHITESPACE@6..7 " "
11+
BLOCK_EXPR@7..18
12+
L_CURLY@7..8 "{"
13+
WHITESPACE@8..9 " "
14+
PATH_EXPR@9..16
15+
PATH@9..16
16+
PATH_SEGMENT@9..16
17+
NAME_REF@9..10
18+
IDENT@9..10 "S"
19+
GENERIC_ARG_LIST@10..16
20+
COLON2@10..12 "::"
21+
L_ANGLE@12..13 "<"
22+
CONST_ARG@13..15
23+
PREFIX_EXPR@13..15
24+
MINUS@13..14 "-"
25+
LITERAL@14..15
26+
INT_NUMBER@14..15 "1"
27+
R_ANGLE@15..16 ">"
28+
WHITESPACE@16..17 " "
29+
R_CURLY@17..18 "}"
30+
WHITESPACE@18..19 "\n"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn f() { S::<-1> }

0 commit comments

Comments
 (0)