[gccrs COMMIT] gccrs: Fix HIR::ClosureExpr copying

gerris.rs@gmail.com gerris.rs@gmail.com
Fri Sep 11 08:42:49 GMT 2026


From: Owen Avery <powerboat9.gamer@gmail.com>

gcc/rust/ChangeLog:

	* hir/tree/rust-hir-expr.cc
	(ClosureParam::ClosureParam): Set locus.
	(ClosureParam::operator=): Likewise.
	(ClosureExpr::ClosureExpr): Likewise.
	(ClosureExpr::operator=): Likewise.
	* typecheck/rust-hir-type-check-expr.cc
	(TypeCheckExpr::visit (ClosureExpr)): Use
	Mappings::get_lang_item.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-4740.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: https://github.com/Rust-GCC/gccrs/commit/add37b32daa982f65dc56852ce0a562c54e27950

The commit has NOT been mentioned in any issue.

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4886

 gcc/rust/hir/tree/rust-hir-expr.cc             |  6 +++++-
 gcc/rust/typecheck/rust-hir-type-check-expr.cc | 12 ++----------
 gcc/testsuite/rust/compile/issue-4740.rs       | 10 ++++++++++
 3 files changed, 17 insertions(+), 11 deletions(-)
 create mode 100644 gcc/testsuite/rust/compile/issue-4740.rs

diff --git a/gcc/rust/hir/tree/rust-hir-expr.cc b/gcc/rust/hir/tree/rust-hir-expr.cc
index e45178af4..c4ccad149 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.cc
+++ b/gcc/rust/hir/tree/rust-hir-expr.cc
@@ -668,7 +668,7 @@ ClosureParam::ClosureParam (std::unique_ptr<Pattern> param_pattern,
 {}
 
 ClosureParam::ClosureParam (ClosureParam const &other)
-  : pattern (other.pattern->clone_pattern ())
+  : pattern (other.pattern->clone_pattern ()), locus (other.locus)
 {
   // guard to protect from null pointer dereference
   if (other.pattern != nullptr)
@@ -692,6 +692,8 @@ ClosureParam::operator= (ClosureParam const &other)
   else
     type = nullptr;
 
+  locus = other.locus;
+
   return *this;
 }
 
@@ -714,6 +716,7 @@ ClosureExpr::ClosureExpr (ClosureExpr const &other)
   expr = other.expr->clone_expr ();
   params = other.params;
   has_move = other.has_move;
+  locus = other.locus;
 }
 
 ClosureExpr &
@@ -725,6 +728,7 @@ ClosureExpr::operator= (ClosureExpr const &other)
   expr = other.expr->clone_expr ();
   params = other.params;
   has_move = other.has_move;
+  locus = other.locus;
 
   return *this;
 }
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index c4cca34ca..fdc17fe44 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1978,16 +1978,8 @@ TypeCheckExpr::visit (HIR::ClosureExpr &expr)
 
   LangItem::Kind lang_item_type = LangItem::Kind::FN_ONCE;
 
-  auto lang_item_defined = mappings.lookup_lang_item (lang_item_type);
-  if (!lang_item_defined)
-    {
-      // FIXME
-      // we need to have a unified way or error'ing when we are missing lang
-      // items that is useful
-      rust_fatal_error (expr.get_locus (), "unable to find lang item: %qs",
-			LangItem::ToString (lang_item_type).c_str ());
-    }
-  DefId &respective_lang_item_id = lang_item_defined.value ();
+  DefId respective_lang_item_id
+    = mappings.get_lang_item (lang_item_type, expr.get_locus ());
 
   // these lang items are always traits
   HIR::Item *item = mappings.lookup_defid (respective_lang_item_id).value ();
diff --git a/gcc/testsuite/rust/compile/issue-4740.rs b/gcc/testsuite/rust/compile/issue-4740.rs
new file mode 100644
index 000000000..3c0969dba
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4740.rs
@@ -0,0 +1,10 @@
+#![feature(no_core)]
+#![no_core]
+
+trait A {
+    fn foo();
+}
+
+// { dg-error "failed to find lang item" "" { target *-*-* } .+1 }
+impl A for [(); (|| 1) ()] {}
+// { dg-message "terminated" "" { target *-*-* } 0 }

base-commit: 1a69267c329f434e3296f48f7b4694a91cb8d7e7
-- 
2.55.0



More information about the Gcc-rust mailing list