aboutsummaryrefslogtreecommitdiff
path: root/crates/parser
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-04-29 02:09:37 +0100
committerGitHub <[email protected]>2021-04-29 02:09:37 +0100
commitdce0d71b18ed78f55989d2a7462ae1d8df10e14f (patch)
treeb8da652e4137c7a519e885a684b81f983f5ba9a9 /crates/parser
parent9d199486dacb982535ed77a2e8aef830ac44a5b5 (diff)
parentcb8632d87ca0ad4e686452b72c0c0c01cd7a869b (diff)
Merge #8685
8685: feat: parse const param defaults r=jonas-schievink a=jonas-schievink These will probably be stabilized in a few releases, let's make sure we can at least parse them bors r+ Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/parser')
-rw-r--r--crates/parser/src/grammar/type_args.rs32
-rw-r--r--crates/parser/src/grammar/type_params.rs10
2 files changed, 42 insertions, 0 deletions
diff --git a/crates/parser/src/grammar/type_args.rs b/crates/parser/src/grammar/type_args.rs
index 56266b8d4..be36cad17 100644
--- a/crates/parser/src/grammar/type_args.rs
+++ b/crates/parser/src/grammar/type_args.rs
@@ -25,6 +25,38 @@ pub(super) fn opt_generic_arg_list(p: &mut Parser, colon_colon_required: bool) {
25 m.complete(p, GENERIC_ARG_LIST); 25 m.complete(p, GENERIC_ARG_LIST);
26} 26}
27 27
28pub(super) fn const_arg(p: &mut Parser) {
29 let m = p.start();
30 // FIXME: duplicates the code below
31 match p.current() {
32 T!['{'] => {
33 expressions::block_expr(p);
34 m.complete(p, CONST_ARG);
35 }
36 k if k.is_literal() => {
37 expressions::literal(p);
38 m.complete(p, CONST_ARG);
39 }
40 T![true] | T![false] => {
41 expressions::literal(p);
42 m.complete(p, CONST_ARG);
43 }
44 T![-] => {
45 let lm = p.start();
46 p.bump(T![-]);
47 expressions::literal(p);
48 lm.complete(p, PREFIX_EXPR);
49 m.complete(p, CONST_ARG);
50 }
51 _ => {
52 let lm = p.start();
53 paths::use_path(p);
54 lm.complete(p, PATH_EXPR);
55 m.complete(p, CONST_ARG);
56 }
57 }
58}
59
28// test type_arg 60// test type_arg
29// type A = B<'static, i32, 1, { 2 }, Item=u64, true, false>; 61// type A = B<'static, i32, 1, { 2 }, Item=u64, true, false>;
30fn generic_arg(p: &mut Parser) { 62fn generic_arg(p: &mut Parser) {
diff --git a/crates/parser/src/grammar/type_params.rs b/crates/parser/src/grammar/type_params.rs
index 3de5248da..b1f979281 100644
--- a/crates/parser/src/grammar/type_params.rs
+++ b/crates/parser/src/grammar/type_params.rs
@@ -70,6 +70,16 @@ fn const_param(p: &mut Parser, m: Marker) {
70 p.bump(T![const]); 70 p.bump(T![const]);
71 name(p); 71 name(p);
72 types::ascription(p); 72 types::ascription(p);
73
74 // test const_param_defaults
75 // struct A<const N: i32 = -1>;
76 // struct B<const N: i32 = {}>;
77 // struct C<const N: i32 = some::CONST>;
78 if p.at(T![=]) {
79 p.bump(T![=]);
80 type_args::const_arg(p);
81 }
82
73 m.complete(p, CONST_PARAM); 83 m.complete(p, CONST_PARAM);
74} 84}
75 85