Skip to content

Commit 1047079

Browse files
committed
Avoid cloning Place in report_cannot_move_from_borrowed_content
1 parent 09014fc commit 1047079

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,14 +481,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
481481

482482
pub(super) fn borrowed_content_source(
483483
&self,
484-
deref_base: &Place<'tcx>,
484+
deref_base: PlaceRef<'cx, 'tcx>,
485485
) -> BorrowedContentSource<'tcx> {
486486
let tcx = self.infcx.tcx;
487487

488488
// Look up the provided place and work out the move path index for it,
489489
// we'll use this to check whether it was originally from an overloaded
490490
// operator.
491-
match self.move_data.rev_lookup.find(deref_base.as_place_ref()) {
491+
match self.move_data.rev_lookup.find(deref_base) {
492492
LookupResult::Exact(mpi) | LookupResult::Parent(Some(mpi)) => {
493493
debug!("borrowed_content_source: mpi={:?}", mpi);
494494

@@ -533,7 +533,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
533533

534534
// If we didn't find an overloaded deref or index, then assume it's a
535535
// built in deref and check the type of the base.
536-
let base_ty = deref_base.ty(self.body, tcx).ty;
536+
let base_ty = Place::ty_from(deref_base.base, deref_base.projection, self.body, tcx).ty;
537537
if base_ty.is_unsafe_ptr() {
538538
BorrowedContentSource::DerefRawPointer
539539
} else if base_ty.is_mutable_pointer() {

src/librustc_mir/borrow_check/move_errors.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,18 +312,18 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
312312
.find_map(|p| self.is_upvar_field_projection(p));
313313

314314
let deref_base = match deref_target_place.projection {
315-
Some(box Projection { ref base, elem: ProjectionElem::Deref }) => Place {
316-
base: deref_target_place.base.clone(),
317-
projection: base.clone(),
315+
Some(box Projection { ref base, elem: ProjectionElem::Deref }) => PlaceRef {
316+
base: &deref_target_place.base,
317+
projection: base,
318318
},
319319
_ => bug!("deref_target_place is not a deref projection"),
320320
};
321321

322-
if let Place {
322+
if let PlaceRef {
323323
base: PlaceBase::Local(local),
324324
projection: None,
325325
} = deref_base {
326-
let decl = &self.body.local_decls[local];
326+
let decl = &self.body.local_decls[*local];
327327
if decl.is_ref_for_guard() {
328328
let mut err = self.cannot_move_out_of(
329329
span,
@@ -391,7 +391,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
391391
diag
392392
}
393393
_ => {
394-
let source = self.borrowed_content_source(&deref_base);
394+
let source = self.borrowed_content_source(deref_base);
395395
match (
396396
self.describe_place(move_place.as_place_ref()),
397397
source.describe_for_named_place(),

src/librustc_mir/borrow_check/mutability_errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
124124
item_msg = format!("`{}`", access_place_desc.unwrap());
125125
reason = ", as it is immutable for the pattern guard".to_string();
126126
} else {
127-
let source = self.borrowed_content_source(&Place {
128-
base: the_place_err.base.clone(),
129-
projection: base.clone(),
127+
let source = self.borrowed_content_source(PlaceRef {
128+
base: the_place_err.base,
129+
projection: base,
130130
});
131131
let pointer_type = source.describe_for_immutable_place();
132132
opt_source = Some(source);

0 commit comments

Comments
 (0)