From 26f19f71e8bf092f0e1fb26d6587a0214cc32832 Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Sat, 28 Sep 2019 20:29:35 +0900 Subject: [PATCH] Resolve reviews --- clippy_lints/src/booleans.rs | 2 +- clippy_lints/src/redundant_clone.rs | 24 +++++++++++------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index 4309eaa78797..c5da0af6f4d1 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -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()))), diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index a8589e6658aa..5a2baf2e8ba4 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -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; } @@ -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 @@ -564,22 +562,22 @@ fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) { struct PossibleBorrower<'a, 'tcx> { map: FxHashMap>, maybe_live: DataflowResultsCursor<'a, 'tcx, MaybeStorageLive<'a, 'tcx>>, + // Caches to avoid allocation of `BitSet` on every query bitset: (BitSet, BitSet), } impl PossibleBorrower<'_, '_> { - fn only_borrowers<'a>( - &mut self, - borrowers: impl IntoIterator, - borrowed: mir::Local, - at: mir::Location, - ) -> Option { + 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(); @@ -587,6 +585,6 @@ impl PossibleBorrower<'_, '_> { self.bitset.1.insert(*b); } - Some(self.bitset.0 == self.bitset.1) + self.bitset.0 == self.bitset.1 } }