Skip to content

Commit 551b071

Browse files
committed
gccrs: Fix ICE where we expect a num enum variant
This changes the assertion into a valid error diagnostic. Fixes #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]>
1 parent 5a762b9 commit 551b071

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

gcc/rust/backend/rust-compile-resolve-path.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ ResolvePathRef::attempt_constructor_expression_lookup (
9797

9898
// this can only be for discriminant variants the others are built up
9999
// using call-expr or struct-init
100-
rust_assert (variant->get_variant_type ()
101-
== TyTy::VariantDef::VariantType::NUM);
100+
if (variant->get_variant_type () != TyTy::VariantDef::VariantType::NUM)
101+
{
102+
rust_error_at (expr_locus, "variant expected constructor call");
103+
return error_mark_node;
104+
}
102105

103106
// we need the actual gcc type
104107
tree compiled_adt_type = TyTyResolveCompile::compile (ctx, adt);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
enum A {
2+
Value(()),
3+
}
4+
5+
fn main() {
6+
let a = A::Value(());
7+
a == A::Value;
8+
// { dg-error "variant expected constructor call" "" { target *-*-* } .-1 }
9+
}

0 commit comments

Comments
 (0)