From 41fc5f7c2a046952dc624c0617a73c14a37b5940 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Tue, 8 Mar 2016 14:38:44 +0200 Subject: [PATCH] mir: Trigger closure instantiations when the closure value is created. --- src/librustc_trans/trans/mir/rvalue.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/librustc_trans/trans/mir/rvalue.rs b/src/librustc_trans/trans/mir/rvalue.rs index d2806f3daba..a3b46c161d3 100644 --- a/src/librustc_trans/trans/mir/rvalue.rs +++ b/src/librustc_trans/trans/mir/rvalue.rs @@ -132,6 +132,31 @@ pub fn trans_rvalue(&mut self, } }, _ => { + // FIXME Shouldn't need to manually trigger closure instantiations. + if let mir::AggregateKind::Closure(def_id, substs) = *kind { + use rustc_front::hir; + use syntax::ast::DUMMY_NODE_ID; + use syntax::codemap::DUMMY_SP; + use syntax::ptr::P; + use trans::closure; + + closure::trans_closure_expr(closure::Dest::Ignore(bcx.ccx()), + &hir::FnDecl { + inputs: P::new(), + output: hir::NoReturn(DUMMY_SP), + variadic: false + }, + &hir::Block { + stmts: P::new(), + expr: None, + id: DUMMY_NODE_ID, + rules: hir::DefaultBlock, + span: DUMMY_SP + }, + DUMMY_NODE_ID, def_id, + &bcx.monomorphize(substs)); + } + for (i, operand) in operands.iter().enumerate() { let op = self.trans_operand(&bcx, operand); // Do not generate stores and GEPis for zero-sized fields. -- GitLab