Skip to content

Commit

Permalink
Resolve reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkuu committed Sep 30, 2019
1 parent 8a5a2f8 commit 26f19f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {

let stats = terminal_stats(&expr);
let mut simplified = expr.simplify();
for simple in Bool::Not(Box::new(expr.clone())).simplify() {
for simple in Bool::Not(Box::new(expr)).simplify() {
match simple {
Bool::Not(_) | Bool::True | Bool::False => {},
_ => simplified.push(Bool::Not(Box::new(simple.clone()))),
Expand Down
24 changes: 11 additions & 13 deletions clippy_lints/src/redundant_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone {
statement_index: bbdata.statements.len(),
};

if from_borrow
&& (cannot_move_out || possible_borrower.only_borrowers(&[arg][..], cloned, loc) != Some(true))
{
if from_borrow && (cannot_move_out || !possible_borrower.only_borrowers(&[arg], cloned, loc)) {
continue;
}

Expand Down Expand Up @@ -171,7 +169,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone {
block: bb,
statement_index: mir.basic_blocks()[bb].statements.len(),
};
if cannot_move_out || possible_borrower.only_borrowers(&[arg, cloned][..], local, loc) != Some(true) {
if cannot_move_out || !possible_borrower.only_borrowers(&[arg, cloned], local, loc) {
continue;
}
local
Expand Down Expand Up @@ -564,29 +562,29 @@ fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) {
struct PossibleBorrower<'a, 'tcx> {
map: FxHashMap<mir::Local, HybridBitSet<mir::Local>>,
maybe_live: DataflowResultsCursor<'a, 'tcx, MaybeStorageLive<'a, 'tcx>>,
// Caches to avoid allocation of `BitSet` on every query
bitset: (BitSet<mir::Local>, BitSet<mir::Local>),
}

impl PossibleBorrower<'_, '_> {
fn only_borrowers<'a>(
&mut self,
borrowers: impl IntoIterator<Item = &'a mir::Local>,
borrowed: mir::Local,
at: mir::Location,
) -> Option<bool> {
fn only_borrowers(&mut self, borrowers: &[mir::Local], borrowed: mir::Local, at: mir::Location) -> bool {
self.maybe_live.seek(at);

self.bitset.0.clear();
let maybe_live = &mut self.maybe_live;
for b in self.map.get(&borrowed)?.iter().filter(move |b| maybe_live.contains(*b)) {
self.bitset.0.insert(b);
if let Some(bitset) = self.map.get(&borrowed) {
for b in bitset.iter().filter(move |b| maybe_live.contains(*b)) {
self.bitset.0.insert(b);
}
} else {
return false;
}

self.bitset.1.clear();
for b in borrowers {
self.bitset.1.insert(*b);
}

Some(self.bitset.0 == self.bitset.1)
self.bitset.0 == self.bitset.1
}
}

0 comments on commit 26f19f7

Please sign in to comment.