diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index 77a3f138fe5..a47ced010e6 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -250,7 +250,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { let new_closure_span = self.find_closure_span(span, context.loc); let span = new_closure_span.map(|(args, _)| args).unwrap_or(span); - let old_closure_span = self.find_closure_span(issued_span, issued_borrow.location); + let old_closure_span = self.find_closure_span(issued_span, issued_borrow.reserve_location); let issued_span = old_closure_span .map(|(args, _)| args) .unwrap_or(issued_span); @@ -380,7 +380,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { .last() .unwrap(); - let borrow_span = self.mir.source_info(borrow.location).span; + let borrow_span = self.mir.source_info(borrow.reserve_location).span; let proper_span = match *root_place { Place::Local(local) => self.mir.local_decls[local].source_info.span, _ => drop_span, @@ -817,7 +817,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { // Retrieve span of given borrow from the current MIR representation pub fn retrieve_borrow_span(&self, borrow: &BorrowData) -> Span { - self.mir.source_info(borrow.location).span + self.mir.source_info(borrow.reserve_location).span } // Retrieve type of a place for the current MIR representation diff --git a/src/librustc_mir/dataflow/impls/borrows.rs b/src/librustc_mir/dataflow/impls/borrows.rs index a150335a1ae..859618d27b3 100644 --- a/src/librustc_mir/dataflow/impls/borrows.rs +++ b/src/librustc_mir/dataflow/impls/borrows.rs @@ -111,7 +111,9 @@ impl<'a, 'gcx, 'tcx> ActiveBorrows<'a, 'gcx, 'tcx> { #[allow(dead_code)] #[derive(Debug)] pub struct BorrowData<'tcx> { - pub(crate) location: Location, + /// Location where the borrow reservation starts. + /// In many cases, this will be equal to the activation location but not always. + pub(crate) reserve_location: Location, pub(crate) kind: mir::BorrowKind, pub(crate) region: Region<'tcx>, pub(crate) borrowed_place: mir::Place<'tcx>, @@ -209,7 +211,8 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> { if is_unsafe_place(self.tcx, self.mir, borrowed_place) { return; } let borrow = BorrowData { - location, kind, region, + reserve_location: location, + kind, region, borrowed_place: borrowed_place.clone(), assigned_place: assigned_place.clone(), }; @@ -245,7 +248,7 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> { let mut found_it = false; for idx in &self.region_map[region] { let bd = &self.idx_vec[*idx]; - if bd.location == location && + if bd.reserve_location == location && bd.kind == kind && bd.region == region && bd.borrowed_place == *place @@ -277,7 +280,7 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> { pub fn scope_tree(&self) -> &Lrc { &self.scope_tree } pub fn location(&self, idx: BorrowIndex) -> &Location { - &self.borrows[idx].location + &self.borrows[idx].reserve_location } /// Add all borrows to the kill set, if those borrows are out of scope at `location`.