diff options
| author | Shotaro Yamada <sinkuu@sinkuu.xyz> | 2019-09-28 20:29:35 +0900 |
|---|---|---|
| committer | Shotaro Yamada <sinkuu@sinkuu.xyz> | 2019-10-03 08:10:29 +0900 |
| commit | 1cee3fe00e08ee1f34583df9a20e1e8c0068a139 (patch) | |
| tree | 26e7d9be34d79508cf06146a39fc41b5509478b6 | |
| parent | a3f403aa5020e8890e23e054ad08624955180720 (diff) | |
| download | rust-1cee3fe00e08ee1f34583df9a20e1e8c0068a139.tar.gz rust-1cee3fe00e08ee1f34583df9a20e1e8c0068a139.zip | |
Resolve reviews
| -rw-r--r-- | clippy_lints/src/booleans.rs | 2 | ||||
| -rw-r--r-- | 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 4309eaa7879..c5da0af6f4d 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 a8589e6658a..5a2baf2e8ba 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<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(); @@ -587,6 +585,6 @@ impl PossibleBorrower<'_, '_> { self.bitset.1.insert(*b); } - Some(self.bitset.0 == self.bitset.1) + self.bitset.0 == self.bitset.1 } } |
