Skip to content

Commit d1a1239

Browse files
committed
Nits and cleanups
1 parent b7f53b8 commit d1a1239

File tree

4 files changed

+35
-43
lines changed

4 files changed

+35
-43
lines changed

src/librustc_mir/build/block.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,11 @@ impl<'a,'tcx> Builder<'a,'tcx> {
5555
let_extent_stack.push(remainder_scope);
5656
unpack!(block = this.in_scope(init_scope, block, move |this| {
5757
// FIXME #30046 ^~~~
58-
match initializer {
59-
Some(initializer) => {
60-
this.expr_into_pattern(block,
61-
remainder_scope,
62-
pattern,
63-
initializer)
64-
}
65-
None => {
66-
this.declare_bindings(remainder_scope, &pattern);
67-
block.unit()
68-
}
58+
if let Some(init) = initializer {
59+
this.expr_into_pattern(block, remainder_scope, pattern, init)
60+
} else {
61+
this.declare_bindings(remainder_scope, &pattern);
62+
block.unit()
6963
}
7064
}));
7165
}

src/librustc_mir/hair/cx/block.rs

+25-28
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Block {
2121
fn make_mirror<'a>(self, cx: &mut Cx<'a, 'tcx>) -> Block<'tcx> {
2222
// We have to eagerly translate the "spine" of the statements
2323
// in order to get the lexical scoping correctly.
24-
let stmts = mirror_stmts(cx, self.id, self.stmts.iter().enumerate());
24+
let stmts = mirror_stmts(cx, self.id, &*self.stmts);
2525
Block {
2626
extent: cx.tcx.region_maps.node_extent(self.id),
2727
span: self.span,
@@ -31,14 +31,13 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Block {
3131
}
3232
}
3333

34-
fn mirror_stmts<'a,'tcx:'a,STMTS>(cx: &mut Cx<'a,'tcx>,
35-
block_id: ast::NodeId,
36-
mut stmts: STMTS)
37-
-> Vec<StmtRef<'tcx>>
38-
where STMTS: Iterator<Item=(usize, &'tcx hir::Stmt)>
34+
fn mirror_stmts<'a,'tcx:'a>(cx: &mut Cx<'a,'tcx>,
35+
block_id: ast::NodeId,
36+
stmts: &'tcx [hir::Stmt])
37+
-> Vec<StmtRef<'tcx>>
3938
{
4039
let mut result = vec![];
41-
while let Some((index, stmt)) = stmts.next() {
40+
for (index, stmt) in stmts.iter().enumerate() {
4241
match stmt.node {
4342
hir::StmtExpr(ref expr, id) | hir::StmtSemi(ref expr, id) =>
4443
result.push(StmtRef::Mirror(Box::new(Stmt {
@@ -48,28 +47,26 @@ fn mirror_stmts<'a,'tcx:'a,STMTS>(cx: &mut Cx<'a,'tcx>,
4847
expr: expr.to_ref()
4948
}
5049
}))),
51-
hir::StmtDecl(ref decl, id) => {
52-
match decl.node {
53-
hir::DeclItem(..) => { /* ignore for purposes of the MIR */ }
54-
hir::DeclLocal(ref local) => {
55-
let remainder_extent = CodeExtentData::Remainder(BlockRemainder {
56-
block: block_id,
57-
first_statement_index: index as u32,
58-
});
59-
let remainder_extent =
60-
cx.tcx.region_maps.lookup_code_extent(remainder_extent);
50+
hir::StmtDecl(ref decl, id) => match decl.node {
51+
hir::DeclItem(..) => { /* ignore for purposes of the MIR */ }
52+
hir::DeclLocal(ref local) => {
53+
let remainder_extent = CodeExtentData::Remainder(BlockRemainder {
54+
block: block_id,
55+
first_statement_index: index as u32,
56+
});
57+
let remainder_extent =
58+
cx.tcx.region_maps.lookup_code_extent(remainder_extent);
6159

62-
let pattern = cx.irrefutable_pat(&local.pat);
63-
result.push(StmtRef::Mirror(Box::new(Stmt {
64-
span: stmt.span,
65-
kind: StmtKind::Let {
66-
remainder_scope: remainder_extent,
67-
init_scope: cx.tcx.region_maps.node_extent(id),
68-
pattern: pattern,
69-
initializer: local.init.to_ref(),
70-
},
71-
})));
72-
}
60+
let pattern = cx.irrefutable_pat(&local.pat);
61+
result.push(StmtRef::Mirror(Box::new(Stmt {
62+
span: stmt.span,
63+
kind: StmtKind::Let {
64+
remainder_scope: remainder_extent,
65+
init_scope: cx.tcx.region_maps.node_extent(id),
66+
pattern: pattern,
67+
initializer: local.init.to_ref(),
68+
},
69+
})));
7370
}
7471
}
7572
}

src/librustc_trans/trans/mir/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
278278
self.set_operand_dropped(bcx, op);
279279
});
280280
landingpad.at_start(|bcx| for op in args {
281-
self.set_operand_dropped(bcx, op);
281+
self.set_operand_dropped(bcx, op);
282282
});
283283
},
284284
(false, _, &None) => {

src/librustc_trans/trans/mir/rvalue.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
4343

4444
match *rvalue {
4545
mir::Rvalue::Use(ref operand) => {
46+
let tr_operand = self.trans_operand(&bcx, operand);
4647
// FIXME: consider not copying constants through stack. (fixable by translating
4748
// constants into OperandValue::Ref, why don’t we do that yet if we don’t?)
48-
let tr_operand = self.trans_operand(&bcx, operand);
4949
self.store_operand(&bcx, dest.llval, tr_operand);
5050
self.set_operand_dropped(&bcx, operand);
5151
bcx
@@ -563,6 +563,7 @@ pub fn rvalue_creates_operand<'tcx>(rvalue: &mir::Rvalue<'tcx>) -> bool {
563563
}
564564

565565
// (*) this is only true if the type is suitable
566-
// (**) we need to zero-out the old value before moving, so we are restricted to either
567-
// ensuring all users of `Use` set it themselves or not allowing to “create” operand for it.
566+
// (**) we need to zero-out the source operand after moving, so we are restricted to either
567+
// ensuring all users of `Use` zero it out themselves or not allowing to “create” operand for
568+
// it.
568569
}

0 commit comments

Comments
 (0)