about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <dirbaio@dirbaio.net>2022-03-10 18:10:03 +0100
committerDario Nieuwenhuis <dirbaio@dirbaio.net>2022-03-10 18:21:29 +0100
commit49d12077757fc937f8c8fac1f800436153eb5d4e (patch)
treec1e877e72a4f332c11a105ad86151d33855c195a
parent356c507357d32951924516217b402909c820ce9c (diff)
downloadrust-49d12077757fc937f8c8fac1f800436153eb5d4e.tar.gz
rust-49d12077757fc937f8c8fac1f800436153eb5d4e.zip
Add support for new `where` clause location in associated types.
A recent Rust nightly changed it: https://github.com/rust-lang/rust/issues/89122

This allows both the old and new location.
-rw-r--r--crates/parser/src/grammar/items.rs7
-rw-r--r--crates/parser/test_data/parser/inline/ok/0012_type_item_where_clause.rast12
-rw-r--r--crates/parser/test_data/parser/inline/ok/0012_type_item_where_clause.rs2
-rw-r--r--crates/parser/test_data/parser/inline/ok/0199_type_item_where_clause_deprecated.rast33
-rw-r--r--crates/parser/test_data/parser/inline/ok/0199_type_item_where_clause_deprecated.rs1
5 files changed, 47 insertions, 8 deletions
diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs
index 36d13cc9773..7bfd9ef8c8a 100644
--- a/crates/parser/src/grammar/items.rs
+++ b/crates/parser/src/grammar/items.rs
@@ -290,12 +290,17 @@ fn type_alias(p: &mut Parser, m: Marker) {
         generic_params::bounds(p);
     }
 
-    // test type_item_where_clause
+    // test type_item_where_clause_deprecated
     // type Foo where Foo: Copy = ();
     generic_params::opt_where_clause(p);
     if p.eat(T![=]) {
         types::type_(p);
     }
+
+    // test type_item_where_clause
+    // type Foo = () where Foo: Copy;
+    generic_params::opt_where_clause(p);
+
     p.expect(T![;]);
     m.complete(p, TYPE_ALIAS);
 }
diff --git a/crates/parser/test_data/parser/inline/ok/0012_type_item_where_clause.rast b/crates/parser/test_data/parser/inline/ok/0012_type_item_where_clause.rast
index 7210b738958..31c87d1b309 100644
--- a/crates/parser/test_data/parser/inline/ok/0012_type_item_where_clause.rast
+++ b/crates/parser/test_data/parser/inline/ok/0012_type_item_where_clause.rast
@@ -5,6 +5,12 @@ SOURCE_FILE
     NAME
       IDENT "Foo"
     WHITESPACE " "
+    EQ "="
+    WHITESPACE " "
+    TUPLE_TYPE
+      L_PAREN "("
+      R_PAREN ")"
+    WHITESPACE " "
     WHERE_CLAUSE
       WHERE_KW "where"
       WHITESPACE " "
@@ -23,11 +29,5 @@ SOURCE_FILE
                 PATH_SEGMENT
                   NAME_REF
                     IDENT "Copy"
-    WHITESPACE " "
-    EQ "="
-    WHITESPACE " "
-    TUPLE_TYPE
-      L_PAREN "("
-      R_PAREN ")"
     SEMICOLON ";"
   WHITESPACE "\n"
diff --git a/crates/parser/test_data/parser/inline/ok/0012_type_item_where_clause.rs b/crates/parser/test_data/parser/inline/ok/0012_type_item_where_clause.rs
index a602d07f03b..2d30e852187 100644
--- a/crates/parser/test_data/parser/inline/ok/0012_type_item_where_clause.rs
+++ b/crates/parser/test_data/parser/inline/ok/0012_type_item_where_clause.rs
@@ -1 +1 @@
-type Foo where Foo: Copy = ();
+type Foo = () where Foo: Copy;
diff --git a/crates/parser/test_data/parser/inline/ok/0199_type_item_where_clause_deprecated.rast b/crates/parser/test_data/parser/inline/ok/0199_type_item_where_clause_deprecated.rast
new file mode 100644
index 00000000000..7210b738958
--- /dev/null
+++ b/crates/parser/test_data/parser/inline/ok/0199_type_item_where_clause_deprecated.rast
@@ -0,0 +1,33 @@
+SOURCE_FILE
+  TYPE_ALIAS
+    TYPE_KW "type"
+    WHITESPACE " "
+    NAME
+      IDENT "Foo"
+    WHITESPACE " "
+    WHERE_CLAUSE
+      WHERE_KW "where"
+      WHITESPACE " "
+      WHERE_PRED
+        PATH_TYPE
+          PATH
+            PATH_SEGMENT
+              NAME_REF
+                IDENT "Foo"
+        COLON ":"
+        WHITESPACE " "
+        TYPE_BOUND_LIST
+          TYPE_BOUND
+            PATH_TYPE
+              PATH
+                PATH_SEGMENT
+                  NAME_REF
+                    IDENT "Copy"
+    WHITESPACE " "
+    EQ "="
+    WHITESPACE " "
+    TUPLE_TYPE
+      L_PAREN "("
+      R_PAREN ")"
+    SEMICOLON ";"
+  WHITESPACE "\n"
diff --git a/crates/parser/test_data/parser/inline/ok/0199_type_item_where_clause_deprecated.rs b/crates/parser/test_data/parser/inline/ok/0199_type_item_where_clause_deprecated.rs
new file mode 100644
index 00000000000..a602d07f03b
--- /dev/null
+++ b/crates/parser/test_data/parser/inline/ok/0199_type_item_where_clause_deprecated.rs
@@ -0,0 +1 @@
+type Foo where Foo: Copy = ();