Skip to content

Commit faf80ad

Browse files
committed
remove base_place
1 parent ee73f80 commit faf80ad

File tree

3 files changed

+18
-70
lines changed

3 files changed

+18
-70
lines changed

src/librustc_mir/borrow_check/mod.rs

+4-46
Original file line numberDiff line numberDiff line change
@@ -1602,10 +1602,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
16021602
place_span: (&Place<'tcx>, Span),
16031603
flow_state: &Flows<'cx, 'gcx, 'tcx>,
16041604
) {
1605-
// FIXME: analogous code in check_loans first maps `place` to
1606-
// its base_path ... but is that what we want here?
1607-
let place = self.base_path(place_span.0);
1608-
16091605
let maybe_uninits = &flow_state.uninits;
16101606

16111607
// Bad scenarios:
@@ -1643,8 +1639,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
16431639
//
16441640
// This code covers scenarios 1, 2, and 3.
16451641

1646-
debug!("check_if_full_path_is_moved place: {:?}", place);
1647-
match self.move_path_closest_to(place) {
1642+
debug!("check_if_full_path_is_moved place: {:?}", place_span.0);
1643+
match self.move_path_closest_to(place_span.0) {
16481644
Ok(mpi) => {
16491645
if maybe_uninits.contains(&mpi) {
16501646
self.report_use_of_moved_or_uninitialized(
@@ -1674,10 +1670,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
16741670
place_span: (&Place<'tcx>, Span),
16751671
flow_state: &Flows<'cx, 'gcx, 'tcx>,
16761672
) {
1677-
// FIXME: analogous code in check_loans first maps `place` to
1678-
// its base_path ... but is that what we want here?
1679-
let place = self.base_path(place_span.0);
1680-
16811673
let maybe_uninits = &flow_state.uninits;
16821674

16831675
// Bad scenarios:
@@ -1706,8 +1698,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
17061698
//
17071699
// This code covers scenario 1.
17081700

1709-
debug!("check_if_path_or_subpath_is_moved place: {:?}", place);
1710-
if let Some(mpi) = self.move_path_for_place(place) {
1701+
debug!("check_if_path_or_subpath_is_moved place: {:?}", place_span.0);
1702+
if let Some(mpi) = self.move_path_for_place(place_span.0) {
17111703
if let Some(child_mpi) = maybe_uninits.has_any_child_of(mpi) {
17121704
self.report_use_of_moved_or_uninitialized(
17131705
context,
@@ -1810,11 +1802,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18101802
let tcx = self.tcx;
18111803
match base.ty(self.mir, tcx).to_ty(tcx).sty {
18121804
ty::Adt(def, _) if def.has_dtor(tcx) => {
1813-
1814-
// FIXME: analogous code in
1815-
// check_loans.rs first maps
1816-
// `base` to its base_path.
1817-
18181805
self.check_if_path_or_subpath_is_moved(
18191806
context, InitializationRequiringAction::Assignment,
18201807
(base, span), flow_state);
@@ -2187,35 +2174,6 @@ enum Overlap {
21872174
Disjoint,
21882175
}
21892176

2190-
impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
2191-
// FIXME (#16118): function intended to allow the borrow checker
2192-
// to be less precise in its handling of Box while still allowing
2193-
// moves out of a Box. They should be removed when/if we stop
2194-
// treating Box specially (e.g. when/if DerefMove is added...)
2195-
2196-
fn base_path<'d>(&self, place: &'d Place<'tcx>) -> &'d Place<'tcx> {
2197-
//! Returns the base of the leftmost (deepest) dereference of an
2198-
//! Box in `place`. If there is no dereference of an Box
2199-
//! in `place`, then it just returns `place` itself.
2200-
2201-
let mut cursor = place;
2202-
let mut deepest = place;
2203-
loop {
2204-
let proj = match *cursor {
2205-
Place::Promoted(_) |
2206-
Place::Local(..) | Place::Static(..) => return deepest,
2207-
Place::Projection(ref proj) => proj,
2208-
};
2209-
if proj.elem == ProjectionElem::Deref
2210-
&& place.ty(self.mir, self.tcx).to_ty(self.tcx).is_box()
2211-
{
2212-
deepest = &proj.base;
2213-
}
2214-
cursor = &proj.base;
2215-
}
2216-
}
2217-
}
2218-
22192177
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
22202178
struct Context {
22212179
kind: ContextKind,
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
1-
error[E0382]: use of moved value: `a.y`
2-
--> $DIR/borrowck-box-insensitivity.rs:46:14
3-
|
4-
LL | let _x = a.x;
5-
| --- value moved here
6-
LL | //~^ value moved here
7-
LL | let _y = a.y; //~ ERROR use of moved
8-
| ^^^ value used here after move
9-
|
10-
= note: move occurs because `a.x` has type `std::boxed::Box<isize>`, which does not implement the `Copy` trait
11-
12-
error[E0382]: use of moved value: `a.y`
13-
--> $DIR/borrowck-box-insensitivity.rs:108:14
14-
|
15-
LL | let _x = a.x.x;
16-
| ----- value moved here
17-
LL | //~^ value moved here
18-
LL | let _y = a.y; //~ ERROR use of collaterally moved
19-
| ^^^ value used here after move
20-
|
21-
= note: move occurs because `a.x.x` has type `std::boxed::Box<isize>`, which does not implement the `Copy` trait
1+
error: compilation successful
2+
--> $DIR/borrowck-box-insensitivity.rs:160:1
3+
|
4+
LL | / fn main() {
5+
LL | | copy_after_move();
6+
LL | | move_after_move();
7+
LL | | borrow_after_move();
8+
... |
9+
LL | | mut_borrow_after_borrow_nested();
10+
LL | | }
11+
| |_^
2212

23-
error: aborting due to 2 previous errors
13+
error: aborting due to previous error
2414

25-
For more information about this error, try `rustc --explain E0382`.

src/test/ui/borrowck/borrowck-box-insensitivity.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(box_syntax)]
11+
#![feature(box_syntax, rustc_attrs)]
1212

1313
struct A {
1414
x: Box<isize>,
@@ -156,6 +156,7 @@ fn mut_borrow_after_borrow_nested() {
156156
//~^ mutable borrow occurs here
157157
}
158158

159+
#[rustc_error]
159160
fn main() {
160161
copy_after_move();
161162
move_after_move();

0 commit comments

Comments
 (0)