diff --git a/src/librustc/mir/repr.rs b/src/librustc/mir/repr.rs index d5d8da248e081..0959bb078ed86 100644 --- a/src/librustc/mir/repr.rs +++ b/src/librustc/mir/repr.rs @@ -13,6 +13,7 @@ use middle::def_id::DefId; use middle::subst::Substs; use middle::ty::{AdtDef, ClosureSubsts, FnOutput, Region, Ty}; use rustc_back::slice; +use rustc_data_structures::tuple_slice::TupleSlice; use rustc_front::hir::InlineAsm; use syntax::ast::Name; use syntax::codemap::Span; @@ -206,7 +207,7 @@ pub enum Terminator<'tcx> { /// jump to branch 0 if this lvalue evaluates to true If { cond: Operand<'tcx>, - targets: [BasicBlock; 2], + targets: (BasicBlock, BasicBlock), }, /// lvalue evaluates to some enum; jump depending on the branch @@ -254,7 +255,7 @@ pub enum Terminator<'tcx> { /// unwinding. Call { data: CallData<'tcx>, - targets: [BasicBlock; 2], + targets: (BasicBlock, BasicBlock), }, } @@ -264,12 +265,12 @@ impl<'tcx> Terminator<'tcx> { match *self { Goto { target: ref b } => slice::ref_slice(b), Panic { target: ref b } => slice::ref_slice(b), - If { cond: _, targets: ref b } => b, + If { cond: _, targets: ref b } => b.as_slice(), Switch { targets: ref b, .. } => b, SwitchInt { targets: ref b, .. } => b, Diverge => &[], Return => &[], - Call { data: _, targets: ref b } => b, + Call { data: _, targets: ref b } => b.as_slice(), } } @@ -278,12 +279,12 @@ impl<'tcx> Terminator<'tcx> { match *self { Goto { target: ref mut b } => slice::mut_ref_slice(b), Panic { target: ref mut b } => slice::mut_ref_slice(b), - If { cond: _, targets: ref mut b } => b, + If { cond: _, targets: ref mut b } => b.as_mut_slice(), Switch { targets: ref mut b, .. } => b, SwitchInt { targets: ref mut b, .. } => b, Diverge => &mut [], Return => &mut [], - Call { data: _, targets: ref mut b } => b, + Call { data: _, targets: ref mut b } => b.as_mut_slice(), } } } diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index ac4f54b4b4962..7547b804e6553 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -10,6 +10,7 @@ use middle::ty::Region; use mir::repr::*; +use rustc_data_structures::tuple_slice::TupleSlice; pub trait Visitor<'tcx> { // Override these, and call `self.super_xxx` to revert back to the @@ -97,7 +98,7 @@ pub trait Visitor<'tcx> { Terminator::If { ref cond, ref targets } => { self.visit_operand(cond); - for &target in &targets[..] { + for &target in targets.as_slice() { self.visit_branch(block, target); } } @@ -126,7 +127,7 @@ pub trait Visitor<'tcx> { for arg in &data.args { self.visit_operand(arg); } - for &target in &targets[..] { + for &target in targets.as_slice() { self.visit_branch(block, target); } } diff --git a/src/librustc_mir/build/expr/as_lvalue.rs b/src/librustc_mir/build/expr/as_lvalue.rs index 697799efd143b..1c96addcea0d9 100644 --- a/src/librustc_mir/build/expr/as_lvalue.rs +++ b/src/librustc_mir/build/expr/as_lvalue.rs @@ -69,7 +69,7 @@ impl<'a,'tcx> Builder<'a,'tcx> { this.cfg.terminate(block, Terminator::If { cond: Operand::Consume(lt), - targets: [success, failure], + targets: (success, failure), }); this.panic(failure); success.and(slice.index(idx)) diff --git a/src/librustc_mir/build/expr/into.rs b/src/librustc_mir/build/expr/into.rs index ac3e87e6b629a..802c55ce7647a 100644 --- a/src/librustc_mir/build/expr/into.rs +++ b/src/librustc_mir/build/expr/into.rs @@ -53,7 +53,7 @@ impl<'a,'tcx> Builder<'a,'tcx> { let mut else_block = this.cfg.start_new_block(); this.cfg.terminate(block, Terminator::If { cond: operand, - targets: [then_block, else_block] + targets: (then_block, else_block) }); unpack!(then_block = this.into(destination, then_block, then_expr)); @@ -84,15 +84,15 @@ impl<'a,'tcx> Builder<'a,'tcx> { let lhs = unpack!(block = this.as_operand(block, lhs)); let blocks = match op { - LogicalOp::And => [else_block, false_block], - LogicalOp::Or => [true_block, else_block], + LogicalOp::And => (else_block, false_block), + LogicalOp::Or => (true_block, else_block), }; this.cfg.terminate(block, Terminator::If { cond: lhs, targets: blocks }); let rhs = unpack!(else_block = this.as_operand(else_block, rhs)); this.cfg.terminate(else_block, Terminator::If { cond: rhs, - targets: [true_block, false_block] + targets: (true_block, false_block) }); this.cfg.push_assign_constant( @@ -149,7 +149,7 @@ impl<'a,'tcx> Builder<'a,'tcx> { this.cfg.terminate(loop_block_end, Terminator::If { cond: cond, - targets: [body_block, exit_block] + targets: (body_block, exit_block) }); } else { body_block = loop_block; @@ -225,7 +225,7 @@ impl<'a,'tcx> Builder<'a,'tcx> { func: fun, args: args, }, - targets: [success, panic], + targets: (success, panic), }); success.unit() } diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 0248f2fc49adb..f8385d5817018 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -555,7 +555,7 @@ impl<'a,'tcx> Builder<'a,'tcx> { let cond = unpack!(block = self.as_operand(block, guard)); let otherwise = self.cfg.start_new_block(); self.cfg.terminate(block, Terminator::If { cond: cond, - targets: [arm_block, otherwise]}); + targets: (arm_block, otherwise)}); Some(otherwise) } else { self.cfg.terminate(block, Terminator::Goto { target: arm_block }); diff --git a/src/librustc_mir/build/matches/test.rs b/src/librustc_mir/build/matches/test.rs index 968514cd05c13..7b329fc4d52c3 100644 --- a/src/librustc_mir/build/matches/test.rs +++ b/src/librustc_mir/build/matches/test.rs @@ -232,7 +232,7 @@ impl<'a,'tcx> Builder<'a,'tcx> { self.cfg.start_new_block()]; self.cfg.terminate(block, Terminator::If { cond: Operand::Consume(result), - targets: [target_blocks[0], target_blocks[1]] + targets: (target_blocks[0], target_blocks[1]) }); target_blocks @@ -252,7 +252,7 @@ impl<'a,'tcx> Builder<'a,'tcx> { let bool_ty = self.hir.bool_ty(); let eq_result = self.temp(bool_ty); let func = self.item_ref_operand(span, item_ref); - let call_blocks = [self.cfg.start_new_block(), self.diverge_cleanup()]; + let call_blocks = (self.cfg.start_new_block(), self.diverge_cleanup()); self.cfg.terminate(block, Terminator::Call { data: CallData { @@ -264,10 +264,10 @@ impl<'a,'tcx> Builder<'a,'tcx> { }); // check the result - self.cfg.terminate(call_blocks[0], + self.cfg.terminate(call_blocks.0, Terminator::If { cond: Operand::Consume(eq_result), - targets: [target_blocks[0], target_blocks[1]], + targets: (target_blocks[0], target_blocks[1]), }); target_blocks diff --git a/src/librustc_mir/transform/simplify_cfg.rs b/src/librustc_mir/transform/simplify_cfg.rs index 558276a13a8b8..d0c0afc80a657 100644 --- a/src/librustc_mir/transform/simplify_cfg.rs +++ b/src/librustc_mir/transform/simplify_cfg.rs @@ -96,9 +96,9 @@ impl SimplifyCfg { mem::swap(&mut terminator, &mut mir.basic_block_data_mut(bb).terminator); mir.basic_block_data_mut(bb).terminator = match terminator { - Terminator::If { ref targets, .. } if targets[0] == targets[1] => { + Terminator::If { ref targets, .. } if targets.0 == targets.1 => { changed = true; - Terminator::Goto { target: targets[0] } + Terminator::Goto { target: targets.0 } } Terminator::If { ref targets, cond: Operand::Constant(Constant { literal: Literal::Value { @@ -106,8 +106,11 @@ impl SimplifyCfg { }, .. }) } => { changed = true; - let target_idx = if cond { 0 } else { 1 }; - Terminator::Goto { target: targets[target_idx] } + if cond { + Terminator::Goto { target: targets.0 } + } else { + Terminator::Goto { target: targets.1 } + } } Terminator::SwitchInt { ref targets, .. } if targets.len() == 1 => { Terminator::Goto { target: targets[0] } diff --git a/src/librustc_trans/trans/mir/block.rs b/src/librustc_trans/trans/mir/block.rs index 3ce08fb2f60ef..b58b51f5a2b23 100644 --- a/src/librustc_trans/trans/mir/block.rs +++ b/src/librustc_trans/trans/mir/block.rs @@ -39,7 +39,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> { unimplemented!() } - mir::Terminator::If { ref cond, targets: [true_bb, false_bb] } => { + mir::Terminator::If { ref cond, targets: (true_bb, false_bb) } => { let cond = self.trans_operand(bcx, cond); let lltrue = self.llblock(true_bb); let llfalse = self.llblock(false_bb);