[wgsl-parser] Consume empty struct closing brace.

This CL updates the WGSL parser to consume the closing } of an empty
struct.

Bug: tint:218
Change-Id: I0b17d2178b1b4b7f44fcf007da867db07dc2a6ae
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/27600
Reviewed-by: Sarah Mashayekhi <sarahmashay@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/src/reader/wgsl/parser_impl.cc b/src/reader/wgsl/parser_impl.cc
index 7e3064d..fdc9df7 100644
--- a/src/reader/wgsl/parser_impl.cc
+++ b/src/reader/wgsl/parser_impl.cc
@@ -1021,12 +1021,6 @@
     return nullptr;
   }
 
-  t = peek();
-  if (!t.IsBraceLeft()) {
-    set_error(t, "missing { for struct declaration");
-    return nullptr;
-  }
-
   auto body = struct_body_decl();
   if (has_error()) {
     return nullptr;
@@ -1075,14 +1069,17 @@
 //   : BRACKET_LEFT struct_member* BRACKET_RIGHT
 ast::StructMemberList ParserImpl::struct_body_decl() {
   auto t = peek();
-  if (!t.IsBraceLeft())
+  if (!t.IsBraceLeft()) {
+    set_error(t, "missing { for struct declaration");
     return {};
-
+  }
   next();  // Consume the peek
 
   t = peek();
-  if (t.IsBraceRight())
+  if (t.IsBraceRight()) {
+    next();  // Consume the peek
     return {};
+  }
 
   ast::StructMemberList members;
   for (;;) {
diff --git a/src/reader/wgsl/parser_impl_type_alias_test.cc b/src/reader/wgsl/parser_impl_type_alias_test.cc
index 383a035..2995881 100644
--- a/src/reader/wgsl/parser_impl_type_alias_test.cc
+++ b/src/reader/wgsl/parser_impl_type_alias_test.cc
@@ -109,6 +109,24 @@
   EXPECT_EQ(arr->array_stride(), 4u);
 }
 
+// This was failing due to not finding the missing ;. https://crbug.com/tint/218
+TEST_F(ParserImplTest, TypeDecl_Struct_Empty) {
+  auto* p = parser("type str = struct {};");
+  p->global_decl();
+  ASSERT_FALSE(p->has_error()) << p->error();
+
+  auto module = p->module();
+  ASSERT_EQ(module.alias_types().size(), 1u);
+
+  auto* t = module.alias_types()[0];
+  ASSERT_NE(t, nullptr);
+  EXPECT_EQ(t->name(), "str");
+
+  ASSERT_TRUE(t->type()->IsStruct());
+  auto* s = t->type()->AsStruct();
+  EXPECT_EQ(s->impl()->members().size(), 0u);
+}
+
 }  // namespace
 }  // namespace wgsl
 }  // namespace reader