Unnamed repository; edit this file 'description' to name the repository.
internal: more focused tests for const arguments
Aleksey Kladov 2021-09-19
parent 09531b7 · commit a6181bf
-rw-r--r--crates/parser/src/grammar/generic_args.rs30
-rw-r--r--crates/parser/src/grammar/generic_params.rs2
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0039_type_arg.rast66
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0039_type_arg.rs1
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rast30
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rs1
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0165_const_param_defaults.rast67
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0165_const_param_defaults.rs2
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0183_const_arg_block.rast31
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0183_const_arg_block.rs1
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0184_const_arg.rast22
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0184_const_arg.rs1
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0185_assoc_type_bound.rast37
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0185_assoc_type_bound.rs1
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0186_lifetime_arg.rast22
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0186_lifetime_arg.rs1
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0187_assoc_type_eq.rast41
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0187_assoc_type_eq.rs1
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0188_const_arg_path.rast37
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0188_const_arg_path.rs1
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0189_const_arg_literal.rast27
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0189_const_arg_literal.rs1
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0190_generic_arg.rast25
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0190_generic_arg.rs1
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0191_const_arg_negative_number.rast24
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0191_const_arg_negative_number.rs1
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0192_const_arg_bool_literal.rast22
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0192_const_arg_bool_literal.rs1
28 files changed, 321 insertions, 176 deletions
diff --git a/crates/parser/src/grammar/generic_args.rs b/crates/parser/src/grammar/generic_args.rs
index d8ddf95f59..b47912d07d 100644
--- a/crates/parser/src/grammar/generic_args.rs
+++ b/crates/parser/src/grammar/generic_args.rs
@@ -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);
diff --git a/crates/parser/src/grammar/generic_params.rs b/crates/parser/src/grammar/generic_params.rs
index b8119f0a21..5414b3b20d 100644
--- a/crates/parser/src/grammar/generic_params.rs
+++ b/crates/parser/src/grammar/generic_params.rs
@@ -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);
}
diff --git a/crates/syntax/test_data/parser/inline/ok/0039_type_arg.rast b/crates/syntax/test_data/parser/inline/ok/0039_type_arg.rast
deleted file mode 100644
index 11efa23a42..0000000000
--- a/crates/syntax/test_data/parser/inline/ok/0039_type_arg.rast
+++ /dev/null
@@ -1,66 +0,0 @@
- [email protected] "'static"
diff --git a/crates/syntax/test_data/parser/inline/ok/0039_type_arg.rs b/crates/syntax/test_data/parser/inline/ok/0039_type_arg.rs
deleted file mode 100644
index 6a8721a73e..0000000000
--- a/crates/syntax/test_data/parser/inline/ok/0039_type_arg.rs
+++ /dev/null
@@ -1 +0,0 @@
-type A = B<'static, i32, 1, { 2 }, Item=u64, true, false>;
diff --git a/crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rast b/crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rast
deleted file mode 100644
index b20e523dc1..0000000000
--- a/crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rast
+++ /dev/null
@@ -1,30 +0,0 @@
diff --git a/crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rs b/crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rs
deleted file mode 100644
index 8a81d05cd9..0000000000
--- a/crates/syntax/test_data/parser/inline/ok/0164_const_generic_negated_literal.rs
+++ /dev/null
@@ -1 +0,0 @@
-fn f() { S::<-1> }
diff --git a/crates/syntax/test_data/parser/inline/ok/0165_const_param_defaults.rast b/crates/syntax/test_data/parser/inline/ok/0165_const_param_defaults.rast
index e8f40a4cd7..8677f8ae2c 100644
--- a/crates/syntax/test_data/parser/inline/ok/0165_const_param_defaults.rast
+++ b/crates/syntax/test_data/parser/inline/ok/0165_const_param_defaults.rast
@@ -1,4 +1,4 @@
@@ -29,68 +29,3 @@ [email protected]
diff --git a/crates/syntax/test_data/parser/inline/ok/0165_const_param_defaults.rs b/crates/syntax/test_data/parser/inline/ok/0165_const_param_defaults.rs
index 68388c8fbd..879ecffa75 100644
--- a/crates/syntax/test_data/parser/inline/ok/0165_const_param_defaults.rs
+++ b/crates/syntax/test_data/parser/inline/ok/0165_const_param_defaults.rs
@@ -1,3 +1 @@
struct A<const N: i32 = -1>;
-struct B<const N: i32 = {}>;
-struct C<const N: i32 = some::CONST>;
diff --git a/crates/syntax/test_data/parser/inline/ok/0183_const_arg_block.rast b/crates/syntax/test_data/parser/inline/ok/0183_const_arg_block.rast
new file mode 100644
index 0000000000..9020d1b861
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0183_const_arg_block.rast
@@ -0,0 +1,31 @@
diff --git a/crates/syntax/test_data/parser/inline/ok/0183_const_arg_block.rs b/crates/syntax/test_data/parser/inline/ok/0183_const_arg_block.rs
new file mode 100644
index 0000000000..1c279db289
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0183_const_arg_block.rs
@@ -0,0 +1 @@
+type T = S<{90 + 2}>;
diff --git a/crates/syntax/test_data/parser/inline/ok/0184_const_arg.rast b/crates/syntax/test_data/parser/inline/ok/0184_const_arg.rast
new file mode 100644
index 0000000000..15bfcb26ef
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0184_const_arg.rast
@@ -0,0 +1,22 @@
diff --git a/crates/syntax/test_data/parser/inline/ok/0184_const_arg.rs b/crates/syntax/test_data/parser/inline/ok/0184_const_arg.rs
new file mode 100644
index 0000000000..8b5e5dbe13
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0184_const_arg.rs
@@ -0,0 +1 @@
+type T = S<92>;
diff --git a/crates/syntax/test_data/parser/inline/ok/0185_assoc_type_bound.rast b/crates/syntax/test_data/parser/inline/ok/0185_assoc_type_bound.rast
new file mode 100644
index 0000000000..24519dc841
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0185_assoc_type_bound.rast
@@ -0,0 +1,37 @@
+ [email protected] "StreamingIterator"
diff --git a/crates/syntax/test_data/parser/inline/ok/0185_assoc_type_bound.rs b/crates/syntax/test_data/parser/inline/ok/0185_assoc_type_bound.rs
new file mode 100644
index 0000000000..daae97e4fd
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0185_assoc_type_bound.rs
@@ -0,0 +1 @@
+type T = StreamingIterator<Item<'a>: Clone>;
diff --git a/crates/syntax/test_data/parser/inline/ok/0186_lifetime_arg.rast b/crates/syntax/test_data/parser/inline/ok/0186_lifetime_arg.rast
new file mode 100644
index 0000000000..812d222211
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0186_lifetime_arg.rast
@@ -0,0 +1,22 @@
+ [email protected] "'static"
diff --git a/crates/syntax/test_data/parser/inline/ok/0186_lifetime_arg.rs b/crates/syntax/test_data/parser/inline/ok/0186_lifetime_arg.rs
new file mode 100644
index 0000000000..41715aa273
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0186_lifetime_arg.rs
@@ -0,0 +1 @@
+type T = S<'static>;
diff --git a/crates/syntax/test_data/parser/inline/ok/0187_assoc_type_eq.rast b/crates/syntax/test_data/parser/inline/ok/0187_assoc_type_eq.rast
new file mode 100644
index 0000000000..308cea77f5
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0187_assoc_type_eq.rast
@@ -0,0 +1,41 @@
+ [email protected] "StreamingIterator"
diff --git a/crates/syntax/test_data/parser/inline/ok/0187_assoc_type_eq.rs b/crates/syntax/test_data/parser/inline/ok/0187_assoc_type_eq.rs
new file mode 100644
index 0000000000..3591417473
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0187_assoc_type_eq.rs
@@ -0,0 +1 @@
+type T = StreamingIterator<Item<'a> = &'a T>;
diff --git a/crates/syntax/test_data/parser/inline/ok/0188_const_arg_path.rast b/crates/syntax/test_data/parser/inline/ok/0188_const_arg_path.rast
new file mode 100644
index 0000000000..8da0121001
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0188_const_arg_path.rast
@@ -0,0 +1,37 @@
diff --git a/crates/syntax/test_data/parser/inline/ok/0188_const_arg_path.rs b/crates/syntax/test_data/parser/inline/ok/0188_const_arg_path.rs
new file mode 100644
index 0000000000..ee075f3e50
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0188_const_arg_path.rs
@@ -0,0 +1 @@
+struct S<const N: u32 = u32::MAX>;
diff --git a/crates/syntax/test_data/parser/inline/ok/0189_const_arg_literal.rast b/crates/syntax/test_data/parser/inline/ok/0189_const_arg_literal.rast
new file mode 100644
index 0000000000..a94cd256aa
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0189_const_arg_literal.rast
@@ -0,0 +1,27 @@
+ [email protected] "\"hello\""
+ [email protected] "0xdeadbeef"
diff --git a/crates/syntax/test_data/parser/inline/ok/0189_const_arg_literal.rs b/crates/syntax/test_data/parser/inline/ok/0189_const_arg_literal.rs
new file mode 100644
index 0000000000..7eacada73a
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0189_const_arg_literal.rs
@@ -0,0 +1 @@
+type T = S<"hello", 0xdeadbeef>;
diff --git a/crates/syntax/test_data/parser/inline/ok/0190_generic_arg.rast b/crates/syntax/test_data/parser/inline/ok/0190_generic_arg.rast
new file mode 100644
index 0000000000..c41d29071b
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0190_generic_arg.rast
@@ -0,0 +1,25 @@
diff --git a/crates/syntax/test_data/parser/inline/ok/0190_generic_arg.rs b/crates/syntax/test_data/parser/inline/ok/0190_generic_arg.rs
new file mode 100644
index 0000000000..f2ccc558bb
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0190_generic_arg.rs
@@ -0,0 +1 @@
+type T = S<i32>;
diff --git a/crates/syntax/test_data/parser/inline/ok/0191_const_arg_negative_number.rast b/crates/syntax/test_data/parser/inline/ok/0191_const_arg_negative_number.rast
new file mode 100644
index 0000000000..87ff6cb7bf
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0191_const_arg_negative_number.rast
@@ -0,0 +1,24 @@
diff --git a/crates/syntax/test_data/parser/inline/ok/0191_const_arg_negative_number.rs b/crates/syntax/test_data/parser/inline/ok/0191_const_arg_negative_number.rs
new file mode 100644
index 0000000000..d0a87bdc03
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0191_const_arg_negative_number.rs
@@ -0,0 +1 @@
+type T = S<-92>;
diff --git a/crates/syntax/test_data/parser/inline/ok/0192_const_arg_bool_literal.rast b/crates/syntax/test_data/parser/inline/ok/0192_const_arg_bool_literal.rast
new file mode 100644
index 0000000000..7c44c6b82d
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0192_const_arg_bool_literal.rast
@@ -0,0 +1,22 @@
diff --git a/crates/syntax/test_data/parser/inline/ok/0192_const_arg_bool_literal.rs b/crates/syntax/test_data/parser/inline/ok/0192_const_arg_bool_literal.rs
new file mode 100644
index 0000000000..4b92e2d487
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0192_const_arg_bool_literal.rs
@@ -0,0 +1 @@
+type T = S<true>;