Unnamed repository; edit this file 'description' to name the repository.
internal: more focused trait item parsing tests
13 files changed, 242 insertions, 228 deletions
diff --git a/crates/parser/src/grammar/items/traits.rs b/crates/parser/src/grammar/items/traits.rs index 569fc58a1c..a8577f2acf 100644 --- a/crates/parser/src/grammar/items/traits.rs +++ b/crates/parser/src/grammar/items/traits.rs @@ -1,28 +1,39 @@ use super::*; // test trait_item -// trait T<U>: Hash + Clone where U: Copy {} -// trait X<U: Debug + Display>: Hash + Clone where U: Copy {} +// trait T { fn new() -> Self; } pub(super) fn trait_(p: &mut Parser, m: Marker) { - assert!(p.at(T![trait])); p.bump(T![trait]); name_r(p, ITEM_RECOVERY_SET); + + // test trait_item_generic_params + // trait X<U: Debug + Display> {} type_params::opt_generic_param_list(p); - // test trait_alias - // trait Z<U> = T<U>; - // trait Z<U> = T<U> where U: Copy; - // trait Z<U> = where Self: T<U>; + if p.eat(T![=]) { + // test trait_alias + // trait Z<U> = T<U>; type_params::bounds_without_colon(p); + + // test trait_alias_where_clause + // trait Z<U> = T<U> where U: Copy; + // trait Z<U> = where Self: T<U>; type_params::opt_where_clause(p); p.expect(T![;]); m.complete(p, TRAIT); return; } + if p.at(T![:]) { + // test trait_item_bounds + // trait T: Hash + Clone {} type_params::bounds(p); } + + // test trait_item_where_clause + // trait T where Self: Copy {} type_params::opt_where_clause(p); + if p.at(T!['{']) { assoc_item_list(p); } else { diff --git a/crates/syntax/test_data/parser/inline/ok/0041_trait_item.rast b/crates/syntax/test_data/parser/inline/ok/0041_trait_item.rast index 3638462f8b..f7814abaa4 100644 --- a/crates/syntax/test_data/parser/inline/ok/0041_trait_item.rast +++ b/crates/syntax/test_data/parser/inline/ok/0041_trait_item.rast @@ -1,125 +1,31 @@ [email protected] "trait" - [email protected] "<" - [email protected] "U" - [email protected] ">" - [email protected] ":" - [email protected] " " - [email protected] "Hash" - [email protected] " " - [email protected] "+" - [email protected] " " - [email protected] "Clone" - [email protected] " " - [email protected] "where" - [email protected] " " - [email protected] "U" - [email protected] ":" - [email protected] " " - [email protected] "Copy" - [email protected] " " - [email protected] "{" - [email protected] "}" - [email protected] "\n" - [email protected] "trait" - [email protected] " " - [email protected] "X" - [email protected] "<" - [email protected] "U" - [email protected] ":" - [email protected] " " - [email protected] "Debug" - [email protected] " " - [email protected] "+" - [email protected] " " - [email protected] "Display" - [email protected] ">" - [email protected] ":" - [email protected] " " - [email protected] "Hash" - [email protected] " " - [email protected] "+" - [email protected] " " - [email protected] "Clone" - [email protected] " " - [email protected] "where" - [email protected] " " - [email protected] "U" - [email protected] ":" - [email protected] " " - [email protected] "Copy" - [email protected] " " - [email protected] "{" - [email protected] "}" - [email protected] "\n" + [email protected] " " + [email protected] "{" + [email protected] " " + [email protected] "fn" + [email protected] " " + [email protected] "new" + [email protected] "(" + [email protected] ")" + [email protected] " " + [email protected] "->" + [email protected] " " + [email protected] "Self" + [email protected] ";" + [email protected] " " + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0041_trait_item.rs b/crates/syntax/test_data/parser/inline/ok/0041_trait_item.rs index 32761dd03d..dcd9a71144 100644 --- a/crates/syntax/test_data/parser/inline/ok/0041_trait_item.rs +++ b/crates/syntax/test_data/parser/inline/ok/0041_trait_item.rs @@ -1,2 +1 @@ -trait T<U>: Hash + Clone where U: Copy {} -trait X<U: Debug + Display>: Hash + Clone where U: Copy {} +trait T { fn new() -> Self; } diff --git a/crates/syntax/test_data/parser/inline/ok/0151_trait_alias.rast b/crates/syntax/test_data/parser/inline/ok/0151_trait_alias.rast index dac50410e4..6bcbd0f1c6 100644 --- a/crates/syntax/test_data/parser/inline/ok/0151_trait_alias.rast +++ b/crates/syntax/test_data/parser/inline/ok/0151_trait_alias.rast @@ -1,4 +1,4 @@ [email protected] "trait" @@ -31,98 +31,3 @@ [email protected] [email protected] "\n" - [email protected] "trait" - [email protected] " " - [email protected] "Z" - [email protected] "<" - [email protected] "U" - [email protected] ">" - [email protected] " " - [email protected] "=" - [email protected] " " - [email protected] "T" - [email protected] "<" - [email protected] "U" - [email protected] ">" - [email protected] " " - [email protected] "where" - [email protected] " " - [email protected] "U" - [email protected] ":" - [email protected] " " - [email protected] "Copy" - [email protected] ";" - [email protected] "\n" - [email protected] "trait" - [email protected] " " - [email protected] "Z" - [email protected] "<" - [email protected] "U" - [email protected] ">" - [email protected] " " - [email protected] "=" - [email protected] " " - [email protected] "where" - [email protected] " " - [email protected] "Self" - [email protected] ":" - [email protected] " " - [email protected] "T" - [email protected] "<" - [email protected] "U" - [email protected] ">" - [email protected] ";" - [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0151_trait_alias.rs b/crates/syntax/test_data/parser/inline/ok/0151_trait_alias.rs index 4bd428ee46..71d76789fa 100644 --- a/crates/syntax/test_data/parser/inline/ok/0151_trait_alias.rs +++ b/crates/syntax/test_data/parser/inline/ok/0151_trait_alias.rs @@ -1,3 +1 @@ trait Z<U> = T<U>; -trait Z<U> = T<U> where U: Copy; -trait Z<U> = where Self: T<U>; diff --git a/crates/syntax/test_data/parser/inline/ok/0174_trait_item_generic_params.rast b/crates/syntax/test_data/parser/inline/ok/0174_trait_item_generic_params.rast new file mode 100644 index 0000000000..f7af2e30e8 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0174_trait_item_generic_params.rast @@ -0,0 +1,35 @@ + [email protected] "trait" + [email protected] " " + [email protected] "X" + [email protected] "<" + [email protected] "U" + [email protected] ":" + [email protected] " " + [email protected] "Debug" + [email protected] " " + [email protected] "+" + [email protected] " " + [email protected] "Display" + [email protected] ">" + [email protected] " " + [email protected] "{" + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0174_trait_item_generic_params.rs b/crates/syntax/test_data/parser/inline/ok/0174_trait_item_generic_params.rs new file mode 100644 index 0000000000..4a51926a6b --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0174_trait_item_generic_params.rs @@ -0,0 +1 @@ +trait X<U: Debug + Display> {} diff --git a/crates/syntax/test_data/parser/inline/ok/0175_trait_item_bounds.rast b/crates/syntax/test_data/parser/inline/ok/0175_trait_item_bounds.rast new file mode 100644 index 0000000000..f025e32520 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0175_trait_item_bounds.rast @@ -0,0 +1,29 @@ + [email protected] "trait" + [email protected] " " + [email protected] "T" + [email protected] ":" + [email protected] " " + [email protected] "Hash" + [email protected] " " + [email protected] "+" + [email protected] " " + [email protected] "Clone" + [email protected] " " + [email protected] "{" + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0175_trait_item_bounds.rs b/crates/syntax/test_data/parser/inline/ok/0175_trait_item_bounds.rs new file mode 100644 index 0000000000..e6ad2b56af --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0175_trait_item_bounds.rs @@ -0,0 +1 @@ +trait T: Hash + Clone {} diff --git a/crates/syntax/test_data/parser/inline/ok/0176_trait_item_where_clause.rast b/crates/syntax/test_data/parser/inline/ok/0176_trait_item_where_clause.rast new file mode 100644 index 0000000000..85105b4043 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0176_trait_item_where_clause.rast @@ -0,0 +1,30 @@ + [email protected] "trait" + [email protected] " " + [email protected] "T" + [email protected] " " + [email protected] "where" + [email protected] " " + [email protected] "Self" + [email protected] ":" + [email protected] " " + [email protected] "Copy" + [email protected] " " + [email protected] "{" + [email protected] "}" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0176_trait_item_where_clause.rs b/crates/syntax/test_data/parser/inline/ok/0176_trait_item_where_clause.rs new file mode 100644 index 0000000000..52a6a806f3 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0176_trait_item_where_clause.rs @@ -0,0 +1 @@ +trait T where Self: Copy {} diff --git a/crates/syntax/test_data/parser/inline/ok/0177_trait_alias_where_clause.rast b/crates/syntax/test_data/parser/inline/ok/0177_trait_alias_where_clause.rast new file mode 100644 index 0000000000..929182f8ee --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0177_trait_alias_where_clause.rast @@ -0,0 +1,96 @@ + [email protected] "trait" + [email protected] " " + [email protected] "Z" + [email protected] "<" + [email protected] "U" + [email protected] ">" + [email protected] " " + [email protected] "=" + [email protected] " " + [email protected] "T" + [email protected] "<" + [email protected] "U" + [email protected] ">" + [email protected] " " + [email protected] "where" + [email protected] " " + [email protected] "U" + [email protected] ":" + [email protected] " " + [email protected] "Copy" + [email protected] ";" + [email protected] "\n" + [email protected] "trait" + [email protected] " " + [email protected] "Z" + [email protected] "<" + [email protected] "U" + [email protected] ">" + [email protected] " " + [email protected] "=" + [email protected] " " + [email protected] "where" + [email protected] " " + [email protected] "Self" + [email protected] ":" + [email protected] " " + [email protected] "T" + [email protected] "<" + [email protected] "U" + [email protected] ">" + [email protected] ";" + [email protected] "\n" diff --git a/crates/syntax/test_data/parser/inline/ok/0177_trait_alias_where_clause.rs b/crates/syntax/test_data/parser/inline/ok/0177_trait_alias_where_clause.rs new file mode 100644 index 0000000000..a90d54b010 --- /dev/null +++ b/crates/syntax/test_data/parser/inline/ok/0177_trait_alias_where_clause.rs @@ -0,0 +1,2 @@ +trait Z<U> = T<U> where U: Copy; +trait Z<U> = where Self: T<U>; |