Skip to content

Commit

Permalink
Fix categorizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Nov 28, 2019
1 parent c1c5c35 commit 45842e5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 25 deletions.
6 changes: 3 additions & 3 deletions clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ fn is_argument(map: &hir::map::Map<'_>, id: HirId) -> bool {

impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
fn consume(&mut self, cmt: &Place<'tcx>, mode: ConsumeMode) {
if let Categorization::Local(lid) = cmt.cat {
if let PlaceBase::Local(lid) = cmt.base {
if let ConsumeMode::Move = mode {
// moved out or in. clearly can't be localized
self.set.remove(&lid);
}
}
let map = &self.cx.tcx.hir();
if let Categorization::Local(lid) = cmt.cat {
if let PlaceBase::Local(lid) = cmt.base {
if let Some(Node::Binding(_)) = map.find(cmt.hir_id) {
if self.set.contains(&lid) {
// let y = x where x is known
Expand All @@ -124,7 +124,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
}

fn borrow(&mut self, cmt: &Place<'tcx>, _: ty::BorrowKind) {
if let Categorization::Local(lid) = cmt.cat {
if let PlaceBase::Local(lid) = cmt.base {
self.set.remove(&lid);
}
}
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1588,7 +1588,7 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate {

fn borrow(&mut self, cmt: &Place<'tcx>, bk: ty::BorrowKind) {
if let ty::BorrowKind::MutBorrow = bk {
if let Categorization::Local(id) = cmt.cat {
if let PlaceBase::Local(id) = cmt.base {
if Some(id) == self.hir_id_low {
self.span_low = Some(cmt.span)
}
Expand All @@ -1600,7 +1600,7 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate {
}

fn mutate(&mut self, cmt: &Place<'tcx>) {
if let Categorization::Local(id) = cmt.cat {
if let PlaceBase::Local(id) = cmt.base {
if Some(id) == self.hir_id_low {
self.span_low = Some(cmt.span)
}
Expand Down
14 changes: 1 addition & 13 deletions clippy_lints/src/needless_pass_by_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,7 @@ struct MovedVariablesCtxt {

impl MovedVariablesCtxt {
fn move_common(&mut self, cmt: &euv::Place<'_>) {
let cmt = unwrap_downcast_or_interior(cmt);

if let mc::Categorization::Local(vid) = cmt.cat {
if let euv::PlaceBase::Local(vid) = cmt.base {
self.moved_vars.insert(vid);
}
}
Expand All @@ -345,13 +343,3 @@ impl<'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt {
fn mutate(&mut self, _: &euv::Place<'tcx>) {}
}

fn unwrap_downcast_or_interior<'a, 'tcx>(mut cmt: &'a euv::Place<'tcx>) -> euv::Place<'tcx> {
loop {
match cmt.cat {
mc::Categorization::Downcast(ref c, _) | mc::Categorization::Interior(ref c, _) => {
cmt = c;
},
_ => return (*cmt).clone(),
}
}
}
13 changes: 6 additions & 7 deletions clippy_lints/src/utils/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,17 @@ struct MutVarsDelegate {

impl<'tcx> MutVarsDelegate {
#[allow(clippy::similar_names)]
fn update(&mut self, cat: &'tcx Categorization<'_>) {
match *cat {
Categorization::Local(id) => {
fn update(&mut self, cat: &Place<'tcx>) {
match cat.base {
PlaceBase::Local(id) => {
self.used_mutably.insert(id);
},
Categorization::Upvar(_) => {
PlaceBase::Upvar(_) => {
//FIXME: This causes false negatives. We can't get the `NodeId` from
//`Categorization::Upvar(_)`. So we search for any `Upvar`s in the
//`while`-body, not just the ones in the condition.
self.skip = true
},
Categorization::Deref(ref cmt, _) | Categorization::Interior(ref cmt, _) => self.update(&cmt.cat),
_ => {},
}
}
Expand All @@ -64,11 +63,11 @@ impl<'tcx> Delegate<'tcx> for MutVarsDelegate {

fn borrow(&mut self, cmt: &Place<'tcx>, bk: ty::BorrowKind) {
if let ty::BorrowKind::MutBorrow = bk {
self.update(&cmt.cat)
self.update(&cmt)
}
}

fn mutate(&mut self, cmt: &Place<'tcx>) {
self.update(&cmt.cat)
self.update(&cmt)
}
}

0 comments on commit 45842e5

Please sign in to comment.