Skip to content

Commit 7d10e8e

Browse files
committed
Remove PlaceExt impl for Place and use the NeoPlace one
1 parent 62a52ed commit 7d10e8e

File tree

3 files changed

+6
-61
lines changed

3 files changed

+6
-61
lines changed

src/librustc_mir/borrow_check/borrow_set.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
192192
location: mir::Location,
193193
) {
194194
if let mir::Rvalue::Ref(region, kind, ref borrowed_place) = *rvalue {
195-
if borrowed_place.ignore_borrow(
195+
let borrowed_neo_place = self.tcx.as_new_place(borrowed_place);
196+
if borrowed_neo_place.ignore_borrow(
196197
self.tcx, self.mir, &self.locals_state_at_exit) {
197198
return;
198199
}

src/librustc_mir/borrow_check/place_ext.rs

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc::hir;
22
use rustc::mir::ProjectionElem;
3-
use rustc::mir::{Mir, Place, NeoPlace, PlaceBase, Mutability};
3+
use rustc::mir::{Mir, NeoPlace, PlaceBase, Mutability};
44
use rustc::mir::tcx::PlaceTy;
55
use rustc::ty::{self, TyCtxt};
66
use borrow_check::borrow_set::LocalsStateAtExit;
@@ -19,64 +19,6 @@ crate trait PlaceExt<'tcx> {
1919
) -> bool;
2020
}
2121

22-
impl<'tcx> PlaceExt<'tcx> for Place<'tcx> {
23-
fn ignore_borrow(
24-
&self,
25-
tcx: TyCtxt<'_, '_, 'tcx>,
26-
mir: &Mir<'tcx>,
27-
locals_state_at_exit: &LocalsStateAtExit,
28-
) -> bool {
29-
let neo_place = tcx.as_new_place(self);
30-
let mut is_unsafe_place = match &neo_place.base {
31-
// If a local variable is immutable, then we only need to track borrows to guard
32-
// against two kinds of errors:
33-
// * The variable being dropped while still borrowed (e.g., because the fn returns
34-
// a reference to a local variable)
35-
// * The variable being moved while still borrowed
36-
//
37-
// In particular, the variable cannot be mutated -- the "access checks" will fail --
38-
// so we don't have to worry about mutation while borrowed.
39-
PlaceBase::Local(index) => {
40-
match locals_state_at_exit {
41-
LocalsStateAtExit::AllAreInvalidated => false,
42-
LocalsStateAtExit::SomeAreInvalidated { has_storage_dead_or_moved } => {
43-
let ignore = !has_storage_dead_or_moved.contains(*index) &&
44-
mir.local_decls[*index].mutability == Mutability::Not;
45-
debug!("ignore_borrow: local {:?} => {:?}", index, ignore);
46-
ignore
47-
}
48-
}
49-
},
50-
PlaceBase::Promoted(_) => false,
51-
PlaceBase::Static(static_) => {
52-
tcx.is_static(static_.def_id) == Some(hir::Mutability::MutMutable)
53-
}
54-
};
55-
56-
let mut base_ty = neo_place.base.ty(mir);
57-
for elem in neo_place.elems.iter() {
58-
if let ProjectionElem::Deref = elem {
59-
if let ty::RawPtr(..) | ty::Ref(_, _, hir::MutImmutable) = base_ty.sty {
60-
// For both derefs of raw pointers and `&T`
61-
// references, the original path is `Copy` and
62-
// therefore not significant. In particular,
63-
// there is nothing the user can do to the
64-
// original path that would invalidate the
65-
// newly created reference -- and if there
66-
// were, then the user could have copied the
67-
// original path into a new variable and
68-
// borrowed *that* one, leaving the original
69-
// path unborrowed.
70-
is_unsafe_place = true;
71-
}
72-
}
73-
base_ty = PlaceTy::from(base_ty).projection_ty(tcx, elem).to_ty(tcx);
74-
}
75-
76-
is_unsafe_place
77-
}
78-
}
79-
8022
impl<'tcx> PlaceExt<'tcx> for NeoPlace<'tcx> {
8123
fn ignore_borrow(
8224
&self,

src/librustc_mir/dataflow/impls/borrows.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,9 @@ impl<'a, 'gcx, 'tcx> BitDenotation<'tcx> for Borrows<'a, 'gcx, 'tcx> {
269269
self.kill_borrows_on_place(sets, lhs);
270270

271271
if let box mir::Rvalue::Ref(_, _, place) = rhs {
272-
if place.ignore_borrow(
272+
let neo_place = self.tcx.as_new_place(place);
273+
274+
if neo_place.ignore_borrow(
273275
self.tcx,
274276
self.mir,
275277
&self.borrow_set.locals_state_at_exit,

0 commit comments

Comments
 (0)