]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Fix ICE where we expect a num enum variant
authorPhilip Herron <herron.philip@googlemail.com>
Mon, 22 Sep 2025 19:29:28 +0000 (20:29 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 20:30:52 +0000 (21:30 +0100)
This changes the assertion into a valid error diagnostic.

Fixes Rust-GCC#3538

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc: add error diag

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/backend/rust-compile-resolve-path.cc
gcc/testsuite/rust/compile/issue-3538.rs [new file with mode: 0644]

index f3b9dc28db21247ae7a29164dcc7c464db5328de..c33d0b072d06c259484abfd62b0edc31c6e2bd90 100644 (file)
@@ -97,8 +97,11 @@ ResolvePathRef::attempt_constructor_expression_lookup (
 
   // this can only be for discriminant variants the others are built up
   // using call-expr or struct-init
-  rust_assert (variant->get_variant_type ()
-              == TyTy::VariantDef::VariantType::NUM);
+  if (variant->get_variant_type () != TyTy::VariantDef::VariantType::NUM)
+    {
+      rust_error_at (expr_locus, "variant expected constructor call");
+      return error_mark_node;
+    }
 
   // we need the actual gcc type
   tree compiled_adt_type = TyTyResolveCompile::compile (ctx, adt);
diff --git a/gcc/testsuite/rust/compile/issue-3538.rs b/gcc/testsuite/rust/compile/issue-3538.rs
new file mode 100644 (file)
index 0000000..7269457
--- /dev/null
@@ -0,0 +1,9 @@
+enum A {
+    Value(()),
+}
+
+fn main() {
+    let a = A::Value(());
+    a == A::Value;
+    // { dg-error "variant expected constructor call" "" { target *-*-* } .-1 }
+}