]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix ICE when handling bad constructor
authorPhilip Herron <herron.philip@googlemail.com>
Thu, 10 Jul 2025 21:58:21 +0000 (22:58 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:55 +0000 (16:36 +0200)
We just had a typo returning ok true when it should have been false.

Fixes Rust-GCC#3876

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::visit): fix typo

gcc/testsuite/ChangeLog:

* rust/compile/issue-3876.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/typecheck/rust-hir-type-check-struct.cc
gcc/testsuite/rust/compile/issue-3876.rs [new file with mode: 0644]

index e3a08e6f044d16471e572a1962e4a2ab7334ff2d..4ef83482a536d8dc02a356b5a569ebff63940825 100644 (file)
@@ -362,7 +362,7 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifier &field)
   if (!ok)
     {
       rust_error_at (field.get_locus (), "unknown field");
-      return true;
+      return false;
     }
 
   auto it = adtFieldIndexToField.find (field_index);
diff --git a/gcc/testsuite/rust/compile/issue-3876.rs b/gcc/testsuite/rust/compile/issue-3876.rs
new file mode 100644 (file)
index 0000000..17b1590
--- /dev/null
@@ -0,0 +1,8 @@
+enum test {
+    A(i32),
+}
+
+fn fun(x: i32) {
+    test::A { x }
+    // { dg-error "unknown field" "" { target *-*-* } .-1 }
+}