Skip to content

Commit 9223bb5

Browse files
authored
Rollup merge of #70627 - spastorino:use-place-directly-its-copy, r=oli-obk
Use place directly its copy r? @oli-obk
2 parents 43119de + b46754e commit 9223bb5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+354
-371
lines changed

src/librustc_codegen_ssa/mir/block.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
299299
&mut self,
300300
helper: TerminatorCodegenHelper<'tcx>,
301301
mut bx: Bx,
302-
location: &mir::Place<'tcx>,
302+
location: mir::Place<'tcx>,
303303
target: mir::BasicBlock,
304304
unwind: Option<mir::BasicBlock>,
305305
) {
@@ -580,7 +580,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
580580

581581
if intrinsic == Some("transmute") {
582582
if let Some(destination_ref) = destination.as_ref() {
583-
let &(ref dest, target) = destination_ref;
583+
let &(dest, target) = destination_ref;
584584
self.codegen_transmute(&mut bx, &args[0], dest);
585585
helper.maybe_sideeffect(self.mir, &mut bx, &[target]);
586586
helper.funclet_br(self, &mut bx, target);
@@ -619,7 +619,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
619619
let mut llargs = Vec::with_capacity(arg_count);
620620

621621
// Prepare the return value destination
622-
let ret_dest = if let Some((ref dest, _)) = *destination {
622+
let ret_dest = if let Some((dest, _)) = *destination {
623623
let is_intrinsic = intrinsic.is_some();
624624
self.make_return_dest(&mut bx, dest, &fn_abi.ret, &mut llargs, is_intrinsic)
625625
} else {
@@ -873,7 +873,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
873873
bx.unreachable();
874874
}
875875

876-
mir::TerminatorKind::Drop { ref location, target, unwind } => {
876+
mir::TerminatorKind::Drop { location, target, unwind } => {
877877
self.codegen_drop_terminator(helper, bx, location, target, unwind);
878878
}
879879

@@ -1123,7 +1123,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11231123
fn make_return_dest(
11241124
&mut self,
11251125
bx: &mut Bx,
1126-
dest: &mir::Place<'tcx>,
1126+
dest: mir::Place<'tcx>,
11271127
fn_ret: &ArgAbi<'tcx, Ty<'tcx>>,
11281128
llargs: &mut Vec<Bx::Value>,
11291129
is_intrinsic: bool,
@@ -1184,7 +1184,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11841184
}
11851185
}
11861186

1187-
fn codegen_transmute(&mut self, bx: &mut Bx, src: &mir::Operand<'tcx>, dst: &mir::Place<'tcx>) {
1187+
fn codegen_transmute(&mut self, bx: &mut Bx, src: &mir::Operand<'tcx>, dst: mir::Place<'tcx>) {
11881188
if let Some(index) = dst.as_local() {
11891189
match self.locals[index] {
11901190
LocalRef::Place(place) => self.codegen_transmute_into(bx, src, place),

src/librustc_codegen_ssa/mir/rvalue.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
383383
(bx, OperandRef { val, layout: cast })
384384
}
385385

386-
mir::Rvalue::Ref(_, bk, ref place) => {
386+
mir::Rvalue::Ref(_, bk, place) => {
387387
let mk_ref = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| {
388388
tcx.mk_ref(
389389
tcx.lifetimes.re_erased,
@@ -393,14 +393,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
393393
self.codegen_place_to_pointer(bx, place, mk_ref)
394394
}
395395

396-
mir::Rvalue::AddressOf(mutability, ref place) => {
396+
mir::Rvalue::AddressOf(mutability, place) => {
397397
let mk_ptr = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| {
398398
tcx.mk_ptr(ty::TypeAndMut { ty, mutbl: mutability })
399399
};
400400
self.codegen_place_to_pointer(bx, place, mk_ptr)
401401
}
402402

403-
mir::Rvalue::Len(ref place) => {
403+
mir::Rvalue::Len(place) => {
404404
let size = self.evaluate_array_len(&mut bx, place);
405405
let operand = OperandRef {
406406
val: OperandValue::Immediate(size),
@@ -537,7 +537,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
537537
}
538538
}
539539

540-
fn evaluate_array_len(&mut self, bx: &mut Bx, place: &mir::Place<'tcx>) -> Bx::Value {
540+
fn evaluate_array_len(&mut self, bx: &mut Bx, place: mir::Place<'tcx>) -> Bx::Value {
541541
// ZST are passed as operands and require special handling
542542
// because codegen_place() panics if Local is operand.
543543
if let Some(index) = place.as_local() {
@@ -557,7 +557,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
557557
fn codegen_place_to_pointer(
558558
&mut self,
559559
mut bx: Bx,
560-
place: &mir::Place<'tcx>,
560+
place: mir::Place<'tcx>,
561561
mk_ptr_ty: impl FnOnce(TyCtxt<'tcx>, Ty<'tcx>) -> Ty<'tcx>,
562562
) -> (Bx, OperandRef<'tcx, Bx::Value>) {
563563
let cg_place = self.codegen_place(&mut bx, place.as_ref());

src/librustc_middle/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2030,9 +2030,9 @@ impl<'tcx> Operand<'tcx> {
20302030

20312031
/// Returns the `Place` that is the target of this `Operand`, or `None` if this `Operand` is a
20322032
/// constant.
2033-
pub fn place(&self) -> Option<&Place<'tcx>> {
2033+
pub fn place(&self) -> Option<Place<'tcx>> {
20342034
match self {
2035-
Operand::Copy(place) | Operand::Move(place) => Some(place),
2035+
Operand::Copy(place) | Operand::Move(place) => Some(*place),
20362036
Operand::Constant(_) => None,
20372037
}
20382038
}

src/librustc_mir/borrow_check/borrow_set.rs

+1-1
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

+4-4
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

+26-31
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 { "" };
@@ -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[..])
@@ -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,15 +1374,15 @@ 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);
13861381
let loan_span = loan_spans.args_or_use();
13871382

13881383
let descr_place = self.describe_any_place(place.as_ref());
13891384
if loan.kind == BorrowKind::Shallow {
1390-
if let Some(section) = self.classify_immutable_section(&loan.assigned_place) {
1385+
if let Some(section) = self.classify_immutable_section(loan.assigned_place) {
13911386
let mut err = self.cannot_mutate_in_immutable_section(
13921387
span,
13931388
loan_span,
@@ -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) => (
@@ -1539,17 +1534,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15391534
}
15401535

15411536
/// Describe the reason for the fake borrow that was assigned to `place`.
1542-
fn classify_immutable_section(&self, place: &Place<'tcx>) -> Option<&'static str> {
1537+
fn classify_immutable_section(&self, place: Place<'tcx>) -> Option<&'static str> {
15431538
use rustc_middle::mir::visit::Visitor;
1544-
struct FakeReadCauseFinder<'a, 'tcx> {
1545-
place: &'a Place<'tcx>,
1539+
struct FakeReadCauseFinder<'tcx> {
1540+
place: Place<'tcx>,
15461541
cause: Option<FakeReadCause>,
15471542
}
1548-
impl<'tcx> Visitor<'tcx> for FakeReadCauseFinder<'_, 'tcx> {
1543+
impl<'tcx> Visitor<'tcx> for FakeReadCauseFinder<'tcx> {
15491544
fn visit_statement(&mut self, statement: &Statement<'tcx>, _: Location) {
15501545
match statement {
1551-
Statement { kind: StatementKind::FakeRead(cause, box ref place), .. }
1552-
if *place == *self.place =>
1546+
Statement { kind: StatementKind::FakeRead(cause, box place), .. }
1547+
if *place == self.place =>
15531548
{
15541549
self.cause = Some(*cause);
15551550
}

src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs

+1-1
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={:?})",

0 commit comments

Comments
 (0)