]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: [E0063] constructor is missing fields
authorMuhammad Mahad <mahadtxt@gmail.com>
Thu, 6 Jul 2023 13:26:26 +0000 (18:26 +0500)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:49:31 +0000 (18:49 +0100)
Added error code for Missing Field in
struct or struct-like enum variant.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve):
called error function.

gcc/testsuite/ChangeLog:

* rust/compile/missing_constructor_fields.rs: New test.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
gcc/rust/typecheck/rust-hir-type-check-struct.cc
gcc/testsuite/rust/compile/missing_constructor_fields.rs [new file with mode: 0644]

index 08d4c2efdee2b9b7bbca7037560ede41a88534a4..08488093fdd2005e6a721a7456df7edb2b7f638a 100644 (file)
@@ -149,7 +149,7 @@ TypeCheckStructExpr::resolve (HIR::StructExprStructFields &struct_expr)
        }
       else if (!struct_expr.has_struct_base ())
        {
-         rust_error_at (struct_expr.get_locus (),
+         rust_error_at (struct_expr.get_locus (), ErrorCode ("E0063"),
                         "constructor is missing fields");
          return;
        }
diff --git a/gcc/testsuite/rust/compile/missing_constructor_fields.rs b/gcc/testsuite/rust/compile/missing_constructor_fields.rs
new file mode 100644 (file)
index 0000000..9d49210
--- /dev/null
@@ -0,0 +1,10 @@
+// https://doc.rust-lang.org/error_codes/E0063.html
+struct Foo {
+    x: i32,
+    y: i32,
+    z: i32,
+}
+
+fn main() {
+    let x = Foo { x: 0 , y:1 }; // { dg-error "constructor is missing fields" }
+}
\ No newline at end of file