Skip to content

Commit 8f1fc86

Browse files
authored
Auto merge of #37489 - nagisa:unnecessary-clone, r=eddyb
Do not clone Mir unnecessarily r? @eddyb
2 parents bfc9b29 + 8ec0b3a commit 8f1fc86

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/librustc/mir/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ macro_rules! newtype_index {
6363
}
6464

6565
/// Lowered representation of a single function.
66-
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
66+
// Do not implement clone for Mir, its easy to do so accidently and its kind of expensive.
67+
#[derive(RustcEncodable, RustcDecodable, Debug)]
6768
pub struct Mir<'tcx> {
6869
/// List of basic blocks. References to basic block use a newtyped index type `BasicBlock`
6970
/// that indexes into this vector.

src/librustc_trans/mir/block.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ use super::analyze::CleanupKind;
3737
use super::constant::Const;
3838
use super::lvalue::{LvalueRef};
3939
use super::operand::OperandRef;
40-
use super::operand::OperandValue::*;
40+
use super::operand::OperandValue::{Pair, Ref, Immediate};
41+
42+
use std::cell::Ref as CellRef;
4143

4244
impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
4345
pub fn trans_block(&mut self, bb: mir::BasicBlock) {
4446
let mut bcx = self.bcx(bb);
45-
let mir = self.mir.clone();
46-
let data = &mir[bb];
47+
let data = &CellRef::clone(&self.mir)[bb];
4748

4849
debug!("trans_block({:?}={:?})", bb, data);
4950

@@ -228,7 +229,7 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
228229
}
229230

230231
mir::TerminatorKind::Drop { ref location, target, unwind } => {
231-
let ty = location.ty(&mir, bcx.tcx()).to_ty(bcx.tcx());
232+
let ty = location.ty(&self.mir, bcx.tcx()).to_ty(bcx.tcx());
232233
let ty = bcx.monomorphize(&ty);
233234

234235
// Double check for necessity to drop

0 commit comments

Comments
 (0)