Skip to content

Commit 1c81c36

Browse files
bors[bot]matklad
andauthored
Merge #10280
10280: internal: type argument parsing refactoring r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 7729473 + 8ae1f9c commit 1c81c36

File tree

3 files changed

+139
-29
lines changed

3 files changed

+139
-29
lines changed

crates/parser/src/grammar/generic_args.rs

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,12 @@ pub(super) fn opt_generic_arg_list(p: &mut Parser, colon_colon_required: bool) {
2626
// test type_arg
2727
// type A = B<'static, i32, 1, { 2 }, Item=u64, true, false>;
2828
fn generic_arg(p: &mut Parser) {
29-
let m = p.start();
3029
match p.current() {
31-
LIFETIME_IDENT => {
32-
lifetime(p);
33-
m.complete(p, LIFETIME_ARG);
34-
}
30+
LIFETIME_IDENT => lifetime_arg(p),
3531
// test associated_type_bounds
3632
// fn print_all<T: Iterator<Item, Item::Item, Item::<true>, Item: Display, Item<'a> = Item>>(printables: T) {}
3733
IDENT if [T![<], T![=], T![:]].contains(&p.nth(1)) => {
34+
let m = p.start();
3835
let path_ty = p.start();
3936
let path = p.start();
4037
let path_seg = p.start();
@@ -78,37 +75,22 @@ fn generic_arg(p: &mut Parser) {
7875
}
7976
}
8077
}
81-
T!['{'] => {
82-
expressions::block_expr(p);
83-
m.complete(p, CONST_ARG);
84-
}
85-
k if k.is_literal() => {
86-
expressions::literal(p);
87-
m.complete(p, CONST_ARG);
88-
}
89-
T![true] | T![false] => {
90-
expressions::literal(p);
91-
m.complete(p, CONST_ARG);
92-
}
9378
// test const_generic_negated_literal
9479
// fn f() { S::<-1> }
95-
T![-] => {
96-
let lm = p.start();
97-
p.bump(T![-]);
98-
expressions::literal(p);
99-
lm.complete(p, PREFIX_EXPR);
100-
m.complete(p, CONST_ARG);
101-
}
102-
_ => {
103-
types::type_(p);
104-
m.complete(p, TYPE_ARG);
105-
}
80+
T!['{'] | T![true] | T![false] | T![-] => const_arg(p),
81+
k if k.is_literal() => const_arg(p),
82+
_ => type_arg(p),
10683
}
10784
}
10885

86+
fn lifetime_arg(p: &mut Parser) {
87+
let m = p.start();
88+
lifetime(p);
89+
m.complete(p, LIFETIME_ARG);
90+
}
91+
10992
pub(super) fn const_arg(p: &mut Parser) {
11093
let m = p.start();
111-
// FIXME: duplicates the code above
11294
match p.current() {
11395
T!['{'] => {
11496
expressions::block_expr(p);
@@ -137,3 +119,9 @@ pub(super) fn const_arg(p: &mut Parser) {
137119
}
138120
}
139121
}
122+
123+
fn type_arg(p: &mut Parser) {
124+
let m = p.start();
125+
types::type_(p);
126+
m.complete(p, TYPE_ARG);
127+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
2+
3+
4+
5+
6+
7+
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
91+
92+
93+
94+
95+
96+
97+
98+
99+
100+
101+
102+
103+
104+
105+
106+
107+
108+
109+
110+
111+
112+
error 75..75: expected identifier
113+
error 76..76: expected SEMICOLON
114+
error 82..82: expected expression
115+
error 83..83: expected SEMICOLON
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn f() {
2+
S::<Item::<lol>::<nope>>;
3+
}
4+
5+
fn g() {
6+
let _: Item::<lol>::<nope> = ();
7+
}

0 commit comments

Comments
 (0)