mirror of https://github.com/rust-lang/rust.git
Fix categorizations
This commit is contained in:
parent
c1c5c3522d
commit
45842e5131
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue