https://gcc.gnu.org/g:948e4a63455c090afd491c7b669896d47ae08559
commit r16-2981-g948e4a63455c090afd491c7b669896d47ae08559 Author: Philip Herron <herron.phi...@googlemail.com> Date: Thu Jul 31 21:46:42 2025 +0100 gccrs: Fix ICE during const eval of const capacity We assert that struct expressions during code-gen must be of TyTy::ADTType but we can simply just check for this and return error_mark_node to make this safe. Fixes Rust-GCC#3960 gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): check for ADTType instead of assert gcc/testsuite/ChangeLog: * rust/compile/issue-3960.rs: New test. Signed-off-by: Philip Herron <herron.phi...@googlemail.com> Diff: --- gcc/rust/backend/rust-compile-expr.cc | 2 ++ gcc/testsuite/rust/compile/issue-3960.rs | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 547bb7c27a8e..8deb55ab77d6 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -490,6 +490,8 @@ CompileExpr::visit (HIR::StructExprStructFields &struct_expr) rust_error_at (struct_expr.get_locus (), "unknown type"); return; } + if (!tyty->is<TyTy::ADTType> ()) + return; // it must be an ADT rust_assert (tyty->get_kind () == TyTy::TypeKind::ADT); diff --git a/gcc/testsuite/rust/compile/issue-3960.rs b/gcc/testsuite/rust/compile/issue-3960.rs new file mode 100644 index 000000000000..57329f0d48aa --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3960.rs @@ -0,0 +1,7 @@ +fn main() { + struct G { + g: (), + } + let g = [0; G { g: () }]; + // { dg-error "mismatched types, expected .usize. but got .G. .E0308." "" { target *-*-* } .-1 } +}