https://gcc.gnu.org/g:c73e44a59cf2cff84d0996182e8423425723c9da
commit r16-4870-gc73e44a59cf2cff84d0996182e8423425723c9da Author: Philip Herron <[email protected]> Date: Mon Sep 22 20:29:28 2025 +0100 gccrs: Fix ICE where we expect a num enum variant 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 <[email protected]> Diff: --- gcc/rust/backend/rust-compile-resolve-path.cc | 7 +++++-- gcc/testsuite/rust/compile/issue-3538.rs | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc index f3b9dc28db21..c33d0b072d06 100644 --- a/gcc/rust/backend/rust-compile-resolve-path.cc +++ b/gcc/rust/backend/rust-compile-resolve-path.cc @@ -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 index 000000000000..72694571f888 --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3538.rs @@ -0,0 +1,9 @@ +enum A { + Value(()), +} + +fn main() { + let a = A::Value(()); + a == A::Value; + // { dg-error "variant expected constructor call" "" { target *-*-* } .-1 } +}
