From 45842e5131b763102abb20a6ba845d5acafdf8a5 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 28 Nov 2019 07:33:12 -0800 Subject: [PATCH] Fix categorizations --- clippy_lints/src/escape.rs | 6 +++--- clippy_lints/src/loops.rs | 4 ++-- clippy_lints/src/needless_pass_by_value.rs | 14 +------------- clippy_lints/src/utils/usage.rs | 13 ++++++------- 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index a3cbac820c6..62fdf295aa7 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -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 @@ -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); } } diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 3b86fddd8bd..948367d8cee 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -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) } @@ -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) } diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 64786f48719..617841f2e5d 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -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); } } @@ -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(), - } - } -} diff --git a/clippy_lints/src/utils/usage.rs b/clippy_lints/src/utils/usage.rs index e71dfd7401f..59220e732a0 100644 --- a/clippy_lints/src/utils/usage.rs +++ b/clippy_lints/src/utils/usage.rs @@ -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), _ => {}, } } @@ -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) } }