Parse const param defaults
This commit is contained in:
@@ -25,6 +25,38 @@ pub(super) fn opt_generic_arg_list(p: &mut Parser, colon_colon_required: bool) {
|
||||
m.complete(p, GENERIC_ARG_LIST);
|
||||
}
|
||||
|
||||
pub(super) fn const_arg(p: &mut Parser) {
|
||||
let m = p.start();
|
||||
// FIXME: duplicates the code below
|
||||
match p.current() {
|
||||
T!['{'] => {
|
||||
expressions::block_expr(p);
|
||||
m.complete(p, CONST_ARG);
|
||||
}
|
||||
k if k.is_literal() => {
|
||||
expressions::literal(p);
|
||||
m.complete(p, CONST_ARG);
|
||||
}
|
||||
T![true] | T![false] => {
|
||||
expressions::literal(p);
|
||||
m.complete(p, CONST_ARG);
|
||||
}
|
||||
T![-] => {
|
||||
let lm = p.start();
|
||||
p.bump(T![-]);
|
||||
expressions::literal(p);
|
||||
lm.complete(p, PREFIX_EXPR);
|
||||
m.complete(p, CONST_ARG);
|
||||
}
|
||||
_ => {
|
||||
let lm = p.start();
|
||||
paths::use_path(p);
|
||||
lm.complete(p, PATH_EXPR);
|
||||
m.complete(p, CONST_ARG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// test type_arg
|
||||
// type A = B<'static, i32, 1, { 2 }, Item=u64, true, false>;
|
||||
fn generic_arg(p: &mut Parser) {
|
||||
|
||||
@@ -70,6 +70,16 @@ fn const_param(p: &mut Parser, m: Marker) {
|
||||
p.bump(T![const]);
|
||||
name(p);
|
||||
types::ascription(p);
|
||||
|
||||
// test const_param_defaults
|
||||
// struct A<const N: i32 = -1>;
|
||||
// struct B<const N: i32 = {}>;
|
||||
// struct C<const N: i32 = some::CONST>;
|
||||
if p.at(T![=]) {
|
||||
p.bump(T![=]);
|
||||
type_args::const_arg(p);
|
||||
}
|
||||
|
||||
m.complete(p, CONST_PARAM);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user