Skip to content

Commit fe877bd

Browse files
committed
Format code
1 parent 08f4aaf commit fe877bd

File tree

8 files changed

+207
-85
lines changed

8 files changed

+207
-85
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prusti-interface/src/environment/mir_body/patch/compiler.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ impl<'tcx> MirPatch<'tcx> {
134134
Some(index) => self.new_blocks[index].statements.len(),
135135
None => body[bb].statements.len(),
136136
};
137-
Location { block: bb, statement_index: offset }
137+
Location {
138+
block: bb,
139+
statement_index: offset,
140+
}
138141
}
139142

140143
pub fn new_internal_with_info(
@@ -224,12 +227,19 @@ impl<'tcx> MirPatch<'tcx> {
224227
delta = 0;
225228
last_bb = loc.block;
226229
}
227-
debug!("MirPatch: adding statement {:?} at loc {:?}+{}", stmt, loc, delta);
230+
debug!(
231+
"MirPatch: adding statement {:?} at loc {:?}+{}",
232+
stmt, loc, delta
233+
);
228234
loc.statement_index += delta;
229235
let source_info = Self::source_info_for_index(&body[loc.block], loc);
230-
body[loc.block]
231-
.statements
232-
.insert(loc.statement_index, Statement { source_info, kind: stmt });
236+
body[loc.block].statements.insert(
237+
loc.statement_index,
238+
Statement {
239+
source_info,
240+
kind: stmt,
241+
},
242+
);
233243
delta += 1;
234244
}
235245
}
@@ -248,4 +258,4 @@ impl<'tcx> MirPatch<'tcx> {
248258
};
249259
Self::source_info_for_index(data, loc)
250260
}
251-
}
261+
}

prusti-viper/src/encoder/mir/procedures/encoder/elaborate_drops/mir_dataflow.rs

Lines changed: 94 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use log::debug;
1515
use prusti_interface::environment::mir_body::patch::MirPatch;
1616
use prusti_rustc_interface::{
1717
abi::{FieldIdx, VariantIdx, FIRST_VARIANT},
18-
dataflow::elaborate_drops::{DropFlagState, DropFlagMode, DropStyle, Unwind},
18+
dataflow::elaborate_drops::{DropFlagMode, DropFlagState, DropStyle, Unwind},
1919
hir,
2020
hir::lang_items::LangItem,
2121
index::Idx,
@@ -25,8 +25,8 @@ use prusti_rustc_interface::{
2525
ty::{self, subst::SubstsRef, util::IntTypeExt, Ty, TyCtxt},
2626
},
2727
};
28-
use tracing::instrument;
2928
use std::{fmt, iter};
29+
use tracing::instrument;
3030

3131
trait UnwindPublic {
3232
fn is_cleanup(self) -> bool;
@@ -153,7 +153,15 @@ pub fn elaborate_drop<'b, 'tcx, D>(
153153
D: DropElaborator<'b, 'tcx>,
154154
'tcx: 'b,
155155
{
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)
157165
}
158166

159167
impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D>
@@ -299,18 +307,27 @@ where
299307
fields: &[(Place<'tcx>, Option<D::Path>)],
300308
) -> Vec<BasicBlock> {
301309
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+
)
306320
.collect()
307321
}
308322

309323
fn drop_ladder_bottom(&mut self) -> (BasicBlock, Unwind) {
310324
// Clear the "master" drop flag at the end. This is needed
311325
// because the "master" drop protects the ADT's discriminant,
312326
// 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+
)
314331
}
315332

316333
/// Creates a full drop ladder, consisting of 2 connected half-drop-ladders
@@ -340,7 +357,8 @@ where
340357

341358
let mut fields = fields;
342359
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())
344362
});
345363

346364
debug!("drop_ladder - fields needing drop: {:?}", fields);
@@ -355,7 +373,10 @@ where
355373

356374
let normal_ladder = self.drop_halfladder(&unwind_ladder, succ, &fields);
357375

