Skip to content

Commit d5219a7

Browse files
committed
Remove a clone in mir/transform/add_validation.
1 parent fe29a4c commit d5219a7

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/librustc_mir/transform/add_validation.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,13 @@ impl MirPass for AddValidation {
196196
return;
197197
}
198198
let restricted_validation = emit_validate == 1 && fn_contains_unsafe(tcx, src);
199-
let local_decls = mir.local_decls.clone(); // FIXME: Find a way to get rid of this clone.
199+
let (span, arg_count) = (mir.span, mir.arg_count);
200+
let (basic_blocks, local_decls) = mir.basic_blocks_and_local_decls_mut();
200201

201202
// Convert a place to a validation operand.
202203
let place_to_operand = |place: Place<'tcx>| -> ValidationOperand<'tcx, Place<'tcx>> {
203-
let (re, mutbl) = place_context(&place, &local_decls, tcx);
204-
let ty = place.ty(&local_decls, tcx).to_ty(tcx);
204+
let (re, mutbl) = place_context(&place, local_decls, tcx);
205+
let ty = place.ty(local_decls, tcx).to_ty(tcx);
205206
ValidationOperand { place, ty, re, mutbl }
206207
};
207208

@@ -232,20 +233,20 @@ impl MirPass for AddValidation {
232233
{
233234
let source_info = SourceInfo {
234235
scope: OUTERMOST_SOURCE_SCOPE,
235-
span: mir.span, // FIXME: Consider using just the span covering the function
236-
// argument declaration.
236+
span: span, // FIXME: Consider using just the span covering the function
237+
// argument declaration.
237238
};
238239
// Gather all arguments, skip return value.
239-
let operands = mir.local_decls.iter_enumerated().skip(1).take(mir.arg_count)
240+
let operands = local_decls.iter_enumerated().skip(1).take(arg_count)
240241
.map(|(local, _)| place_to_operand(Place::Local(local))).collect();
241-
emit_acquire(&mut mir.basic_blocks_mut()[START_BLOCK], source_info, operands);
242+
emit_acquire(&mut basic_blocks[START_BLOCK], source_info, operands);
242243
}
243244

244245
// PART 2
245246
// Add ReleaseValid/AcquireValid around function call terminators. We don't use a visitor
246247
// because we need to access the block that a Call jumps to.
247248
let mut returns : Vec<(SourceInfo, Place<'tcx>, BasicBlock)> = Vec::new();
248-
for block_data in mir.basic_blocks_mut() {
249+
for block_data in basic_blocks.iter_mut() {
249250
match block_data.terminator {
250251
Some(Terminator { kind: TerminatorKind::Call { ref args, ref destination, .. },
251252
source_info }) => {
@@ -298,7 +299,7 @@ impl MirPass for AddValidation {
298299
// Now we go over the returns we collected to acquire the return values.
299300
for (source_info, dest_place, dest_block) in returns {
300301
emit_acquire(
301-
&mut mir.basic_blocks_mut()[dest_block],
302+
&mut basic_blocks[dest_block],
302303
source_info,
303304
vec![place_to_operand(dest_place)]
304305
);
@@ -312,7 +313,7 @@ impl MirPass for AddValidation {
312313
// PART 3
313314
// Add ReleaseValid/AcquireValid around Ref and Cast. Again an iterator does not seem very
314315
// suited as we need to add new statements before and after each Ref.
315-
for block_data in mir.basic_blocks_mut() {
316+
for block_data in basic_blocks {
316317
// We want to insert statements around Ref commands as we iterate. To this end, we
317318
// iterate backwards using indices.
318319
for i in (0..block_data.statements.len()).rev() {

0 commit comments

Comments
 (0)