mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-22 11:24:24 +00:00
internal: more focused tests for const arguments
This commit is contained in:
parent
09531b703d
commit
a6181bfdb7
28 changed files with 321 additions and 176 deletions
|
@ -23,11 +23,13 @@ pub(super) fn opt_generic_arg_list(p: &mut Parser, colon_colon_required: bool) {
|
|||
m.complete(p, GENERIC_ARG_LIST);
|
||||
}
|
||||
|
||||
// test type_arg
|
||||
// type A = B<'static, i32, 1, { 2 }, Item=u64, true, false>;
|
||||
// test generic_arg
|
||||
// type T = S<i32>;
|
||||
fn generic_arg(p: &mut Parser) {
|
||||
match p.current() {
|
||||
LIFETIME_IDENT => lifetime_arg(p),
|
||||
T!['{'] | T![true] | T![false] | T![-] => const_arg(p),
|
||||
k if k.is_literal() => const_arg(p),
|
||||
// test associated_type_bounds
|
||||
// fn print_all<T: Iterator<Item, Item::Item, Item::<true>, Item: Display, Item<'a> = Item>>(printables: T) {}
|
||||
IDENT if [T![<], T![=], T![:]].contains(&p.nth(1)) => {
|
||||
|
@ -35,13 +37,15 @@ fn generic_arg(p: &mut Parser) {
|
|||
name_ref(p);
|
||||
opt_generic_arg_list(p, false);
|
||||
match p.current() {
|
||||
// NameRef<...> =
|
||||
// test assoc_type_eq
|
||||
// type T = StreamingIterator<Item<'a> = &'a T>;
|
||||
T![=] => {
|
||||
p.bump_any();
|
||||
types::type_(p);
|
||||
m.complete(p, ASSOC_TYPE_ARG);
|
||||
}
|
||||
// NameRef<...>:
|
||||
// test assoc_type_bound
|
||||
// type T = StreamingIterator<Item<'a>: Clone>;
|
||||
T![:] if !p.at(T![::]) => {
|
||||
generic_params::bounds(p);
|
||||
m.complete(p, ASSOC_TYPE_ARG);
|
||||
|
@ -53,35 +57,43 @@ fn generic_arg(p: &mut Parser) {
|
|||
}
|
||||
}
|
||||
}
|
||||
// test const_generic_negated_literal
|
||||
// fn f() { S::<-1> }
|
||||
T!['{'] | T![true] | T![false] | T![-] => const_arg(p),
|
||||
k if k.is_literal() => const_arg(p),
|
||||
_ => type_arg(p),
|
||||
}
|
||||
}
|
||||
|
||||
// test lifetime_arg
|
||||
// type T = S<'static>;
|
||||
fn lifetime_arg(p: &mut Parser) {
|
||||
let m = p.start();
|
||||
lifetime(p);
|
||||
m.complete(p, LIFETIME_ARG);
|
||||
}
|
||||
|
||||
// test const_arg
|
||||
// type T = S<92>;
|
||||
pub(super) fn const_arg(p: &mut Parser) {
|
||||
let m = p.start();
|
||||
match p.current() {
|
||||
// test const_arg_block
|
||||
// type T = S<{90 + 2}>;
|
||||
T!['{'] => {
|
||||
expressions::block_expr(p);
|
||||
m.complete(p, CONST_ARG);
|
||||
}
|
||||
// test const_arg_literal
|
||||
// type T = S<"hello", 0xdeadbeef>;
|
||||
k if k.is_literal() => {
|
||||
expressions::literal(p);
|
||||
m.complete(p, CONST_ARG);
|
||||
}
|
||||
// test const_arg_bool_literal
|
||||
// type T = S<true>;
|
||||
T![true] | T![false] => {
|
||||
expressions::literal(p);
|
||||
m.complete(p, CONST_ARG);
|
||||
}
|
||||
// test const_arg_negative_number
|
||||
// type T = S<-92>;
|
||||
T![-] => {
|
||||
let lm = p.start();
|
||||
p.bump(T![-]);
|
||||
|
@ -89,6 +101,8 @@ pub(super) fn const_arg(p: &mut Parser) {
|
|||
lm.complete(p, PREFIX_EXPR);
|
||||
m.complete(p, CONST_ARG);
|
||||
}
|
||||
// test const_arg_path
|
||||
// struct S<const N: u32 = u32::MAX>;
|
||||
_ => {
|
||||
let lm = p.start();
|
||||
paths::use_path(p);
|
||||
|
|
|
@ -81,8 +81,6 @@ fn const_param(p: &mut Parser, m: Marker) {
|
|||
if p.at(T![=]) {
|
||||
// test const_param_defaults
|
||||
// struct A<const N: i32 = -1>;
|
||||
// struct B<const N: i32 = {}>;
|
||||
// struct C<const N: i32 = some::CONST>;
|
||||
p.bump(T![=]);
|
||||
generic_args::const_arg(p);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue