From faf80ad3979e58d238f41c22e7be06ff1276a359 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Mon, 3 Sep 2018 21:50:03 +0100 Subject: [PATCH] remove base_place --- src/librustc_mir/borrow_check/mod.rs | 50 ++----------------- .../borrowck-box-insensitivity.nll.stderr | 35 +++++-------- .../ui/borrowck/borrowck-box-insensitivity.rs | 3 +- 3 files changed, 18 insertions(+), 70 deletions(-) diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 3536947b25ebf..fd5ca0780e290 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -1602,10 +1602,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { place_span: (&Place<'tcx>, Span), flow_state: &Flows<'cx, 'gcx, 'tcx>, ) { - // FIXME: analogous code in check_loans first maps `place` to - // its base_path ... but is that what we want here? - let place = self.base_path(place_span.0); - let maybe_uninits = &flow_state.uninits; // Bad scenarios: @@ -1643,8 +1639,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { // // This code covers scenarios 1, 2, and 3. - debug!("check_if_full_path_is_moved place: {:?}", place); - match self.move_path_closest_to(place) { + debug!("check_if_full_path_is_moved place: {:?}", place_span.0); + match self.move_path_closest_to(place_span.0) { Ok(mpi) => { if maybe_uninits.contains(&mpi) { self.report_use_of_moved_or_uninitialized( @@ -1674,10 +1670,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { place_span: (&Place<'tcx>, Span), flow_state: &Flows<'cx, 'gcx, 'tcx>, ) { - // FIXME: analogous code in check_loans first maps `place` to - // its base_path ... but is that what we want here? - let place = self.base_path(place_span.0); - let maybe_uninits = &flow_state.uninits; // Bad scenarios: @@ -1706,8 +1698,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { // // This code covers scenario 1. - debug!("check_if_path_or_subpath_is_moved place: {:?}", place); - if let Some(mpi) = self.move_path_for_place(place) { + debug!("check_if_path_or_subpath_is_moved place: {:?}", place_span.0); + if let Some(mpi) = self.move_path_for_place(place_span.0) { if let Some(child_mpi) = maybe_uninits.has_any_child_of(mpi) { self.report_use_of_moved_or_uninitialized( context, @@ -1810,11 +1802,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { let tcx = self.tcx; match base.ty(self.mir, tcx).to_ty(tcx).sty { ty::Adt(def, _) if def.has_dtor(tcx) => { - - // FIXME: analogous code in - // check_loans.rs first maps - // `base` to its base_path. - self.check_if_path_or_subpath_is_moved( context, InitializationRequiringAction::Assignment, (base, span), flow_state); @@ -2187,35 +2174,6 @@ enum Overlap { Disjoint, } -impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { - // FIXME (#16118): function intended to allow the borrow checker - // to be less precise in its handling of Box while still allowing - // moves out of a Box. They should be removed when/if we stop - // treating Box specially (e.g. when/if DerefMove is added...) - - fn base_path<'d>(&self, place: &'d Place<'tcx>) -> &'d Place<'tcx> { - //! Returns the base of the leftmost (deepest) dereference of an - //! Box in `place`. If there is no dereference of an Box - //! in `place`, then it just returns `place` itself. - - let mut cursor = place; - let mut deepest = place; - loop { - let proj = match *cursor { - Place::Promoted(_) | - Place::Local(..) | Place::Static(..) => return deepest, - Place::Projection(ref proj) => proj, - }; - if proj.elem == ProjectionElem::Deref - && place.ty(self.mir, self.tcx).to_ty(self.tcx).is_box() - { - deepest = &proj.base; - } - cursor = &proj.base; - } - } -} - #[derive(Copy, Clone, PartialEq, Eq, Debug)] struct Context { kind: ContextKind, diff --git a/src/test/ui/borrowck/borrowck-box-insensitivity.nll.stderr b/src/test/ui/borrowck/borrowck-box-insensitivity.nll.stderr index 601f05b499c75..0e380e90e7591 100644 --- a/src/test/ui/borrowck/borrowck-box-insensitivity.nll.stderr +++ b/src/test/ui/borrowck/borrowck-box-insensitivity.nll.stderr @@ -1,25 +1,14 @@ -error[E0382]: use of moved value: `a.y` - --> $DIR/borrowck-box-insensitivity.rs:46:14 - | -LL | let _x = a.x; - | --- value moved here -LL | //~^ value moved here -LL | let _y = a.y; //~ ERROR use of moved - | ^^^ value used here after move - | - = note: move occurs because `a.x` has type `std::boxed::Box`, which does not implement the `Copy` trait - -error[E0382]: use of moved value: `a.y` - --> $DIR/borrowck-box-insensitivity.rs:108:14 - | -LL | let _x = a.x.x; - | ----- value moved here -LL | //~^ value moved here -LL | let _y = a.y; //~ ERROR use of collaterally moved - | ^^^ value used here after move - | - = note: move occurs because `a.x.x` has type `std::boxed::Box`, which does not implement the `Copy` trait +error: compilation successful + --> $DIR/borrowck-box-insensitivity.rs:160:1 + | +LL | / fn main() { +LL | | copy_after_move(); +LL | | move_after_move(); +LL | | borrow_after_move(); +... | +LL | | mut_borrow_after_borrow_nested(); +LL | | } + | |_^ -error: aborting due to 2 previous errors +error: aborting due to previous error -For more information about this error, try `rustc --explain E0382`. diff --git a/src/test/ui/borrowck/borrowck-box-insensitivity.rs b/src/test/ui/borrowck/borrowck-box-insensitivity.rs index 75bf6bce04b39..eabb8d7bca3fa 100644 --- a/src/test/ui/borrowck/borrowck-box-insensitivity.rs +++ b/src/test/ui/borrowck/borrowck-box-insensitivity.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(box_syntax)] +#![feature(box_syntax, rustc_attrs)] struct A { x: Box, @@ -156,6 +156,7 @@ fn mut_borrow_after_borrow_nested() { //~^ mutable borrow occurs here } +#[rustc_error] fn main() { copy_after_move(); move_after_move();