Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 890b393

Browse files
committed
Use Place directly, it's Copy even more use cases
1 parent 25528c1 commit 890b393

File tree

17 files changed

+120
-119
lines changed

17 files changed

+120
-119
lines changed

src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
396396
);
397397
self.suggest_split_at_mut_if_applicable(
398398
&mut err,
399-
&place,
400-
&issued_borrow.borrowed_place,
399+
place,
400+
issued_borrow.borrowed_place,
401401
);
402402
err
403403
}
@@ -410,7 +410,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
410410
(BorrowKind::Mut { .. }, BorrowKind::Shallow)
411411
| (BorrowKind::Unique, BorrowKind::Shallow) => {
412412
if let Some(immutable_section_description) =
413-
self.classify_immutable_section(&issued_borrow.assigned_place)
413+
self.classify_immutable_section(issued_borrow.assigned_place)
414414
{
415415
let mut err = self.cannot_mutate_in_immutable_section(
416416
span,
@@ -546,8 +546,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
546546
fn suggest_split_at_mut_if_applicable(
547547
&self,
548548
err: &mut DiagnosticBuilder<'_>,
549-
place: &Place<'tcx>,
550-
borrowed_place: &Place<'tcx>,
549+
place: Place<'tcx>,
550+
borrowed_place: Place<'tcx>,
551551
) {
552552
if let ([ProjectionElem::Index(_)], [ProjectionElem::Index(_)]) =
553553
(&place.projection[..], &borrowed_place.projection[..])
@@ -1382,7 +1382,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13821382

13831383
let descr_place = self.describe_any_place(place.as_ref());
13841384
if loan.kind == BorrowKind::Shallow {
1385-
if let Some(section) = self.classify_immutable_section(&loan.assigned_place) {
1385+
if let Some(section) = self.classify_immutable_section(loan.assigned_place) {
13861386
let mut err = self.cannot_mutate_in_immutable_section(
13871387
span,
13881388
loan_span,
@@ -1534,17 +1534,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15341534
}
15351535

15361536
/// Describe the reason for the fake borrow that was assigned to `place`.
1537-
fn classify_immutable_section(&self, place: &Place<'tcx>) -> Option<&'static str> {
1537+
fn classify_immutable_section(&self, place: Place<'tcx>) -> Option<&'static str> {
15381538
use rustc_middle::mir::visit::Visitor;
1539-
struct FakeReadCauseFinder<'a, 'tcx> {
1540-
place: &'a Place<'tcx>,
1539+
struct FakeReadCauseFinder<'tcx> {
1540+
place: Place<'tcx>,
15411541
cause: Option<FakeReadCause>,
15421542
}
1543-
impl<'tcx> Visitor<'tcx> for FakeReadCauseFinder<'_, 'tcx> {
1543+
impl<'tcx> Visitor<'tcx> for FakeReadCauseFinder<'tcx> {
15441544
fn visit_statement(&mut self, statement: &Statement<'tcx>, _: Location) {
15451545
match statement {
1546-
Statement { kind: StatementKind::FakeRead(cause, box ref place), .. }
1547-
if *place == *self.place =>
1546+
Statement { kind: StatementKind::FakeRead(cause, box place), .. }
1547+
if *place == self.place =>
15481548
{
15491549
self.cause = Some(*cause);
15501550
}

src/librustc_mir/borrow_check/diagnostics/move_errors.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
105105
// whether or not the right-hand side is a place expression
106106
if let LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(
107107
VarBindingForm {
108-
opt_match_place: Some((ref opt_match_place, match_span)),
108+
opt_match_place: Some((opt_match_place, match_span)),
109109
binding_mode: _,
110110
opt_ty_info: _,
111111
pat_span: _,
@@ -117,7 +117,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
117117
grouped_errors,
118118
kind,
119119
original_path,
120-
move_from,
120+
*move_from,
121121
local,
122122
opt_match_place,
123123
match_span,
@@ -143,16 +143,16 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
143143
grouped_errors: &mut Vec<GroupedMoveError<'tcx>>,
144144
kind: IllegalMoveOriginKind<'tcx>,
145145
original_path: Place<'tcx>,
146-
move_from: &Place<'tcx>,
146+
move_from: Place<'tcx>,
147147
bind_to: Local,
148-
match_place: &Option<Place<'tcx>>,
148+
match_place: Option<Place<'tcx>>,
149149
match_span: Span,
150150
statement_span: Span,
151151
) {
152152
debug!("append_binding_error(match_place={:?}, match_span={:?})", match_place, match_span);
153153

154154
let from_simple_let = match_place.is_none();
155-
let match_place = match_place.as_ref().unwrap_or(move_from);
155+
let match_place = match_place.unwrap_or(move_from);
156156

157157
match self.move_data.rev_lookup.find(match_place.as_ref()) {
158158
// Error with the match place
@@ -178,7 +178,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
178178
};
179179
grouped_errors.push(GroupedMoveError::MovesFromPlace {
180180
span,
181-
move_from: *match_place,
181+
move_from,
182182
original_path,
183183
kind,
184184
binds_to,
@@ -223,14 +223,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
223223
let (span, use_spans, original_path, kind): (
224224
Span,
225225
Option<UseSpans>,
226-
&Place<'tcx>,
226+
Place<'tcx>,
227227
&IllegalMoveOriginKind<'_>,
228228
) = match error {
229-
GroupedMoveError::MovesFromPlace { span, ref original_path, ref kind, .. }
230-
| GroupedMoveError::MovesFromValue { span, ref original_path, ref kind, .. } => {
229+
GroupedMoveError::MovesFromPlace { span, original_path, ref kind, .. }
230+
| GroupedMoveError::MovesFromValue { span, original_path, ref kind, .. } => {
231231
(span, None, original_path, kind)
232232
}
233-
GroupedMoveError::OtherIllegalMove { use_spans, ref original_path, ref kind } => {
233+
GroupedMoveError::OtherIllegalMove { use_spans, original_path, ref kind } => {
234234
(use_spans.args_or_use(), Some(use_spans), original_path, kind)
235235
}
236236
};
@@ -247,7 +247,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
247247
IllegalMoveOriginKind::BorrowedContent { target_place } => self
248248
.report_cannot_move_from_borrowed_content(
249249
original_path,
250-
target_place,
250+
*target_place,
251251
span,
252252
use_spans,
253253
),
@@ -268,7 +268,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
268268

269269
fn report_cannot_move_from_static(
270270
&mut self,
271-
place: &Place<'tcx>,
271+
place: Place<'tcx>,
272272
span: Span,
273273
) -> DiagnosticBuilder<'a> {
274274
let description = if place.projection.len() == 1 {
@@ -288,8 +288,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
288288

289289
fn report_cannot_move_from_borrowed_content(
290290
&mut self,
291-
move_place: &Place<'tcx>,
292-
deref_target_place: &Place<'tcx>,
291+
move_place: Place<'tcx>,
292+
deref_target_place: Place<'tcx>,
293293
span: Span,
294294
use_spans: Option<UseSpans>,
295295
) -> DiagnosticBuilder<'a> {

src/librustc_mir/dataflow/impls/borrowed_locals.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ where
160160

161161
match rvalue {
162162
mir::Rvalue::AddressOf(mt, borrowed_place) => {
163-
if !borrowed_place.is_indirect() && self.kind.in_address_of(*mt, borrowed_place) {
163+
if !borrowed_place.is_indirect() && self.kind.in_address_of(*mt, *borrowed_place) {
164164
self.trans.gen(borrowed_place.local);
165165
}
166166
}
167167

168168
mir::Rvalue::Ref(_, kind, borrowed_place) => {
169-
if !borrowed_place.is_indirect() && self.kind.in_ref(*kind, borrowed_place) {
169+
if !borrowed_place.is_indirect() && self.kind.in_ref(*kind, *borrowed_place) {
170170
self.trans.gen(borrowed_place.local);
171171
}
172172
}
@@ -230,33 +230,33 @@ impl MutBorrow<'mir, 'tcx> {
230230
/// below. See [rust-lang/unsafe-code-guidelines#134].
231231
///
232232
/// [rust-lang/unsafe-code-guidelines#134]: https://github.com/rust-lang/unsafe-code-guidelines/issues/134
233-
fn shared_borrow_allows_mutation(&self, place: &Place<'tcx>) -> bool {
233+
fn shared_borrow_allows_mutation(&self, place: Place<'tcx>) -> bool {
234234
!place.ty(self.body, self.tcx).ty.is_freeze(self.tcx, self.param_env, DUMMY_SP)
235235
}
236236
}
237237

238238
pub trait BorrowAnalysisKind<'tcx> {
239239
const ANALYSIS_NAME: &'static str;
240240

241-
fn in_address_of(&self, mt: Mutability, place: &Place<'tcx>) -> bool;
242-
fn in_ref(&self, kind: mir::BorrowKind, place: &Place<'tcx>) -> bool;
241+
fn in_address_of(&self, mt: Mutability, place: Place<'tcx>) -> bool;
242+
fn in_ref(&self, kind: mir::BorrowKind, place: Place<'tcx>) -> bool;
243243
}
244244

245245
impl BorrowAnalysisKind<'tcx> for AnyBorrow {
246246
const ANALYSIS_NAME: &'static str = "maybe_borrowed_locals";
247247

248-
fn in_ref(&self, _: mir::BorrowKind, _: &Place<'_>) -> bool {
248+
fn in_ref(&self, _: mir::BorrowKind, _: Place<'_>) -> bool {
249249
true
250250
}
251-
fn in_address_of(&self, _: Mutability, _: &Place<'_>) -> bool {
251+
fn in_address_of(&self, _: Mutability, _: Place<'_>) -> bool {
252252
true
253253
}
254254
}
255255

256256
impl BorrowAnalysisKind<'tcx> for MutBorrow<'mir, 'tcx> {
257257
const ANALYSIS_NAME: &'static str = "maybe_mut_borrowed_locals";
258258

259-
fn in_ref(&self, kind: mir::BorrowKind, place: &Place<'tcx>) -> bool {
259+
fn in_ref(&self, kind: mir::BorrowKind, place: Place<'tcx>) -> bool {
260260
match kind {
261261
mir::BorrowKind::Mut { .. } => true,
262262
mir::BorrowKind::Shared | mir::BorrowKind::Shallow | mir::BorrowKind::Unique => {
@@ -265,7 +265,7 @@ impl BorrowAnalysisKind<'tcx> for MutBorrow<'mir, 'tcx> {
265265
}
266266
}
267267

268-
fn in_address_of(&self, mt: Mutability, place: &Place<'tcx>) -> bool {
268+
fn in_address_of(&self, mt: Mutability, place: Place<'tcx>) -> bool {
269269
match mt {
270270
Mutability::Mut => true,
271271
Mutability::Not => self.shared_borrow_allows_mutation(place),

src/librustc_mir/dataflow/move_paths/builder.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
9494
/// problematic for borrowck.
9595
///
9696
/// Maybe we should have separate "borrowck" and "moveck" modes.
97-
fn move_path_for(&mut self, place: &Place<'tcx>) -> Result<MovePathIndex, MoveError<'tcx>> {
97+
fn move_path_for(&mut self, place: Place<'tcx>) -> Result<MovePathIndex, MoveError<'tcx>> {
9898
debug!("lookup({:?})", place);
9999
let mut base = self.builder.data.rev_lookup.locals[place.local];
100100

@@ -195,7 +195,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
195195
})
196196
}
197197

198-
fn create_move_path(&mut self, place: &Place<'tcx>) {
198+
fn create_move_path(&mut self, place: Place<'tcx>) {
199199
// This is an non-moving access (such as an overwrite or
200200
// drop), so this not being a valid move path is OK.
201201
let _ = self.move_path_for(place);
@@ -279,22 +279,22 @@ struct Gatherer<'b, 'a, 'tcx> {
279279

280280
impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
281281
fn gather_statement(&mut self, stmt: &Statement<'tcx>) {
282-
match stmt.kind {
283-
StatementKind::Assign(box (ref place, ref rval)) => {
284-
self.create_move_path(place);
282+
match &stmt.kind {
283+
StatementKind::Assign(box (place, rval)) => {
284+
self.create_move_path(*place);
285285
if let RvalueInitializationState::Shallow = rval.initialization_state() {
286286
// Box starts out uninitialized - need to create a separate
287287
// move-path for the interior so it will be separate from
288288
// the exterior.
289-
self.create_move_path(&self.builder.tcx.mk_place_deref(place.clone()));
289+
self.create_move_path(self.builder.tcx.mk_place_deref(place.clone()));
290290
self.gather_init(place.as_ref(), InitKind::Shallow);
291291
} else {
292292
self.gather_init(place.as_ref(), InitKind::Deep);
293293
}
294294
self.gather_rvalue(rval);
295295
}
296-
StatementKind::FakeRead(_, ref place) => {
297-
self.create_move_path(place);
296+
StatementKind::FakeRead(_, place) => {
297+
self.create_move_path(**place);
298298
}
299299
StatementKind::LlvmInlineAsm(ref asm) => {
300300
for (output, kind) in asm.outputs.iter().zip(&asm.asm.outputs) {
@@ -308,7 +308,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
308308
}
309309
StatementKind::StorageLive(_) => {}
310310
StatementKind::StorageDead(local) => {
311-
self.gather_move(&Place::from(local));
311+
self.gather_move(Place::from(*local));
312312
}
313313
StatementKind::SetDiscriminant { .. } => {
314314
span_bug!(
@@ -369,7 +369,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
369369
| TerminatorKind::Unreachable => {}
370370

371371
TerminatorKind::Return => {
372-
self.gather_move(&Place::return_place());
372+
self.gather_move(Place::return_place());
373373
}
374374

375375
TerminatorKind::Assert { ref cond, .. } => {
@@ -380,16 +380,16 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
380380
self.gather_operand(discr);
381381
}
382382

383-
TerminatorKind::Yield { ref value, resume_arg: ref place, .. } => {
383+
TerminatorKind::Yield { ref value, resume_arg: place, .. } => {
384384
self.gather_operand(value);
385385
self.create_move_path(place);
386386
self.gather_init(place.as_ref(), InitKind::Deep);
387387
}
388388

389-
TerminatorKind::Drop { ref location, target: _, unwind: _ } => {
389+
TerminatorKind::Drop { location, target: _, unwind: _ } => {
390390
self.gather_move(location);
391391
}
392-
TerminatorKind::DropAndReplace { ref location, ref value, .. } => {
392+
TerminatorKind::DropAndReplace { location, ref value, .. } => {
393393
self.create_move_path(location);
394394
self.gather_operand(value);
395395
self.gather_init(location.as_ref(), InitKind::Deep);
@@ -405,7 +405,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
405405
for arg in args {
406406
self.gather_operand(arg);
407407
}
408-
if let Some((ref destination, _bb)) = *destination {
408+
if let Some((destination, _bb)) = *destination {
409409
self.create_move_path(destination);
410410
self.gather_init(destination.as_ref(), InitKind::NonPanicPathOnly);
411411
}
@@ -416,14 +416,14 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
416416
fn gather_operand(&mut self, operand: &Operand<'tcx>) {
417417
match *operand {
418418
Operand::Constant(..) | Operand::Copy(..) => {} // not-a-move
419-
Operand::Move(ref place) => {
419+
Operand::Move(place) => {
420420
// a move
421421
self.gather_move(place);
422422
}
423423
}
424424
}
425425

426-
fn gather_move(&mut self, place: &Place<'tcx>) {
426+
fn gather_move(&mut self, place: Place<'tcx>) {
427427
debug!("gather_move({:?}, {:?})", self.loc, place);
428428

429429
if let [ref base @ .., ProjectionElem::Subslice { from, to, from_end: false }] =
@@ -434,7 +434,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
434434
// are disjoint, which is expected by drop elaboration.
435435
let base_place =
436436
Place { local: place.local, projection: self.builder.tcx.intern_place_elems(base) };
437-
let base_path = match self.move_path_for(&base_place) {
437+
let base_path = match self.move_path_for(base_place) {
438438
Ok(path) => path,
439439
Err(MoveError::UnionMove { path }) => {
440440
self.record_move(place, path);
@@ -467,13 +467,13 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
467467
match self.move_path_for(place) {
468468
Ok(path) | Err(MoveError::UnionMove { path }) => self.record_move(place, path),
469469
Err(error @ MoveError::IllegalMove { .. }) => {
470-
self.builder.errors.push((*place, error));
470+
self.builder.errors.push((place, error));
471471
}
472472
};
473473
}
474474
}
475475

476-
fn record_move(&mut self, place: &Place<'tcx>, path: MovePathIndex) {
476+
fn record_move(&mut self, place: Place<'tcx>, path: MovePathIndex) {
477477
let move_out = self.builder.data.moves.push(MoveOut { path, source: self.loc });
478478
debug!(
479479
"gather_move({:?}, {:?}): adding move {:?} of {:?}",

src/librustc_mir/interpret/operand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
464464
// avoid allocations.
465465
pub fn eval_place_to_op(
466466
&self,
467-
place: &mir::Place<'tcx>,
467+
place: mir::Place<'tcx>,
468468
layout: Option<TyAndLayout<'tcx>>,
469469
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
470470
let base_op = match place.local {
@@ -498,7 +498,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
498498
use rustc_middle::mir::Operand::*;
499499
let op = match *mir_op {
500500
// FIXME: do some more logic on `move` to invalidate the old location
501-
Copy(ref place) | Move(ref place) => self.eval_place_to_op(place, layout)?,
501+
Copy(place) | Move(place) => self.eval_place_to_op(place, layout)?,
502502

503503
Constant(ref constant) => {
504504
let val =

src/librustc_mir/interpret/place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ where
635635
/// place; for reading, a more efficient alternative is `eval_place_for_read`.
636636
pub fn eval_place(
637637
&mut self,
638-
place: &mir::Place<'tcx>,
638+
place: mir::Place<'tcx>,
639639
) -> InterpResult<'tcx, PlaceTy<'tcx, M::PointerTag>> {
640640
let mut place_ty = match place.local {
641641
mir::RETURN_PLACE => {

0 commit comments

Comments
 (0)