Skip to content

Commit 95e727a

Browse files
committed
Avoid cloning Place in check_access_permissions
1 parent 34e3b70 commit 95e727a

File tree

2 files changed

+36
-28
lines changed

2 files changed

+36
-28
lines changed

src/librustc_mir/borrow_check/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,9 +1996,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19961996
self.report_mutability_error(
19971997
place,
19981998
span,
1999-
&Place {
2000-
base: _place_err.0.clone(),
2001-
projection: _place_err.1.clone(),
1999+
PlaceRef {
2000+
base: _place_err.0,
2001+
projection: _place_err.1,
20022002
},
20032003
error_access,
20042004
location,
@@ -2033,9 +2033,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
20332033
self.report_mutability_error(
20342034
place,
20352035
span,
2036-
&Place {
2037-
base: the_place_err.0.clone(),
2038-
projection: the_place_err.1.clone(),
2036+
PlaceRef {
2037+
base: the_place_err.0,
2038+
projection: the_place_err.1,
20392039
},
20402040
error_access,
20412041
location,

src/librustc_mir/borrow_check/mutability_errors.rs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ use core::unicode::property::Pattern_White_Space;
22
use rustc::hir;
33
use rustc::hir::Node;
44
use rustc::mir::{self, BindingForm, ClearCrossCrate, Local, Location, Body};
5-
use rustc::mir::{Mutability, Place, PlaceBase, Projection, ProjectionElem, Static, StaticKind};
5+
use rustc::mir::{
6+
Mutability, Place, PlaceRef, PlaceBase, Projection, ProjectionElem, Static, StaticKind
7+
};
68
use rustc::ty::{self, Ty, TyCtxt};
79
use rustc_data_structures::indexed_vec::Idx;
810
use syntax_pos::Span;
@@ -25,7 +27,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
2527
&mut self,
2628
access_place: &Place<'tcx>,
2729
span: Span,
28-
the_place_err: &Place<'tcx>,
30+
the_place_err: PlaceRef<'cx, 'tcx>,
2931
error_access: AccessKind,
3032
location: Location,
3133
) {
@@ -44,7 +46,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
4446
debug!("report_mutability_error: access_place_desc={:?}", access_place_desc);
4547

4648
match the_place_err {
47-
Place {
49+
PlaceRef {
4850
base: PlaceBase::Local(local),
4951
projection: None,
5052
} => {
@@ -62,7 +64,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
6264
}
6365
}
6466

65-
Place {
67+
PlaceRef {
6668
base: _,
6769
projection:
6870
Some(box Projection {
@@ -83,21 +85,27 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
8385
}
8486
}
8587

86-
Place {
88+
PlaceRef {
8789
base: _,
8890
projection:
8991
Some(box Projection {
9092
base,
9193
elem: ProjectionElem::Deref,
9294
}),
9395
} => {
94-
if the_place_err.base == PlaceBase::Local(Local::new(1)) &&
96+
if the_place_err.base == &PlaceBase::Local(Local::new(1)) &&
9597
base.is_none() &&
9698
!self.upvars.is_empty() {
9799
item_msg = format!("`{}`", access_place_desc.unwrap());
98100
debug_assert!(self.body.local_decls[Local::new(1)].ty.is_region_ptr());
99101
debug_assert!(is_closure_or_generator(
100-
the_place_err.ty(self.body, self.infcx.tcx).ty
102+
Place::ty_from(
103+
the_place_err.base,
104+
the_place_err.projection,
105+
self.body,
106+
self.infcx.tcx
107+
)
108+
.ty
101109
));
102110

103111
reason =
@@ -138,7 +146,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
138146
}
139147
}
140148

141-
Place {
149+
PlaceRef {
142150
base:
143151
PlaceBase::Static(box Static {
144152
kind: StaticKind::Promoted(_),
@@ -147,7 +155,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
147155
projection: None,
148156
} => unreachable!(),
149157

150-
Place {
158+
PlaceRef {
151159
base:
152160
PlaceBase::Static(box Static {
153161
kind: StaticKind::Static(def_id),
@@ -168,30 +176,30 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
168176
}
169177
}
170178

171-
Place {
179+
PlaceRef {
172180
base: _,
173181
projection:
174182
Some(box Projection {
175183
base: _,
176184
elem: ProjectionElem::Index(_),
177185
}),
178186
}
179-
| Place {
187+
| PlaceRef {
180188
base: _,
181189
projection:
182190
Some(box Projection {
183191
base: _,
184192
elem: ProjectionElem::ConstantIndex { .. },
185193
}),
186194
}
187-
| Place {
195+
| PlaceRef {
188196
base: _,
189197
projection: Some(box Projection {
190198
base: _,
191199
elem: ProjectionElem::Subslice { .. },
192200
}),
193201
}
194-
| Place {
202+
| PlaceRef {
195203
base: _,
196204
projection: Some(box Projection {
197205
base: _,
@@ -252,7 +260,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
252260
// something like `*((*_1).0`. The local that we get will be a reference to the
253261
// struct we've got a field access of (it must be a reference since there's a deref
254262
// after the field access).
255-
Place {
263+
PlaceRef {
256264
base,
257265
projection: Some(box Projection {
258266
base: Some(box Projection {
@@ -282,7 +290,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
282290
},
283291

284292
// Suggest removing a `&mut` from the use of a mutable reference.
285-
Place {
293+
PlaceRef {
286294
base: PlaceBase::Local(local),
287295
projection: None,
288296
} if {
@@ -318,7 +326,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
318326

319327
// We want to suggest users use `let mut` for local (user
320328
// variable) mutations...
321-
Place {
329+
PlaceRef {
322330
base: PlaceBase::Local(local),
323331
projection: None,
324332
} if self.body.local_decls[*local].can_be_made_mutable() => {
@@ -339,7 +347,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
339347
}
340348

341349
// Also suggest adding mut for upvars
342-
Place {
350+
PlaceRef {
343351
base,
344352
projection: Some(box Projection {
345353
base: proj_base,
@@ -375,7 +383,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
375383
// complete hack to approximate old AST-borrowck
376384
// diagnostic: if the span starts with a mutable borrow of
377385
// a local variable, then just suggest the user remove it.
378-
Place {
386+
PlaceRef {
379387
base: PlaceBase::Local(_),
380388
projection: None,
381389
} if {
@@ -390,7 +398,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
390398
err.span_label(span, "try removing `&mut` here");
391399
}
392400

393-
Place {
401+
PlaceRef {
394402
base: PlaceBase::Local(local),
395403
projection: Some(box Projection {
396404
base: None,
@@ -417,7 +425,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
417425
//
418426
// FIXME: can this case be generalized to work for an
419427
// arbitrary base for the projection?
420-
Place {
428+
PlaceRef {
421429
base: PlaceBase::Local(local),
422430
projection: Some(box Projection {
423431
base: None,
@@ -500,7 +508,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
500508
}
501509
}
502510

503-
Place {
511+
PlaceRef {
504512
base,
505513
projection: Some(box Projection {
506514
base: None,
@@ -517,7 +525,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
517525
);
518526
}
519527

520-
Place {
528+
PlaceRef {
521529
base: _,
522530
projection: Some(box Projection {
523531
base: _,

0 commit comments

Comments
 (0)