diff options
| author | Simonas Kazlauskas <git@kazlauskas.me> | 2016-02-26 14:12:28 +0200 |
|---|---|---|
| committer | Simonas Kazlauskas <git@kazlauskas.me> | 2016-02-26 14:15:38 +0200 |
| commit | d1a12392b2bcbb58538cc99a995e962d2f0cdf45 (patch) | |
| tree | 193af0a6937d585aab94de92a5898960896501ff /src | |
| parent | b7f53b8aa6bafe0642efda7e387507fdb6be56df (diff) | |
| download | rust-d1a12392b2bcbb58538cc99a995e962d2f0cdf45.tar.gz rust-d1a12392b2bcbb58538cc99a995e962d2f0cdf45.zip | |
Nits and cleanups
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/build/block.rs | 16 | ||||
| -rw-r--r-- | src/librustc_mir/hair/cx/block.rs | 53 | ||||
| -rw-r--r-- | src/librustc_trans/trans/mir/block.rs | 2 | ||||
| -rw-r--r-- | src/librustc_trans/trans/mir/rvalue.rs | 7 |
4 files changed, 35 insertions, 43 deletions
diff --git a/src/librustc_mir/build/block.rs b/src/librustc_mir/build/block.rs index 7d8a35165d2..4c80eab102f 100644 --- a/src/librustc_mir/build/block.rs +++ b/src/librustc_mir/build/block.rs @@ -55,17 +55,11 @@ impl<'a,'tcx> Builder<'a,'tcx> { let_extent_stack.push(remainder_scope); unpack!(block = this.in_scope(init_scope, block, move |this| { // FIXME #30046 ^~~~ - match initializer { - Some(initializer) => { - this.expr_into_pattern(block, - remainder_scope, - pattern, - initializer) - } - None => { - this.declare_bindings(remainder_scope, &pattern); - block.unit() - } + if let Some(init) = initializer { + this.expr_into_pattern(block, remainder_scope, pattern, init) + } else { + this.declare_bindings(remainder_scope, &pattern); + block.unit() } })); } diff --git a/src/librustc_mir/hair/cx/block.rs b/src/librustc_mir/hair/cx/block.rs index 66cb1f56b91..c7af42b776f 100644 --- a/src/librustc_mir/hair/cx/block.rs +++ b/src/librustc_mir/hair/cx/block.rs @@ -21,7 +21,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Block { fn make_mirror<'a>(self, cx: &mut Cx<'a, 'tcx>) -> Block<'tcx> { // We have to eagerly translate the "spine" of the statements // in order to get the lexical scoping correctly. - let stmts = mirror_stmts(cx, self.id, self.stmts.iter().enumerate()); + let stmts = mirror_stmts(cx, self.id, &*self.stmts); Block { extent: cx.tcx.region_maps.node_extent(self.id), span: self.span, @@ -31,14 +31,13 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Block { } } -fn mirror_stmts<'a,'tcx:'a,STMTS>(cx: &mut Cx<'a,'tcx>, - block_id: ast::NodeId, - mut stmts: STMTS) - -> Vec<StmtRef<'tcx>> - where STMTS: Iterator<Item=(usize, &'tcx hir::Stmt)> +fn mirror_stmts<'a,'tcx:'a>(cx: &mut Cx<'a,'tcx>, + block_id: ast::NodeId, + stmts: &'tcx [hir::Stmt]) + -> Vec<StmtRef<'tcx>> { let mut result = vec![]; - while let Some((index, stmt)) = stmts.next() { + for (index, stmt) in stmts.iter().enumerate() { match stmt.node { hir::StmtExpr(ref expr, id) | hir::StmtSemi(ref expr, id) => result.push(StmtRef::Mirror(Box::new(Stmt { @@ -48,28 +47,26 @@ fn mirror_stmts<'a,'tcx:'a,STMTS>(cx: &mut Cx<'a,'tcx>, expr: expr.to_ref() } }))), - hir::StmtDecl(ref decl, id) => { - match decl.node { - hir::DeclItem(..) => { /* ignore for purposes of the MIR */ } - hir::DeclLocal(ref local) => { - let remainder_extent = CodeExtentData::Remainder(BlockRemainder { - block: block_id, - first_statement_index: index as u32, - }); - let remainder_extent = - cx.tcx.region_maps.lookup_code_extent(remainder_extent); + hir::StmtDecl(ref decl, id) => match decl.node { + hir::DeclItem(..) => { /* ignore for purposes of the MIR */ } + hir::DeclLocal(ref local) => { + let remainder_extent = CodeExtentData::Remainder(BlockRemainder { + block: block_id, + first_statement_index: index as u32, + }); + let remainder_extent = + cx.tcx.region_maps.lookup_code_extent(remainder_extent); - let pattern = cx.irrefutable_pat(&local.pat); - result.push(StmtRef::Mirror(Box::new(Stmt { - span: stmt.span, - kind: StmtKind::Let { - remainder_scope: remainder_extent, - init_scope: cx.tcx.region_maps.node_extent(id), - pattern: pattern, - initializer: local.init.to_ref(), - }, - }))); - } + let pattern = cx.irrefutable_pat(&local.pat); + result.push(StmtRef::Mirror(Box::new(Stmt { + span: stmt.span, + kind: StmtKind::Let { + remainder_scope: remainder_extent, + init_scope: cx.tcx.region_maps.node_extent(id), + pattern: pattern, + initializer: local.init.to_ref(), + }, + }))); } } } diff --git a/src/librustc_trans/trans/mir/block.rs b/src/librustc_trans/trans/mir/block.rs index 29479b030c6..a9fee18ded8 100644 --- a/src/librustc_trans/trans/mir/block.rs +++ b/src/librustc_trans/trans/mir/block.rs @@ -278,7 +278,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { self.set_operand_dropped(bcx, op); }); landingpad.at_start(|bcx| for op in args { - self.set_operand_dropped(bcx, op); + self.set_operand_dropped(bcx, op); }); }, (false, _, &None) => { diff --git a/src/librustc_trans/trans/mir/rvalue.rs b/src/librustc_trans/trans/mir/rvalue.rs index 3911a29f034..541df43b49b 100644 --- a/src/librustc_trans/trans/mir/rvalue.rs +++ b/src/librustc_trans/trans/mir/rvalue.rs @@ -43,9 +43,9 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { match *rvalue { mir::Rvalue::Use(ref operand) => { + let tr_operand = self.trans_operand(&bcx, operand); // FIXME: consider not copying constants through stack. (fixable by translating // constants into OperandValue::Ref, why don’t we do that yet if we don’t?) - let tr_operand = self.trans_operand(&bcx, operand); self.store_operand(&bcx, dest.llval, tr_operand); self.set_operand_dropped(&bcx, operand); bcx @@ -563,6 +563,7 @@ pub fn rvalue_creates_operand<'tcx>(rvalue: &mir::Rvalue<'tcx>) -> bool { } // (*) this is only true if the type is suitable - // (**) we need to zero-out the old value before moving, so we are restricted to either - // ensuring all users of `Use` set it themselves or not allowing to “create” operand for it. + // (**) we need to zero-out the source operand after moving, so we are restricted to either + // ensuring all users of `Use` zero it out themselves or not allowing to “create” operand for + // it. } |
