From: lishin <[email protected]>
gcc/rust/ChangeLog:
* rust-gcc.cc (constructor_expression):
Ensure vec_alloc reserves at least one element.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3947.rs: New test.
Signed-off-by: lishin <[email protected]>
---
gcc/rust/rust-gcc.cc | 2 +-
gcc/testsuite/rust/compile/issue-3947.rs | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/rust/compile/issue-3947.rs
diff --git a/gcc/rust/rust-gcc.cc b/gcc/rust/rust-gcc.cc
index 398dea17d14..8f950d176f2 100644
--- a/gcc/rust/rust-gcc.cc
+++ b/gcc/rust/rust-gcc.cc
@@ -1258,7 +1258,7 @@ constructor_expression (tree type_tree, bool is_variant,
return error_mark_node;
vec<constructor_elt, va_gc> *init;
- vec_alloc (init, vals.size ());
+ vec_alloc (init, union_index != -1 ? 1 : vals.size ());
tree sink = NULL_TREE;
bool is_constant = true;
diff --git a/gcc/testsuite/rust/compile/issue-3947.rs
b/gcc/testsuite/rust/compile/issue-3947.rs
new file mode 100644
index 00000000000..58ccde6a91d
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3947.rs
@@ -0,0 +1,10 @@
+enum _Enum {
+ A(),
+}
+
+type _E = _Enum;
+
+// { dg-warning "function is never used: '_a'" "" { target *-*-* } .+1 }
+const fn _a() -> _Enum {
+ _E::A()
+}
--
2.50.1