@@ -15,7 +15,7 @@ use log::debug;
15
15
use prusti_interface:: environment:: mir_body:: patch:: MirPatch ;
16
16
use prusti_rustc_interface:: {
17
17
abi:: { FieldIdx , VariantIdx , FIRST_VARIANT } ,
18
- dataflow:: elaborate_drops:: { DropFlagState , DropFlagMode , DropStyle , Unwind } ,
18
+ dataflow:: elaborate_drops:: { DropFlagMode , DropFlagState , DropStyle , Unwind } ,
19
19
hir,
20
20
hir:: lang_items:: LangItem ,
21
21
index:: Idx ,
@@ -25,8 +25,8 @@ use prusti_rustc_interface::{
25
25
ty:: { self , subst:: SubstsRef , util:: IntTypeExt , Ty , TyCtxt } ,
26
26
} ,
27
27
} ;
28
- use tracing:: instrument;
29
28
use std:: { fmt, iter} ;
29
+ use tracing:: instrument;
30
30
31
31
trait UnwindPublic {
32
32
fn is_cleanup ( self ) -> bool ;
@@ -153,7 +153,15 @@ pub fn elaborate_drop<'b, 'tcx, D>(
153
153
D : DropElaborator < ' b , ' tcx > ,
154
154
' tcx : ' b ,
155
155
{
156
- DropCtxt { elaborator, source_info, place, path, succ, unwind } . elaborate_drop ( bb)
156
+ DropCtxt {
157
+ elaborator,
158
+ source_info,
159
+ place,
160
+ path,
161
+ succ,
162
+ unwind,
163
+ }
164
+ . elaborate_drop ( bb)
157
165
}
158
166
159
167
impl < ' l , ' b , ' tcx , D > DropCtxt < ' l , ' b , ' tcx , D >
@@ -299,18 +307,27 @@ where
299
307
fields : & [ ( Place < ' tcx > , Option < D :: Path > ) ] ,
300
308
) -> Vec < BasicBlock > {
301
309
iter:: once ( succ)
302
- . chain ( fields. iter ( ) . rev ( ) . zip ( unwind_ladder) . map ( |( & ( place, path) , & unwind_succ) | {
303
- succ = self . drop_subpath ( place, path, succ, unwind_succ) ;
304
- succ
305
- } ) )
310
+ . chain (
311
+ fields
312
+ . iter ( )
313
+ . rev ( )
314
+ . zip ( unwind_ladder)
315
+ . map ( |( & ( place, path) , & unwind_succ) | {
316
+ succ = self . drop_subpath ( place, path, succ, unwind_succ) ;
317
+ succ
318
+ } ) ,
319
+ )
306
320
. collect ( )
307
321
}
308
322
309
323
fn drop_ladder_bottom ( & mut self ) -> ( BasicBlock , Unwind ) {
310
324
// Clear the "master" drop flag at the end. This is needed
311
325
// because the "master" drop protects the ADT's discriminant,
312
326
// which is invalidated after the ADT is dropped.
313
- ( self . drop_flag_reset_block ( DropFlagMode :: Shallow , self . succ , self . unwind ) , self . unwind )
327
+ (
328
+ self . drop_flag_reset_block ( DropFlagMode :: Shallow , self . succ , self . unwind ) ,
329
+ self . unwind ,
330
+ )
314
331
}
315
332
316
333
/// Creates a full drop ladder, consisting of 2 connected half-drop-ladders
@@ -340,7 +357,8 @@ where
340
357
341
358
let mut fields = fields;
342
359
fields. retain ( |& ( place, _) | {
343
- self . place_ty ( place) . needs_drop ( self . tcx ( ) , self . elaborator . param_env ( ) )
360
+ self . place_ty ( place)
361
+ . needs_drop ( self . tcx ( ) , self . elaborator . param_env ( ) )
344
362
} ) ;
345
363
346
364
debug ! ( "drop_ladder - fields needing drop: {:?}" , fields) ;
@@ -355,7 +373,10 @@ where
355
373
356
374
let normal_ladder = self . drop_halfladder ( & unwind_ladder, succ, & fields) ;
357
375
358
- ( * normal_ladder. last ( ) . unwrap ( ) , * unwind_ladder. last ( ) . unwrap ( ) )
376
+ (
377
+ * normal_ladder. last ( ) . unwrap ( ) ,
378
+ * unwind_ladder. last ( ) . unwrap ( ) ,
379
+ )
359
380
}
360
381
361
382
fn open_drop_for_tuple ( & mut self , tys : & [ Ty < ' tcx > ] ) -> BasicBlock {
@@ -385,16 +406,23 @@ where
385
406
let nonnull_ty = unique_variant. fields [ FieldIdx :: from_u32 ( 0 ) ] . ty ( self . tcx ( ) , substs) ;
386
407
let ptr_ty = self . tcx ( ) . mk_imm_ptr ( substs[ 0 ] . expect_ty ( ) ) ;
387
408
388
- let unique_place = self . tcx ( ) . mk_place_field ( self . place , FieldIdx :: new ( 0 ) , unique_ty) ;
389
- let nonnull_place = self . tcx ( ) . mk_place_field ( unique_place, FieldIdx :: new ( 0 ) , nonnull_ty) ;
390
- let ptr_place = self . tcx ( ) . mk_place_field ( nonnull_place, FieldIdx :: new ( 0 ) , ptr_ty) ;
409
+ let unique_place = self
410
+ . tcx ( )
411
+ . mk_place_field ( self . place , FieldIdx :: new ( 0 ) , unique_ty) ;
412
+ let nonnull_place = self
413
+ . tcx ( )
414
+ . mk_place_field ( unique_place, FieldIdx :: new ( 0 ) , nonnull_ty) ;
415
+ let ptr_place = self
416
+ . tcx ( )
417
+ . mk_place_field ( nonnull_place, FieldIdx :: new ( 0 ) , ptr_ty) ;
391
418
let interior = self . tcx ( ) . mk_place_deref ( ptr_place) ;
392
419
393
420
let interior_path = self . elaborator . deref_subpath ( self . path ) ;
394
421
395
422
let succ = self . box_free_block ( adt, substs, self . succ , self . unwind ) ;
396
- let unwind_succ =
397
- self . unwind . map ( |unwind| self . box_free_block ( adt, substs, unwind, Unwind :: InCleanup ) ) ;
423
+ let unwind_succ = self
424
+ . unwind
425
+ . map ( |unwind| self . box_free_block ( adt, substs, unwind, Unwind :: InCleanup ) ) ;
398
426
399
427
self . drop_subpath ( interior, interior_path, succ, unwind_succ)
400
428
}
@@ -455,8 +483,11 @@ where
455
483
) -> ( BasicBlock , Unwind ) {
456
484
let mut values = Vec :: with_capacity ( adt. variants ( ) . len ( ) ) ;
457
485
let mut normal_blocks = Vec :: with_capacity ( adt. variants ( ) . len ( ) ) ;
458
- let mut unwind_blocks =
459
- if unwind. is_cleanup ( ) { None } else { Some ( Vec :: with_capacity ( adt. variants ( ) . len ( ) ) ) } ;
486
+ let mut unwind_blocks = if unwind. is_cleanup ( ) {
487
+ None
488
+ } else {
489
+ Some ( Vec :: with_capacity ( adt. variants ( ) . len ( ) ) )
490
+ } ;
460
491
461
492
let mut have_otherwise_with_drop_glue = false ;
462
493
let mut have_otherwise = false ;
@@ -518,12 +549,18 @@ where
518
549
} else if !have_otherwise_with_drop_glue {
519
550
normal_blocks. push ( self . goto_block ( succ, unwind) ) ;
520
551
if let Unwind :: To ( unwind) = unwind {
521
- unwind_blocks. as_mut ( ) . unwrap ( ) . push ( self . goto_block ( unwind, Unwind :: InCleanup ) ) ;
552
+ unwind_blocks
553
+ . as_mut ( )
554
+ . unwrap ( )
555
+ . push ( self . goto_block ( unwind, Unwind :: InCleanup ) ) ;
522
556
}
523
557
} else {
524
558
normal_blocks. push ( self . drop_block ( succ, unwind) ) ;
525
559
if let Unwind :: To ( unwind) = unwind {
526
- unwind_blocks. as_mut ( ) . unwrap ( ) . push ( self . drop_block ( unwind, Unwind :: InCleanup ) ) ;
560
+ unwind_blocks
561
+ . as_mut ( )
562
+ . unwrap ( )
563
+ . push ( self . drop_block ( unwind, Unwind :: InCleanup ) ) ;
527
564
}
528
565
}
529
566
@@ -584,8 +621,13 @@ where
584
621
let drop_fn = tcx. associated_item_def_ids ( drop_trait) [ 0 ] ;
585
622
let ty = self . place_ty ( self . place ) ;
586
623
587
- let ref_ty =
588
- tcx. mk_ref ( tcx. lifetimes . re_erased , ty:: TypeAndMut { ty, mutbl : hir:: Mutability :: Mut } ) ;
624
+ let ref_ty = tcx. mk_ref (
625
+ tcx. lifetimes . re_erased ,
626
+ ty:: TypeAndMut {
627
+ ty,
628
+ mutbl : hir:: Mutability :: Mut ,
629
+ } ,
630
+ ) ;
589
631
let ref_place = self . new_temp ( ref_ty) ;
590
632
let unit_temp = Place :: from ( self . new_temp ( tcx. mk_unit ( ) ) ) ;
591
633
@@ -594,7 +636,9 @@ where
594
636
Place :: from( ref_place) ,
595
637
Rvalue :: Ref (
596
638
tcx. lifetimes. re_erased,
597
- BorrowKind :: Mut { allow_two_phase_borrow: false } ,
639
+ BorrowKind :: Mut {
640
+ allow_two_phase_borrow: false ,
641
+ } ,
598
642
self . place,
599
643
) ,
600
644
) ] ,
@@ -643,7 +687,10 @@ where
643
687
let move_ = |place : Place < ' tcx > | Operand :: Move ( place) ;
644
688
let tcx = self . tcx ( ) ;
645
689
646
- let ptr_ty = tcx. mk_ptr ( ty:: TypeAndMut { ty : ety, mutbl : hir:: Mutability :: Mut } ) ;
690
+ let ptr_ty = tcx. mk_ptr ( ty:: TypeAndMut {
691
+ ty : ety,
692
+ mutbl : hir:: Mutability :: Mut ,
693
+ } ) ;
647
694
let ptr = Place :: from ( self . new_temp ( ptr_ty) ) ;
648
695
let can_go = Place :: from ( self . new_temp ( tcx. types . bool ) ) ;
649
696
let one = self . constant_usize ( 1 ) ;
@@ -671,7 +718,10 @@ where
671
718
let loop_block = BasicBlockData {
672
719
statements : vec ! [ self . assign(
673
720
can_go,
674
- Rvalue :: BinaryOp ( BinOp :: Eq , Box :: new( ( copy( Place :: from( cur) ) , copy( len. into( ) ) ) ) ) ,
721
+ Rvalue :: BinaryOp (
722
+ BinOp :: Eq ,
723
+ Box :: new( ( copy( Place :: from( cur) ) , copy( len. into( ) ) ) ) ,
724
+ ) ,
675
725
) ] ,
676
726
is_cleanup : unwind. is_cleanup ( ) ,
677
727
terminator : Some ( Terminator {
@@ -768,8 +818,9 @@ where
768
818
let len = self . new_temp ( tcx. types . usize ) ;
769
819
let cur = self . new_temp ( tcx. types . usize ) ;
770
820
771
- let unwind =
772
- self . unwind . map ( |unwind| self . drop_loop ( unwind, cur, len, ety, Unwind :: InCleanup ) ) ;
821
+ let unwind = self
822
+ . unwind
823
+ . map ( |unwind| self . drop_loop ( unwind, cur, len, ety, Unwind :: InCleanup ) ) ;
773
824
774
825
let loop_block = self . drop_loop ( self . succ , cur, len, ety, unwind) ;
775
826
@@ -860,8 +911,12 @@ where
860
911
return succ;
861
912
}
862
913
let block = self . new_block ( unwind, TerminatorKind :: Goto { target : succ } ) ;
863
- let block_start = Location { block, statement_index : 0 } ;
864
- self . elaborator . clear_drop_flag ( block_start, self . path , mode) ;
914
+ let block_start = Location {
915
+ block,
916
+ statement_index : 0 ,
917
+ } ;
918
+ self . elaborator
919
+ . clear_drop_flag ( block_start, self . path , mode) ;
865
920
block
866
921
}
867
922
@@ -926,8 +981,12 @@ where
926
981
} ; // FIXME(#43234)
927
982
let free_block = self . new_block ( unwind, call) ;
928
983
929
- let block_start = Location { block : free_block, statement_index : 0 } ;
930
- self . elaborator . clear_drop_flag ( block_start, self . path , DropFlagMode :: Shallow ) ;
984
+ let block_start = Location {
985
+ block : free_block,
986
+ statement_index : 0 ,
987
+ } ;
988
+ self . elaborator
989
+ . clear_drop_flag ( block_start, self . path , DropFlagMode :: Shallow ) ;
931
990
free_block
932
991
}
933
992
@@ -977,7 +1036,10 @@ where
977
1036
fn new_block ( & mut self , unwind : Unwind , k : TerminatorKind < ' tcx > ) -> BasicBlock {
978
1037
self . elaborator . patch ( ) . new_block ( BasicBlockData {
979
1038
statements : vec ! [ ] ,
980
- terminator : Some ( Terminator { source_info : self . source_info , kind : k } ) ,
1039
+ terminator : Some ( Terminator {
1040
+ source_info : self . source_info ,
1041
+ kind : k,
1042
+ } ) ,
981
1043
is_cleanup : unwind. is_cleanup ( ) ,
982
1044
} )
983
1045
}
@@ -1000,4 +1062,4 @@ where
1000
1062
kind : StatementKind :: Assign ( Box :: new ( ( lhs, rhs) ) ) ,
1001
1063
}
1002
1064
}
1003
- }
1065
+ }
0 commit comments