gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::generate_closure_function):
handle closure parameters pattern bindings using CompilePatternBindings visitor
gcc/testsuite/ChangeLog:
* rust/execute/torture/closure4.rs: New test.
* rust/execute/torture/ref-pattern2.rs: New test.
Signed-off-by: Mahmoud Mohamed <mahadelr19@gmail.com>
tree compiled_param_var = ctx->get_backend ()->struct_field_expression (
args_param_expr, i, closure_param.get_locus ());
- const HIR::Pattern ¶m_pattern = *closure_param.get_pattern ();
- ctx->insert_pattern_binding (
- param_pattern.get_pattern_mappings ().get_hirid (), compiled_param_var);
+ CompilePatternBindings::Compile (closure_param.get_pattern ().get (),
+ compiled_param_var, ctx);
i++;
}
--- /dev/null
+#[lang = "fn_once"]
+pub trait FnOnce<Args> {
+ #[lang = "fn_once_output"]
+ type Output;
+
+ extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
+}
+
+struct Foo(i32, i32);
+
+fn main() -> i32 {
+ let foo = |&x: &i32, y: i32| -> i32 {
+ x + y
+ };
+
+ let bar = |Foo(x, y): Foo| -> i32 {
+ x + y
+ };
+
+ let a = 4;
+ foo(&a, 2) + bar(Foo(100, 200)) - 306
+}
--- /dev/null
+#[lang = "fn_once"]
+pub trait FnOnce<Args> {
+ #[lang = "fn_once_output"]
+ type Output;
+
+ extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
+}
+
+fn main() -> i32 {
+ let foo = |&&d: &&i32| -> i32 { d };
+
+ let x = &&5i32;
+ foo(x) - 5
+}