https://gcc.gnu.org/g:29bb862bcd7b9276d33d93d9d1e48dca544f9831

commit r17-4349-g29bb862bcd7b9276d33d93d9d1e48dca544f9831
Author: Owen Avery <[email protected]>
Date:   Thu Sep 10 22:19:03 2026 -0400

    gccrs: Fix HIR::ClosureExpr copying
    
    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 <[email protected]>

Diff:
---
 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(-)

diff --git a/gcc/rust/hir/tree/rust-hir-expr.cc 
b/gcc/rust/hir/tree/rust-hir-expr.cc
index e45178af4156..c4ccad1497bf 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 c4cca34ca697..fdc17fe44e25 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 000000000000..3c0969dba8dd
--- /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 }

Reply via email to