Skip to content

Commit a6181bf

Browse files
committed
internal: more focused tests for const arguments
1 parent 09531b7 commit a6181bf

28 files changed

+321
-176
lines changed

crates/parser/src/grammar/generic_args.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,29 @@ pub(super) fn opt_generic_arg_list(p: &mut Parser, colon_colon_required: bool) {
2323
m.complete(p, GENERIC_ARG_LIST);
2424
}
2525

26-
// test type_arg
27-
// type A = B<'static, i32, 1, { 2 }, Item=u64, true, false>;
26+
// test generic_arg
27+
// type T = S<i32>;
2828
fn generic_arg(p: &mut Parser) {
2929
match p.current() {
3030
LIFETIME_IDENT => lifetime_arg(p),
31+
T!['{'] | T![true] | T![false] | T![-] => const_arg(p),
32+
k if k.is_literal() => const_arg(p),
3133
// test associated_type_bounds
3234
// fn print_all<T: Iterator<Item, Item::Item, Item::<true>, Item: Display, Item<'a> = Item>>(printables: T) {}
3335
IDENT if [T![<], T![=], T![:]].contains(&p.nth(1)) => {
3436
let m = p.start();
3537
name_ref(p);
3638
opt_generic_arg_list(p, false);
3739
match p.current() {
38-
// NameRef<...> =
40+
// test assoc_type_eq
41+
// type T = StreamingIterator<Item<'a> = &'a T>;
3942
T![=] => {
4043
p.bump_any();
4144
types::type_(p);
4245
m.complete(p, ASSOC_TYPE_ARG);
4346
}
44-
// NameRef<...>:
47+
// test assoc_type_bound
48+
// type T = StreamingIterator<Item<'a>: Clone>;
4549
T![:] if !p.at(T![::]) => {
4650
generic_params::bounds(p);
4751
m.complete(p, ASSOC_TYPE_ARG);
@@ -53,42 +57,52 @@ fn generic_arg(p: &mut Parser) {
5357
}
5458
}
5559
}
56-
// test const_generic_negated_literal
57-
// fn f() { S::<-1> }
58-
T!['{'] | T![true] | T![false] | T![-] => const_arg(p),
59-
k if k.is_literal() => const_arg(p),
6060
_ => type_arg(p),
6161
}
6262
}
6363

64+
// test lifetime_arg
65+
// type T = S<'static>;
6466
fn lifetime_arg(p: &mut Parser) {
6567
let m = p.start();
6668
lifetime(p);
6769
m.complete(p, LIFETIME_ARG);
6870
}
6971

72+
// test const_arg
73+
// type T = S<92>;
7074
pub(super) fn const_arg(p: &mut Parser) {
7175
let m = p.start();
7276
match p.current() {
77+
// test const_arg_block
78+
// type T = S<{90 + 2}>;
7379
T!['{'] => {
7480
expressions::block_expr(p);
7581
m.complete(p, CONST_ARG);
7682
}
83+
// test const_arg_literal
84+
// type T = S<"hello", 0xdeadbeef>;
7785
k if k.is_literal() => {
7886
expressions::literal(p);
7987
m.complete(p, CONST_ARG);
8088
}
89+
// test const_arg_bool_literal
90+
// type T = S<true>;
8191
T![true] | T![false] => {
8292
expressions::literal(p);
8393
m.complete(p, CONST_ARG);
8494
}
95+
// test const_arg_negative_number
96+
// type T = S<-92>;
8597
T![-] => {
8698
let lm = p.start();
8799
p.bump(T![-]);
88100
expressions::literal(p);
89101
lm.complete(p, PREFIX_EXPR);
90102
m.complete(p, CONST_ARG);
91103
}
104+
// test const_arg_path
105+
// struct S<const N: u32 = u32::MAX>;
92106
_ => {
93107
let lm = p.start();
94108
paths::use_path(p);

crates/parser/src/grammar/generic_params.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ fn const_param(p: &mut Parser, m: Marker) {
8181
if p.at(T![=]) {
8282
// test const_param_defaults
8383
// struct A<const N: i32 = -1>;
84-
// struct B<const N: i32 = {}>;
85-
// struct C<const N: i32 = some::CONST>;
8684
p.bump(T![=]);
8785
generic_args::const_arg(p);
8886
}

crates/syntax/test_data/parser/inline/ok/0039_type_arg.rast

Lines changed: 0 additions & 66 deletions
This file was deleted.

crates/syntax/test_data/parser/inline/ok/0039_type_arg.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rast

Lines changed: 0 additions & 30 deletions
This file was deleted.

crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SOURCE_FILE@0..96
1+
SOURCE_FILE@0..29
22
33
44
@@ -29,68 +29,3 @@ [email protected]
2929
3030
3131
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-
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
struct A<const N: i32 = -1>;
2-
struct B<const N: i32 = {}>;
3-
struct C<const N: i32 = some::CONST>;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
type T = S<{90 + 2}>;

0 commit comments

Comments
 (0)