Skip to content

Commit

Permalink
Fix clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
fpoli committed Aug 21, 2023
1 parent 9254172 commit 30d8683
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 61 deletions.
21 changes: 5 additions & 16 deletions analysis/src/domains/reaching_definitions/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ impl<'mir, 'tcx: 'mir> ReachingDefsState<'mir, 'tcx> {
let stmt = &self.mir[location.block].statements[location.statement_index];
if let mir::StatementKind::Assign(box (ref target, _)) = stmt.kind {
if let Some(local) = target.as_local() {
let location_set = self
.reaching_defs
.entry(local)
.or_insert_with(FxHashSet::default);
let location_set = self.reaching_defs.entry(local).or_default();
location_set.clear();
location_set.insert(DefLocation::Assignment(location));
}
Expand All @@ -134,10 +131,7 @@ impl<'mir, 'tcx: 'mir> ReachingDefsState<'mir, 'tcx> {
if let Some(bb) = target {
let mut dest_state = self.clone();
if let Some(local) = destination.as_local() {
let location_set = dest_state
.reaching_defs
.entry(local)
.or_insert_with(FxHashSet::default);
let location_set = dest_state.reaching_defs.entry(local).or_default();
location_set.clear();
location_set.insert(DefLocation::Assignment(location));
}
Expand All @@ -150,10 +144,8 @@ impl<'mir, 'tcx: 'mir> ReachingDefsState<'mir, 'tcx> {
// while keeping all others
if target.is_some() {
if let Some(local) = destination.as_local() {
let location_set = cleanup_state
.reaching_defs
.entry(local)
.or_insert_with(FxHashSet::default);
let location_set =
cleanup_state.reaching_defs.entry(local).or_default();
location_set.insert(DefLocation::Assignment(location));
}
}
Expand Down Expand Up @@ -182,10 +174,7 @@ impl<'mir, 'tcx: 'mir> AbstractState for ReachingDefsState<'mir, 'tcx> {

fn join(&mut self, other: &Self) {
for (local, other_locations) in other.reaching_defs.iter() {
let location_set = self
.reaching_defs
.entry(*local)
.or_insert_with(FxHashSet::default);
let location_set = self.reaching_defs.entry(*local).or_default();
location_set.extend(other_locations);
}
}
Expand Down
4 changes: 1 addition & 3 deletions analysis/src/pointwise_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ impl<'mir, 'tcx: 'mir, S: Serialize> PointwiseState<'mir, 'tcx, S> {
&mut self,
block: mir::BasicBlock,
) -> &mut FxHashMap<mir::BasicBlock, S> {
self.state_after_block
.entry(block)
.or_insert_with(FxHashMap::default)
self.state_after_block.entry(block).or_default()
}

/// Update the state before the `location`.
Expand Down
6 changes: 2 additions & 4 deletions prusti-interface/src/environment/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,15 @@ impl ProcedureLoops {

let mut loop_bodies = FxHashMap::default();
for &(source, target) in back_edges.iter() {
let body = loop_bodies.entry(target).or_insert_with(FxHashSet::default);
let body = loop_bodies.entry(target).or_default();
collect_loop_body(target, source, real_edges, body);
}

let mut enclosing_loop_heads_set: FxHashMap<BasicBlockIndex, FxHashSet<BasicBlockIndex>> =
FxHashMap::default();
for (&loop_head, loop_body) in loop_bodies.iter() {
for &block in loop_body.iter() {
let heads_set = enclosing_loop_heads_set
.entry(block)
.or_insert_with(FxHashSet::default);
let heads_set = enclosing_loop_heads_set.entry(block).or_default();
heads_set.insert(loop_head);
}
}
Expand Down
15 changes: 7 additions & 8 deletions prusti-interface/src/environment/polonius_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,9 @@ pub fn graphviz<'tcx>(
let from_block = from.location.block;
let to = interner.get_point(to_index);
let to_block = to.location.block;
let from_points = blocks.entry(from_block).or_insert_with(FxHashSet::default);
let from_points: &mut FxHashSet<_> = blocks.entry(from_block).or_default();
from_points.insert(from_index);
let to_points = blocks.entry(to_block).or_insert_with(FxHashSet::default);
let to_points: &mut FxHashSet<_> = blocks.entry(to_block).or_default();
to_points.insert(to_index);
if from_block != to_block {
block_edges.insert((from_block, to_block));
Expand Down Expand Up @@ -441,7 +441,7 @@ fn add_fake_facts<'a, 'tcx: 'a>(
let mut outlives_at_point = FxHashMap::default();
for &(region1, region2, point) in all_facts.subset_base.iter() {
if !universal_region.contains(&region1) && !universal_region.contains(&region2) {
let subset_base = outlives_at_point.entry(point).or_insert_with(Vec::new);
let subset_base = outlives_at_point.entry(point).or_default();
subset_base.push((region1, region2));
}
}
Expand Down Expand Up @@ -1174,7 +1174,6 @@ impl<'a, 'tcx: 'a> PoloniusInfo<'a, 'tcx> {
return Ok(None);
};
let (dest, source) = assignment.as_assign().unwrap();
let dest = dest;
let source = source.clone();
let location = self.loan_position[loan];
Ok(Some(LoanPlaces {
Expand Down Expand Up @@ -2197,9 +2196,9 @@ impl AdditionalFacts {
for (region, loan, point) in &zombie_requires.elements {
zombie_requires_map
.entry(*point)
.or_insert_with(BTreeMap::default)
.or_default()
.entry(*region)
.or_insert_with(BTreeSet::new)
.or_default()
.insert(*loan);
}

Expand All @@ -2209,7 +2208,7 @@ impl AdditionalFacts {
for (loan, point) in &zombie_borrow_live_at.elements {
zombie_borrow_live_at_map
.entry(*point)
.or_insert_with(Vec::new)
.or_default()
.push(*loan);
}

Expand All @@ -2219,7 +2218,7 @@ impl AdditionalFacts {
for (loan, point) in &borrow_become_zombie_at.elements {
borrow_become_zombie_at_map
.entry(*point)
.or_insert_with(Vec::new)
.or_default()
.push(*loan);
}

Expand Down
14 changes: 7 additions & 7 deletions prusti-viper/src/encoder/foldunfold/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl EventLog {
perm: vir::Expr,
original_place: vir::Expr,
) {
let entry = self.duplicated_reads.entry(borrow).or_insert_with(Vec::new);
let entry = self.duplicated_reads.entry(borrow).or_default();
entry.push((perm, original_place, self.id_generator));
self.id_generator += 1;
}
Expand Down Expand Up @@ -149,8 +149,11 @@ impl EventLog {
borrow,
result
.iter()
.map(|(a, p, id)| format!("({a}, {p}, {id}), "))
.collect::<String>()
.iter()
.fold(String::new(), |mut output, (a, p, id)| {
let _ = write!(output, "({a}, {p}, {id}), ");
output
})
);
result
.into_iter()
Expand All @@ -161,10 +164,7 @@ impl EventLog {
/// `perm` is an instance of either `PredicateAccessPredicate` or `FieldAccessPredicate`.
pub fn log_convertion_to_read(&mut self, borrow: vir::borrows::Borrow, perm: vir::Expr) {
assert!(perm.get_perm_amount() == vir::PermAmount::Remaining);
let entry = self
.converted_to_read_places
.entry(borrow)
.or_insert_with(Vec::new);
let entry = self.converted_to_read_places.entry(borrow).or_default();
entry.push(perm);
}

Expand Down
7 changes: 5 additions & 2 deletions prusti-viper/src/encoder/foldunfold/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,11 @@ impl<'p, 'v: 'p, 'tcx: 'v> vir::CfgReplacer<PathCtxt<'p>, ActionVec> for FoldUnf
"acc_perms = {}",
acc_perms
.iter()
.map(|(a, p, id)| format!("({a}, {p}, {id}), "))
.collect::<String>()
.iter()
.fold(String::new(), |mut output, (a, p, id)| {
let _ = write!(output, "({a}, {p}, {id}), ");
output
})
);
for (place, perm_amount, _) in acc_perms {
trace!("acc place: {} {}", place, perm_amount);
Expand Down
2 changes: 1 addition & 1 deletion prusti-viper/src/encoder/foldunfold/perm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ where
for perm in self {
res_perms
.entry(perm.get_label().cloned())
.or_insert_with(Vec::new)
.or_default()
.push(perm.clone());
}
res_perms
Expand Down
4 changes: 2 additions & 2 deletions prusti-viper/src/encoder/foldunfold/process_expire_borrows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ impl<'p, 'v: 'p, 'tcx: 'v> FoldUnfold<'p, 'v, 'tcx> {
for perm in &dropped_permissions {
let comment = format!("restored (from log): {perm}");
let key = (predecessor, curr_block_index);
let entry = cfg.edges.entry(key).or_insert_with(Vec::new);
let entry = cfg.edges.entry(key).or_default();
entry.push(vir::Stmt::comment(comment));
}
pctxt
Expand Down Expand Up @@ -228,7 +228,7 @@ impl<'p, 'v: 'p, 'tcx: 'v> FoldUnfold<'p, 'v, 'tcx> {
}
}
let key = (src_index, curr_block_index);
let entry = cfg.edges.entry(key).or_insert_with(Vec::new);
let entry = cfg.edges.entry(key).or_default();
entry.extend(stmts_to_add);
}
}
Expand Down
4 changes: 2 additions & 2 deletions prusti-viper/src/encoder/mir/procedures/encoder/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl<'p, 'v: 'p, 'tcx: 'v> LifetimesEncoder<'tcx> for ProcedureEncoder<'p, 'v, '
)?;
self.reborrow_lifetimes_to_remove_for_block
.entry(target)
.or_insert_with(BTreeSet::new);
.or_default();
let mut values = self
.reborrow_lifetimes_to_remove_for_block
.get(&self.current_basic_block.unwrap())
Expand Down Expand Up @@ -374,7 +374,7 @@ impl<'p, 'v: 'p, 'tcx: 'v> LifetimesEncoder<'tcx> for ProcedureEncoder<'p, 'v, '
)?;
self.reborrow_lifetimes_to_remove_for_block
.entry(target)
.or_insert_with(BTreeSet::new);
.or_default();
let mut values = self
.reborrow_lifetimes_to_remove_for_block
.get(&self.current_basic_block.unwrap())
Expand Down
2 changes: 1 addition & 1 deletion prusti-viper/src/encoder/mir/procedures/encoder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ impl<'p, 'v: 'p, 'tcx: 'v> ProcedureEncoder<'p, 'v, 'tcx> {
self.derived_lifetimes_yet_to_kill.clear();
self.reborrow_lifetimes_to_remove_for_block
.entry(bb)
.or_insert_with(BTreeSet::new);
.or_default();
self.current_basic_block = Some(bb);
let label = self.encode_basic_block_label(bb);
let mut block_builder = procedure_builder.create_basic_block_builder(label);
Expand Down
2 changes: 1 addition & 1 deletion prusti-viper/src/encoder/procedure_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ impl<'p, 'v: 'p, 'tcx: 'v> ProcedureEncoder<'p, 'v, 'tcx> {
);
self.cfg_blocks_map
.entry(bbi)
.or_insert_with(FxHashSet::default)
.or_default()
.insert(curr_block);

if self.loop_encoder.is_loop_head(bbi) {
Expand Down
4 changes: 2 additions & 2 deletions prusti-viper/src/encoder/purifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ impl StmtWalker for VarDependencyCollector {
let entry = self
.dependencies
.entry(dependent.clone())
.or_insert_with(FxHashSet::default);
.or_default();
entry.extend(dependencies.iter().cloned());
}
for dependency in dependencies {
let entry = self
.dependents
.entry(dependency)
.or_insert_with(FxHashSet::default);
.or_default();
entry.extend(dependents.iter().cloned());
}
match kind {
Expand Down
10 changes: 5 additions & 5 deletions vir/defs/polymorphic/ast/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::super::{
};
use crate::polymorphic::ast::*;
use rustc_hash::FxHashMap;
use std::fmt;
use std::fmt::{self, Write};

// TODO: Fix by boxing all `Expr`s.
#[allow(clippy::large_enum_variant)]
Expand Down Expand Up @@ -1372,8 +1372,8 @@ pub trait FallibleStmtWalker {
}

pub fn stmts_to_str(stmts: &[Stmt]) -> String {
stmts
.iter()
.map(|stmt| format!("{}\n", stmt))
.collect::<String>()
stmts.iter().fold(String::new(), |mut output, stmt| {
let _ = writeln!(output, "{stmt}");
output
})
}
2 changes: 1 addition & 1 deletion vir/defs/polymorphic/cfg/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl CfgMethod {
let mut result = FxHashMap::default();
for (index, block) in self.basic_blocks.iter().enumerate() {
for successor in block.successor.get_following() {
let entry = result.entry(successor.block_index).or_insert_with(Vec::new);
let entry: &mut Vec<_> = result.entry(successor.block_index).or_default();
entry.push(index);
}
}
Expand Down
10 changes: 5 additions & 5 deletions vir/src/legacy/ast/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::super::{
};
use crate::legacy::ast::*;
use std::{
fmt,
fmt::{self, Write},
hash::{Hash, Hasher},
mem::discriminant,
ops::Deref,
Expand Down Expand Up @@ -876,8 +876,8 @@ pub trait StmtWalker {
}

pub fn stmts_to_str(stmts: &[Stmt]) -> String {
stmts
.iter()
.map(|stmt| format!("{stmt}\n"))
.collect::<String>()
stmts.iter().fold(String::new(), |mut output, stmt| {
let _ = writeln!(output, "{stmt}");
output
})
}
2 changes: 1 addition & 1 deletion vir/src/legacy/cfg/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl CfgMethod {
let mut result = FxHashMap::default();
for (index, block) in self.basic_blocks.iter().enumerate() {
for successor in block.successor.get_following() {
let entry = result.entry(successor.block_index).or_insert_with(Vec::new);
let entry: &mut Vec<_> = result.entry(successor.block_index).or_default();
entry.push(index);
}
}
Expand Down

0 comments on commit 30d8683

Please sign in to comment.