From: Philip Herron <[email protected]>
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]>
---
gcc/rust/backend/rust-compile-resolve-path.cc | 7 +++++--
gcc/testsuite/rust/compile/issue-3538.rs | 9 +++++++++
2 files changed, 14 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-3538.rs
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc
b/gcc/rust/backend/rust-compile-resolve-path.cc
index f3b9dc28db2..c33d0b072d0 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 00000000000..72694571f88
--- /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 }
+}
--
2.50.1