@@ -196,12 +196,13 @@ impl MirPass for AddValidation {
196
196
return ;
197
197
}
198
198
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 ( ) ;
200
201
201
202
// Convert a place to a validation operand.
202
203
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) ;
205
206
ValidationOperand { place, ty, re, mutbl }
206
207
} ;
207
208
@@ -232,20 +233,20 @@ impl MirPass for AddValidation {
232
233
{
233
234
let source_info = SourceInfo {
234
235
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.
237
238
} ;
238
239
// 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)
240
241
. 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) ;
242
243
}
243
244
244
245
// PART 2
245
246
// Add ReleaseValid/AcquireValid around function call terminators. We don't use a visitor
246
247
// because we need to access the block that a Call jumps to.
247
248
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 ( ) {
249
250
match block_data. terminator {
250
251
Some ( Terminator { kind : TerminatorKind :: Call { ref args, ref destination, .. } ,
251
252
source_info } ) => {
@@ -298,7 +299,7 @@ impl MirPass for AddValidation {
298
299
// Now we go over the returns we collected to acquire the return values.
299
300
for ( source_info, dest_place, dest_block) in returns {
300
301
emit_acquire (
301
- & mut mir . basic_blocks_mut ( ) [ dest_block] ,
302
+ & mut basic_blocks [ dest_block] ,
302
303
source_info,
303
304
vec ! [ place_to_operand( dest_place) ]
304
305
) ;
@@ -312,7 +313,7 @@ impl MirPass for AddValidation {
312
313
// PART 3
313
314
// Add ReleaseValid/AcquireValid around Ref and Cast. Again an iterator does not seem very
314
315
// 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 {
316
317
// We want to insert statements around Ref commands as we iterate. To this end, we
317
318
// iterate backwards using indices.
318
319
for i in ( 0 ..block_data. statements . len ( ) ) . rev ( ) {
0 commit comments