GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gccrs

Fix copying of ClosureExpr in gccrs

GCC Rust's HIR now correctly copies `ClosureExpr` and its parameters, ensuring proper state management.

Owen Avery fixed issues with copying HIR::ClosureExpr in gccrs, ensuring that locus information is set correctly for both the expression and its parameters. This change improves the reliability of closure handling within the compiler’s intermediate representation. It also includes a new test case to cover the corrected behavior, addressing Rust-GCC/gccrs#4740.

In Details

The High-level Intermediate Representation (HIR) for closures in gccrs has been corrected to handle copying properly. Specifically, the copy constructors and assignment operators for ClosureParam and ClosureExpr in rust-hir-expr.cc now correctly set the locus (source location) information. Additionally, TypeCheckExpr::visit(ClosureExpr) in rust-hir-type-check-expr.cc was updated to use Mappings::get_lang_item for potentially more robust handling. A new test case, issue-4740.rs, has been added to verify these changes.

For Context
HIR (High-level Intermediate Representation)
An abstract syntax tree (AST) like representation used within the compiler after initial parsing, but before lower-level intermediate representations. It captures more semantic information than the AST.
ClosureExpr
Represents a closure (an anonymous function that can capture its environment) within the GCC Rust compiler's intermediate representation.
locus
In compiler terminology, this refers to the source code location (like file, line number, and column) associated with a particular piece of code or AST node.
operator=
In C++, this refers to the assignment operator, which defines how one object's state is copied to another existing object of the same type.
Filed Under: gccrsrustHIRbugfix