[COMMITTED 031/141] gccrs: Clone expr instead of taking it

arthur.cohen@embecosm.com arthur.cohen@embecosm.com
Mon Mar 24 12:44:14 GMT 2025


From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

We're reusing the value, it could therefore not be taken be should be
cloned.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit):
	Clone expr instead of taking it.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
 gcc/rust/typecheck/rust-hir-type-check-enumitem.cc | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
index 4bf7b72c1e9..7fa4b43d187 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
@@ -142,10 +142,11 @@ TypeCheckEnumItem::visit (HIR::EnumItemDiscriminant &item)
   rust_assert (canonical_path.has_value ());
 
   RustIdent ident{*canonical_path, item.get_locus ()};
-  variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
-				  item.get_mappings ().get_defid (),
-				  item.get_identifier ().as_string (), ident,
-				  item.take_discriminant_expression ());
+  variant
+    = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
+			    item.get_mappings ().get_defid (),
+			    item.get_identifier ().as_string (), ident,
+			    item.get_discriminant_expression ().clone_expr ());
 }
 
 void
-- 
2.45.2



More information about the Gcc-rust mailing list