358-
(*normal_ladder.last().unwrap(), *unwind_ladder.last().unwrap())
376+
(
377+
*normal_ladder.last().unwrap(),
378+
*unwind_ladder.last().unwrap(),
379+
)
359380
}
360381

361382
fn open_drop_for_tuple(&mut self, tys: &[Ty<'tcx>]) -> BasicBlock {
@@ -385,16 +406,23 @@ where
385406
let nonnull_ty = unique_variant.fields[FieldIdx::from_u32(0)].ty(self.tcx(), substs);
386407
let ptr_ty = self.tcx().mk_imm_ptr(substs[0].expect_ty());
387408

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);
391418
let interior = self.tcx().mk_place_deref(ptr_place);
392419

393420
let interior_path = self.elaborator.deref_subpath(self.path);
394421

395422
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));
398426

399427
self.drop_subpath(interior, interior_path, succ, unwind_succ)
400428
}
@@ -455,8 +483,11 @@ where
455483
) -> (BasicBlock, Unwind) {
456484
let mut values = Vec::with_capacity(adt.variants().len());
457485
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+
};
460491

461492
let mut have_otherwise_with_drop_glue = false;
462493
let mut have_otherwise = false;
@@ -518,12 +549,18 @@ where
518549
} else if !have_otherwise_with_drop_glue {
519550
normal_blocks.push(self.goto_block(succ, unwind));
520551
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));
522556
}
523557
} else {
524558
normal_blocks.push(self.drop_block(succ, unwind));
525559
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));
527564
}
528565
}
529566

@@ -584,8 +621,13 @@ where
584621
let drop_fn = tcx.associated_item_def_ids(drop_trait)[0];
585622
let ty = self.place_ty(self.place);
586623

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+
);
589631
let ref_place = self.new_temp(ref_ty);
590632
let unit_temp = Place::from(self.new_temp(tcx.mk_unit()));
591633

@@ -594,7 +636,9 @@ where
594636
Place::from(ref_place),
595637
Rvalue::Ref(
596638
tcx.lifetimes.re_erased,
597-
BorrowKind::Mut { allow_two_phase_borrow: false },
639+
BorrowKind::Mut {
640+
allow_two_phase_borrow: false,
641+
},
598642
self.place,
599643
),
600644
)],
@@ -643,7 +687,10 @@ where
643687
let move_ = |place: Place<'tcx>| Operand::Move(place);
644688
let tcx = self.tcx();
645689

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+
});
647694
let ptr = Place::from(self.new_temp(ptr_ty));
648695
let can_go = Place::from(self.new_temp(tcx.types.bool));
649696
let one = self.constant_usize(1);
@@ -671,7 +718,10 @@ where
671718
let loop_block = BasicBlockData {
672719
statements: vec![self.assign(
673720
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+
),
675725
)],
676726
is_cleanup: unwind.is_cleanup(),
677727
terminator: Some(Terminator {
@@ -768,8 +818,9 @@ where
768818
let len = self.new_temp(tcx.types.usize);
769819
let cur = self.new_temp(tcx.types.usize);
770820

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));
773824

774825
let loop_block = self.drop_loop(self.succ, cur, len, ety, unwind);
775826

@@ -860,8 +911,12 @@ where
860911
return succ;
861912
}
862913
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);
865920
block
866921
}
867922

@@ -926,8 +981,12 @@ where
926981
}; // FIXME(#43234)
927982
let free_block = self.new_block(unwind, call);
928983

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);
931990
free_block
932991
}
933992

@@ -977,7 +1036,10 @@ where
9771036
fn new_block(&mut self, unwind: Unwind, k: TerminatorKind<'tcx>) -> BasicBlock {
9781037
self.elaborator.patch().new_block(BasicBlockData {
9791038
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+
}),
9811043
is_cleanup: unwind.is_cleanup(),
9821044
})
9831045
}
@@ -1000,4 +1062,4 @@ where
10001062
kind: StatementKind::Assign(Box::new((lhs, rhs))),
10011063
}
10021064
}
1003-
}
1065+
}

0 commit comments

Comments
 (0)