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

Commit d45dca3

Browse files
committed
Use Place directly, it's Copy
1 parent 75ff311 commit d45dca3

File tree

10 files changed

+88
-94
lines changed

10 files changed

+88
-94
lines changed

src/librustc_mir/borrow_check/borrow_set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> {
206206
let idx = self.idx_vec.push(borrow);
207207
self.location_map.insert(location, idx);
208208

209-
self.insert_as_pending_if_two_phase(location, &assigned_place, kind, idx);
209+
self.insert_as_pending_if_two_phase(location, assigned_place, kind, idx);
210210

211211
self.local_map.entry(borrowed_place.local).or_default().insert(idx);
212212
}

src/librustc_mir/borrow_check/constraint_generation.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'cg, 'cx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'tcx> {
114114
fn visit_assign(&mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) {
115115
// When we see `X = ...`, then kill borrows of
116116
// `(*X).foo` and so forth.
117-
self.record_killed_borrows_for_place(place, location);
117+
self.record_killed_borrows_for_place(*place, location);
118118

119119
self.super_assign(place, rvalue, location);
120120
}
@@ -139,7 +139,7 @@ impl<'cg, 'cx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'tcx> {
139139

140140
// A `Call` terminator's return value can be a local which has borrows,
141141
// so we need to record those as `killed` as well.
142-
if let TerminatorKind::Call { ref destination, .. } = terminator.kind {
142+
if let TerminatorKind::Call { destination, .. } = terminator.kind {
143143
if let Some((place, _)) = destination {
144144
self.record_killed_borrows_for_place(place, location);
145145
}
@@ -177,7 +177,7 @@ impl<'cx, 'cg, 'tcx> ConstraintGeneration<'cx, 'cg, 'tcx> {
177177

178178
/// When recording facts for Polonius, records the borrows on the specified place
179179
/// as `killed`. For example, when assigning to a local, or on a call's return destination.
180-
fn record_killed_borrows_for_place(&mut self, place: &Place<'tcx>, location: Location) {
180+
fn record_killed_borrows_for_place(&mut self, place: Place<'tcx>, location: Location) {
181181
if let Some(all_facts) = self.all_facts {
182182
let _prof_timer = self.infcx.tcx.prof.generic_activity("polonius_fact_generation");
183183

@@ -217,7 +217,7 @@ impl<'cx, 'cg, 'tcx> ConstraintGeneration<'cx, 'cg, 'tcx> {
217217
let places_conflict = places_conflict::places_conflict(
218218
self.infcx.tcx,
219219
self.body,
220-
&self.borrow_set.borrows[borrow_index].borrowed_place,
220+
self.borrow_set.borrows[borrow_index].borrowed_place,
221221
place,
222222
places_conflict::PlaceConflictBias::NoOverlap,
223223
);

src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
247247
pub(in crate::borrow_check) fn report_move_out_while_borrowed(
248248
&mut self,
249249
location: Location,
250-
(place, span): (&Place<'tcx>, Span),
250+
(place, span): (Place<'tcx>, Span),
251251
borrow: &BorrowData<'tcx>,
252252
) {
253253
debug!(
@@ -291,7 +291,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
291291
pub(in crate::borrow_check) fn report_use_while_mutably_borrowed(
292292
&mut self,
293293
location: Location,
294-
(place, _span): (&Place<'tcx>, Span),
294+
(place, _span): (Place<'tcx>, Span),
295295
borrow: &BorrowData<'tcx>,
296296
) -> DiagnosticBuilder<'cx> {
297297
let borrow_spans = self.retrieve_borrow_spans(borrow);
@@ -330,7 +330,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
330330
pub(in crate::borrow_check) fn report_conflicting_borrow(
331331
&mut self,
332332
location: Location,
333-
(place, span): (&Place<'tcx>, Span),
333+
(place, span): (Place<'tcx>, Span),
334334
gen_borrow_kind: BorrowKind,
335335
issued_borrow: &BorrowData<'tcx>,
336336
) -> DiagnosticBuilder<'cx> {
@@ -347,7 +347,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
347347
};
348348

349349
let (desc_place, msg_place, msg_borrow, union_type_name) =
350-
self.describe_place_for_conflicting_borrow(place, &issued_borrow.borrowed_place);
350+
self.describe_place_for_conflicting_borrow(place, issued_borrow.borrowed_place);
351351

352352
let explanation = self.explain_why_borrow_contains_point(location, issued_borrow, None);
353353
let second_borrow_desc = if explanation.is_explained() { "second " } else { "" };
@@ -584,8 +584,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
584584
/// > mutable (via `a.u.s.b`) [E0502]
585585
pub(in crate::borrow_check) fn describe_place_for_conflicting_borrow(
586586
&self,
587-
first_borrowed_place: &Place<'tcx>,
588-
second_borrowed_place: &Place<'tcx>,
587+
first_borrowed_place: Place<'tcx>,
588+
second_borrowed_place: Place<'tcx>,
589589
) -> (String, String, String, String) {
590590
// Define a small closure that we can use to check if the type of a place
591591
// is a union.
@@ -615,13 +615,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
615615
cursor = proj_base;
616616

617617
match elem {
618-
ProjectionElem::Field(field, _)
619-
if union_ty(*local, proj_base).is_some() =>
620-
{
621-
return Some((
622-
PlaceRef { local: *local, projection: proj_base },
623-
field,
624-
));
618+
ProjectionElem::Field(field, _) if union_ty(local, proj_base).is_some() => {
619+
return Some((PlaceRef { local, projection: proj_base }, field));
625620
}
626621
_ => {}
627622
}
@@ -631,7 +626,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
631626
.and_then(|(target_base, target_field)| {
632627
// With the place of a union and a field access into it, we traverse the second
633628
// borrowed place and look for a access to a different field of the same union.
634-
let Place { local, ref projection } = *second_borrowed_place;
629+
let Place { local, ref projection } = second_borrowed_place;
635630

636631
let mut cursor = &projection[..];
637632
while let [proj_base @ .., elem] = cursor {
@@ -682,7 +677,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
682677
&mut self,
683678
location: Location,
684679
borrow: &BorrowData<'tcx>,
685-
place_span: (&Place<'tcx>, Span),
680+
place_span: (Place<'tcx>, Span),
686681
kind: Option<WriteKind>,
687682
) {
688683
debug!(
@@ -967,7 +962,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
967962
&mut self,
968963
location: Location,
969964
borrow: &BorrowData<'tcx>,
970-
(place, drop_span): (&Place<'tcx>, Span),
965+
(place, drop_span): (Place<'tcx>, Span),
971966
kind: Option<WriteKind>,
972967
dropped_ty: Ty<'tcx>,
973968
) {
@@ -1379,7 +1374,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13791374
pub(in crate::borrow_check) fn report_illegal_mutation_of_borrowed(
13801375
&mut self,
13811376
location: Location,
1382-
(place, span): (&Place<'tcx>, Span),
1377+
(place, span): (Place<'tcx>, Span),
13831378
loan: &BorrowData<'tcx>,
13841379
) {
13851380
let loan_spans = self.retrieve_borrow_spans(loan);
@@ -1432,9 +1427,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14321427
pub(in crate::borrow_check) fn report_illegal_reassignment(
14331428
&mut self,
14341429
_location: Location,
1435-
(place, span): (&Place<'tcx>, Span),
1430+
(place, span): (Place<'tcx>, Span),
14361431
assigned_span: Span,
1437-
err_place: &Place<'tcx>,
1432+
err_place: Place<'tcx>,
14381433
) {
14391434
let (from_arg, local_decl, local_name) = match err_place.as_local() {
14401435
Some(local) => (

src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
286286
&self,
287287
location: Location,
288288
borrow: &BorrowData<'tcx>,
289-
kind_place: Option<(WriteKind, &Place<'tcx>)>,
289+
kind_place: Option<(WriteKind, Place<'tcx>)>,
290290
) -> BorrowExplanation {
291291
debug!(
292292
"explain_why_borrow_contains_point(location={:?}, borrow={:?}, kind_place={:?})",

src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(crate) enum AccessKind {
2222
impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
2323
pub(crate) fn report_mutability_error(
2424
&mut self,
25-
access_place: &Place<'tcx>,
25+
access_place: Place<'tcx>,
2626
span: Span,
2727
the_place_err: PlaceRef<'tcx>,
2828
error_access: AccessKind,

src/librustc_mir/borrow_check/invalidation.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,33 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
5656
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
5757
self.check_activations(location);
5858

59-
match statement.kind {
60-
StatementKind::Assign(box (ref lhs, ref rhs)) => {
59+
match &statement.kind {
60+
StatementKind::Assign(box (lhs, rhs)) => {
6161
self.consume_rvalue(location, rhs);
6262

63-
self.mutate_place(location, lhs, Shallow(None), JustWrite);
63+
self.mutate_place(location, *lhs, Shallow(None), JustWrite);
6464
}
6565
StatementKind::FakeRead(_, _) => {
6666
// Only relevant for initialized/liveness/safety checks.
6767
}
68-
StatementKind::SetDiscriminant { ref place, variant_index: _ } => {
69-
self.mutate_place(location, place, Shallow(None), JustWrite);
68+
StatementKind::SetDiscriminant { place, variant_index: _ } => {
69+
self.mutate_place(location, **place, Shallow(None), JustWrite);
7070
}
71-
StatementKind::LlvmInlineAsm(ref asm) => {
71+
StatementKind::LlvmInlineAsm(asm) => {
7272
for (o, output) in asm.asm.outputs.iter().zip(asm.outputs.iter()) {
7373
if o.is_indirect {
7474
// FIXME(eddyb) indirect inline asm outputs should
7575
// be encoded through MIR place derefs instead.
7676
self.access_place(
7777
location,
78-
output,
78+
*output,
7979
(Deep, Read(ReadKind::Copy)),
8080
LocalMutationIsAllowed::No,
8181
);
8282
} else {
8383
self.mutate_place(
8484
location,
85-
output,
85+
*output,
8686
if o.is_rw { Deep } else { Shallow(None) },
8787
if o.is_rw { WriteAndRead } else { JustWrite },
8888
);
@@ -102,7 +102,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
102102
StatementKind::StorageDead(local) => {
103103
self.access_place(
104104
location,
105-
&Place::from(local),
105+
Place::from(*local),
106106
(Shallow(None), Write(WriteKind::StorageDeadOrDrop)),
107107
LocalMutationIsAllowed::Yes,
108108
);
@@ -119,36 +119,36 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
119119
TerminatorKind::SwitchInt { ref discr, switch_ty: _, values: _, targets: _ } => {
120120
self.consume_operand(location, discr);
121121
}
122-
TerminatorKind::Drop { location: ref drop_place, target: _, unwind: _ } => {
122+
TerminatorKind::Drop { location: drop_place, target: _, unwind: _ } => {
123123
self.access_place(
124124
location,
125-
drop_place,
125+
*drop_place,
126126
(AccessDepth::Drop, Write(WriteKind::StorageDeadOrDrop)),
127127
LocalMutationIsAllowed::Yes,
128128
);
129129
}
130130
TerminatorKind::DropAndReplace {
131-
location: ref drop_place,
131+
location: drop_place,
132132
value: ref new_value,
133133
target: _,
134134
unwind: _,
135135
} => {
136-
self.mutate_place(location, drop_place, Deep, JustWrite);
136+
self.mutate_place(location, *drop_place, Deep, JustWrite);
137137
self.consume_operand(location, new_value);
138138
}
139139
TerminatorKind::Call {
140140
ref func,
141141
ref args,
142-
ref destination,
142+
destination,
143143
cleanup: _,
144144
from_hir_call: _,
145145
} => {
146146
self.consume_operand(location, func);
147147
for arg in args {
148148
self.consume_operand(location, arg);
149149
}
150-
if let Some((ref dest, _ /*bb*/)) = *destination {
151-
self.mutate_place(location, dest, Deep, JustWrite);
150+
if let Some((dest, _ /*bb*/)) = destination {
151+
self.mutate_place(location, *dest, Deep, JustWrite);
152152
}
153153
}
154154
TerminatorKind::Assert { ref cond, expected: _, ref msg, target: _, cleanup: _ } => {
@@ -171,7 +171,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
171171
}
172172
}
173173

174-
self.mutate_place(location, resume_arg, Deep, JustWrite);
174+
self.mutate_place(location, *resume_arg, Deep, JustWrite);
175175
}
176176
TerminatorKind::Resume | TerminatorKind::Return | TerminatorKind::GeneratorDrop => {
177177
// Invalidate all borrows of local places
@@ -201,7 +201,7 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
201201
fn mutate_place(
202202
&mut self,
203203
location: Location,
204-
place: &Place<'tcx>,
204+
place: Place<'tcx>,
205205
kind: AccessDepth,
206206
_mode: MutateMode,
207207
) {
@@ -216,15 +216,15 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
216216
/// Simulates consumption of an operand.
217217
fn consume_operand(&mut self, location: Location, operand: &Operand<'tcx>) {
218218
match *operand {
219-
Operand::Copy(ref place) => {
219+
Operand::Copy(place) => {
220220
self.access_place(
221221
location,
222222
place,
223223
(Deep, Read(ReadKind::Copy)),
224224
LocalMutationIsAllowed::No,
225225
);
226226
}
227-
Operand::Move(ref place) => {
227+
Operand::Move(place) => {
228228
self.access_place(
229229
location,
230230
place,
@@ -239,7 +239,7 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
239239
// Simulates consumption of an rvalue
240240
fn consume_rvalue(&mut self, location: Location, rvalue: &Rvalue<'tcx>) {
241241
match *rvalue {
242-
Rvalue::Ref(_ /*rgn*/, bk, ref place) => {
242+
Rvalue::Ref(_ /*rgn*/, bk, place) => {
243243
let access_kind = match bk {
244244
BorrowKind::Shallow => {
245245
(Shallow(Some(ArtificialField::ShallowBorrow)), Read(ReadKind::Borrow(bk)))
@@ -258,7 +258,7 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
258258
self.access_place(location, place, access_kind, LocalMutationIsAllowed::No);
259259
}
260260

261-
Rvalue::AddressOf(mutability, ref place) => {
261+
Rvalue::AddressOf(mutability, place) => {
262262
let access_kind = match mutability {
263263
Mutability::Mut => (
264264
Deep,
@@ -279,7 +279,7 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
279279
self.consume_operand(location, operand)
280280
}
281281

282-
Rvalue::Len(ref place) | Rvalue::Discriminant(ref place) => {
282+
Rvalue::Len(place) | Rvalue::Discriminant(place) => {
283283
let af = match *rvalue {
284284
Rvalue::Len(..) => Some(ArtificialField::ArrayLength),
285285
Rvalue::Discriminant(..) => None,
@@ -313,7 +313,7 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
313313
fn access_place(
314314
&mut self,
315315
location: Location,
316-
place: &Place<'tcx>,
316+
place: Place<'tcx>,
317317
kind: (AccessDepth, ReadOrWrite),
318318
_is_local_mutation_allowed: LocalMutationIsAllowed,
319319
) {
@@ -325,7 +325,7 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
325325
fn check_access_for_conflict(
326326
&mut self,
327327
location: Location,
328-
place: &Place<'tcx>,
328+
place: Place<'tcx>,
329329
sd: AccessDepth,
330330
rw: ReadOrWrite,
331331
) {
@@ -413,7 +413,7 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
413413

414414
self.access_place(
415415
location,
416-
&borrow.borrowed_place,
416+
borrow.borrowed_place,
417417
(Deep, Activation(WriteKind::MutableBorrow(borrow.kind), borrow_index)),
418418
LocalMutationIsAllowed::No,
419419
);

0 commit comments

Comments
 (0)