Repository: rust-analyzer/rust-analyzer
Pull request #486 (2019-01-10 18:22:20)

Fix handling of where clauses in tuple structs
Originally reported by @max-frai on discord.

As I was writing this, I was wondering if there's any way we can compare our test suite against libsyntax (i.e. check that it similarly fails/succeeds). Any ideas?


Patch:
diff --git a/crates/ra_syntax/src/grammar/items/nominal.rs b/crates/ra_syntax/src/grammar/items/nominal.rs
index 8d02ad555a..495462ca7a 100644
--- a/crates/ra_syntax/src/grammar/items/nominal.rs
+++ b/crates/ra_syntax/src/grammar/items/nominal.rs
@@ -29,6 +29,10 @@ pub(super) fn struct_def(p: &mut Parser, kind: SyntaxKind) {
         L_CURLY => named_field_def_list(p),
         L_PAREN if kind == STRUCT_KW => {
             pos_field_list(p);
+            // test tuple_struct_where
+            // struct Test<T>(T) where T: Clone;
+            // struct Test<T>(T);
+            type_params::opt_where_clause(p);
             p.expect(SEMI);
         }
         _ if kind == STRUCT_KW => {


Test patch:
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0114_tuple_struct_where.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0114_tuple_struct_where.rs
new file mode 100644
index 0000000000..ddd59016dc
--- /dev/null
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0114_tuple_struct_where.rs
@@ -0,0 +1,2 @@
+struct Test<T>(T) where T: Clone;
+struct Test<T>(T);
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0114_tuple_struct_where.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0114_tuple_struct_where.txt
new file mode 100644
index 0000000000..b7de83072f
--- /dev/null
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0114_tuple_struct_where.txt
@@ -0,0 +1,62 @@
+SOURCE_FILE@[0; 53)
+  STRUCT_DEF@[0; 33)
+    STRUCT_KW@[0; 6)
+    WHITESPACE@[6; 7)
+    NAME@[7; 11)
+      IDENT@[7; 11) "Test"
+    TYPE_PARAM_LIST@[11; 14)
+      L_ANGLE@[11; 12)
+      TYPE_PARAM@[12; 13)
+        NAME@[12; 13)
+          IDENT@[12; 13) "T"
+      R_ANGLE@[13; 14)
+    POS_FIELD_LIST@[14; 17)
+      L_PAREN@[14; 15)
+      POS_FIELD@[15; 16)
+        PATH_TYPE@[15; 16)
+          PATH@[15; 16)
+            PATH_SEGMENT@[15; 16)
+              NAME_REF@[15; 16)
+                IDENT@[15; 16) "T"
+      R_PAREN@[16; 17)
+    WHITESPACE@[17; 18)
+    WHERE_CLAUSE@[18; 32)
+      WHERE_KW@[18; 23)
+      WHITESPACE@[23; 24)
+      WHERE_PRED@[24; 32)
+        PATH_TYPE@[24; 25)
+          PATH@[24; 25)
+            PATH_SEGMENT@[24; 25)
+              NAME_REF@[24; 25)
+                IDENT@[24; 25) "T"
+        COLON@[25; 26)
+        WHITESPACE@[26; 27)
+        PATH_TYPE@[27; 32)
+          PATH@[27; 32)
+            PATH_SEGMENT@[27; 32)
+              NAME_REF@[27; 32)
+                IDENT@[27; 32) "Clone"
+    SEMI@[32; 33)
+  WHITESPACE@[33; 34)
+  STRUCT_DEF@[34; 52)
+    STRUCT_KW@[34; 40)
+    WHITESPACE@[40; 41)
+    NAME@[41; 45)
+      IDENT@[41; 45) "Test"
+    TYPE_PARAM_LIST@[45; 48)
+      L_ANGLE@[45; 46)
+      TYPE_PARAM@[46; 47)
+        NAME@[46; 47)
+          IDENT@[46; 47) "T"
+      R_ANGLE@[47; 48)
+    POS_FIELD_LIST@[48; 51)
+      L_PAREN@[48; 49)
+      POS_FIELD@[49; 50)
+        PATH_TYPE@[49; 50)
+          PATH@[49; 50)
+            PATH_SEGMENT@[49; 50)
+              NAME_REF@[49; 50)
+                IDENT@[49; 50) "T"
+      R_PAREN@[50; 51)
+    SEMI@[51; 52)
+  WHITESPACE@[52; 53)