use crate::borrow_check::AccessDepth;
use crate::dataflow::indexes::BorrowIndex;
use rustc::mir::{BasicBlock, Location, Body, Place, PlaceBase};
-use rustc::mir::{ProjectionElem, BorrowKind};
+use rustc::mir::BorrowKind;
use rustc::ty::{self, TyCtxt};
use rustc_data_structures::graph::dominators::Dominators;
/// Determines if a given borrow is borrowing local data
/// This is called for all Yield statements on movable generators
pub(super) fn borrow_of_local_data(place: &Place<'_>) -> bool {
- place.iterate(|place_base, place_projection| {
- match place_base {
- PlaceBase::Static(..) => return false,
- PlaceBase::Local(..) => {},
- }
-
- for proj in place_projection {
- // Reborrow of already borrowed data is ignored
- // Any errors will be caught on the initial borrow
- if proj.elem == ProjectionElem::Deref {
- return false;
- }
- }
+ match place.base {
+ PlaceBase::Static(_) => false,
- true
- })
+ // Reborrow of already borrowed data is ignored
+ // Any errors will be caught on the initial borrow
+ PlaceBase::Local(_) => !place.is_indirect(),
+ }
}
}
fn find_local(place: &Place<'_>) -> Option<Local> {
- place.iterate(|place_base, place_projection| {
- for proj in place_projection {
- if proj.elem == ProjectionElem::Deref {
- return None;
- }
- }
-
- if let PlaceBase::Local(local) = place_base {
- Some(*local)
- } else {
- None
- }
- })
+ match place.base {
+ PlaceBase::Local(local) if !place.is_indirect() => Some(local),
+ _ => None,
+ }
}
impl<'tcx> Visitor<'tcx> for BorrowedLocalsVisitor<'_> {