Skip to content

Commit 343432a

Browse files
committed
Auto merge of #68512 - spastorino:local-is-copy, r=oli-obk
Local is copy r? @oli-obk
2 parents d55f3e9 + 3021856 commit 343432a

31 files changed

+134
-130
lines changed

src/librustc/mir/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,7 @@ rustc_index::newtype_index! {
17731773

17741774
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
17751775
pub struct PlaceRef<'a, 'tcx> {
1776-
pub local: &'a Local,
1776+
pub local: Local,
17771777
pub projection: &'a [PlaceElem<'tcx>],
17781778
}
17791779

@@ -1797,8 +1797,8 @@ impl<'tcx> Place<'tcx> {
17971797
// FIXME: can we safely swap the semantics of `fn base_local` below in here instead?
17981798
pub fn local_or_deref_local(&self) -> Option<Local> {
17991799
match self.as_ref() {
1800-
PlaceRef { local, projection: &[] }
1801-
| PlaceRef { local, projection: &[ProjectionElem::Deref] } => Some(*local),
1800+
PlaceRef { local, projection: [] }
1801+
| PlaceRef { local, projection: [ProjectionElem::Deref] } => Some(local),
18021802
_ => None,
18031803
}
18041804
}
@@ -1810,7 +1810,7 @@ impl<'tcx> Place<'tcx> {
18101810
}
18111811

18121812
pub fn as_ref(&self) -> PlaceRef<'_, 'tcx> {
1813-
PlaceRef { local: &self.local, projection: &self.projection }
1813+
PlaceRef { local: self.local, projection: &self.projection }
18141814
}
18151815
}
18161816

@@ -1826,18 +1826,18 @@ impl<'a, 'tcx> PlaceRef<'a, 'tcx> {
18261826
//
18271827
// FIXME: can we safely swap the semantics of `fn base_local` below in here instead?
18281828
pub fn local_or_deref_local(&self) -> Option<Local> {
1829-
match self {
1829+
match *self {
18301830
PlaceRef { local, projection: [] }
1831-
| PlaceRef { local, projection: [ProjectionElem::Deref] } => Some(**local),
1831+
| PlaceRef { local, projection: [ProjectionElem::Deref] } => Some(local),
18321832
_ => None,
18331833
}
18341834
}
18351835

18361836
/// If this place represents a local variable like `_X` with no
18371837
/// projections, return `Some(_X)`.
18381838
pub fn as_local(&self) -> Option<Local> {
1839-
match self {
1840-
PlaceRef { local, projection: [] } => Some(**local),
1839+
match *self {
1840+
PlaceRef { local, projection: [] } => Some(local),
18411841
_ => None,
18421842
}
18431843
}

src/librustc/mir/tcx.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'tcx> PlaceTy<'tcx> {
114114

115115
impl<'tcx> Place<'tcx> {
116116
pub fn ty_from<D>(
117-
local: &Local,
117+
local: Local,
118118
projection: &[PlaceElem<'tcx>],
119119
local_decls: &D,
120120
tcx: TyCtxt<'tcx>,
@@ -124,7 +124,7 @@ impl<'tcx> Place<'tcx> {
124124
{
125125
projection
126126
.iter()
127-
.fold(PlaceTy::from_ty(local_decls.local_decls()[*local].ty), |place_ty, elem| {
127+
.fold(PlaceTy::from_ty(local_decls.local_decls()[local].ty), |place_ty, elem| {
128128
place_ty.projection_ty(tcx, elem)
129129
})
130130
}
@@ -133,7 +133,7 @@ impl<'tcx> Place<'tcx> {
133133
where
134134
D: HasLocalDecls<'tcx>,
135135
{
136-
Place::ty_from(&self.local, &self.projection, local_decls, tcx)
136+
Place::ty_from(self.local, &self.projection, local_decls, tcx)
137137
}
138138
}
139139

src/librustc_codegen_ssa/mir/analyze.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
134134
// ZSTs don't require any actual memory access.
135135
let elem_ty = base_ty.projection_ty(cx.tcx(), elem).ty;
136136
let elem_ty = self.fx.monomorphize(&elem_ty);
137-
let span = self.fx.mir.local_decls[*place_ref.local].source_info.span;
137+
let span = self.fx.mir.local_decls[place_ref.local].source_info.span;
138138
if cx.spanned_layout_of(elem_ty, span).is_zst() {
139139
return;
140140
}
@@ -174,7 +174,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
174174
// We use `NonUseContext::VarDebugInfo` for the base,
175175
// which might not force the base local to memory,
176176
// so we have to do it manually.
177-
self.visit_local(place_ref.local, context, location);
177+
self.visit_local(&place_ref.local, context, location);
178178
}
179179
}
180180

@@ -212,8 +212,8 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
212212
};
213213
}
214214

215-
self.visit_place_base(place_ref.local, context, location);
216-
self.visit_projection(place_ref.local, place_ref.projection, context, location);
215+
self.visit_place_base(&place_ref.local, context, location);
216+
self.visit_projection(&place_ref.local, place_ref.projection, context, location);
217217
}
218218
}
219219
}

src/librustc_codegen_ssa/mir/block.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
264264
}
265265

266266
PassMode::Direct(_) | PassMode::Pair(..) => {
267-
let op = self.codegen_consume(&mut bx, &mir::Place::return_place().as_ref());
267+
let op = self.codegen_consume(&mut bx, mir::Place::return_place().as_ref());
268268
if let Ref(llval, _, align) = op.val {
269269
bx.load(llval, align)
270270
} else {
@@ -319,7 +319,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
319319
return;
320320
}
321321

322-
let place = self.codegen_place(&mut bx, &location.as_ref());
322+
let place = self.codegen_place(&mut bx, location.as_ref());
323323
let (args1, args2);
324324
let mut args = if let Some(llextra) = place.llextra {
325325
args2 = [place.llval, llextra];
@@ -1111,7 +1111,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11111111
} else {
11121112
self.codegen_place(
11131113
bx,
1114-
&mir::PlaceRef { local: &dest.local, projection: &dest.projection },
1114+
mir::PlaceRef { local: dest.local, projection: &dest.projection },
11151115
)
11161116
};
11171117
if fn_ret.is_indirect() {
@@ -1137,7 +1137,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11371137
LocalRef::Place(place) => self.codegen_transmute_into(bx, src, place),
11381138
LocalRef::UnsizedPlace(_) => bug!("transmute must not involve unsized locals"),
11391139
LocalRef::Operand(None) => {
1140-
let dst_layout = bx.layout_of(self.monomorphized_place_ty(&dst.as_ref()));
1140+
let dst_layout = bx.layout_of(self.monomorphized_place_ty(dst.as_ref()));
11411141
assert!(!dst_layout.ty.has_erasable_regions());
11421142
let place = PlaceRef::alloca(bx, dst_layout);
11431143
place.storage_live(bx);
@@ -1151,7 +1151,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11511151
}
11521152
}
11531153
} else {
1154-
let dst = self.codegen_place(bx, &dst.as_ref());
1154+
let dst = self.codegen_place(bx, dst.as_ref());
11551155
self.codegen_transmute_into(bx, src, dst);
11561156
}
11571157
}

src/librustc_codegen_ssa/mir/operand.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
369369
fn maybe_codegen_consume_direct(
370370
&mut self,
371371
bx: &mut Bx,
372-
place_ref: &mir::PlaceRef<'_, 'tcx>,
372+
place_ref: mir::PlaceRef<'_, 'tcx>,
373373
) -> Option<OperandRef<'tcx, Bx::Value>> {
374374
debug!("maybe_codegen_consume_direct(place_ref={:?})", place_ref);
375375

376-
match self.locals[*place_ref.local] {
376+
match self.locals[place_ref.local] {
377377
LocalRef::Operand(Some(mut o)) => {
378378
// Moves out of scalar and scalar pair fields are trivial.
379379
for elem in place_ref.projection.iter() {
@@ -413,7 +413,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
413413
pub fn codegen_consume(
414414
&mut self,
415415
bx: &mut Bx,
416-
place_ref: &mir::PlaceRef<'_, 'tcx>,
416+
place_ref: mir::PlaceRef<'_, 'tcx>,
417417
) -> OperandRef<'tcx, Bx::Value> {
418418
debug!("codegen_consume(place_ref={:?})", place_ref);
419419

@@ -444,7 +444,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
444444

445445
match *operand {
446446
mir::Operand::Copy(ref place) | mir::Operand::Move(ref place) => {
447-
self.codegen_consume(bx, &place.as_ref())
447+
self.codegen_consume(bx, place.as_ref())
448448
}
449449

450450
mir::Operand::Constant(ref constant) => {

src/librustc_codegen_ssa/mir/place.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -408,14 +408,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
408408
pub fn codegen_place(
409409
&mut self,
410410
bx: &mut Bx,
411-
place_ref: &mir::PlaceRef<'_, 'tcx>,
411+
place_ref: mir::PlaceRef<'_, 'tcx>,
412412
) -> PlaceRef<'tcx, Bx::Value> {
413413
debug!("codegen_place(place_ref={:?})", place_ref);
414414
let cx = self.cx;
415415
let tcx = self.cx.tcx();
416416

417417
let result = match place_ref {
418-
mir::PlaceRef { local, projection: [] } => match self.locals[**local] {
418+
mir::PlaceRef { local, projection: [] } => match self.locals[local] {
419419
LocalRef::Place(place) => {
420420
return place;
421421
}
@@ -428,13 +428,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
428428
},
429429
mir::PlaceRef { local, projection: [proj_base @ .., mir::ProjectionElem::Deref] } => {
430430
// Load the pointer from its location.
431-
self.codegen_consume(bx, &mir::PlaceRef { local, projection: proj_base })
431+
self.codegen_consume(bx, mir::PlaceRef { local, projection: proj_base })
432432
.deref(bx.cx())
433433
}
434434
mir::PlaceRef { local, projection: [proj_base @ .., elem] } => {
435435
// FIXME turn this recursion into iteration
436436
let cg_base =
437-
self.codegen_place(bx, &mir::PlaceRef { local, projection: proj_base });
437+
self.codegen_place(bx, mir::PlaceRef { local, projection: proj_base });
438438

439439
match elem {
440440
mir::ProjectionElem::Deref => bug!(),
@@ -497,7 +497,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
497497
result
498498
}
499499

500-
pub fn monomorphized_place_ty(&self, place_ref: &mir::PlaceRef<'_, 'tcx>) -> Ty<'tcx> {
500+
pub fn monomorphized_place_ty(&self, place_ref: mir::PlaceRef<'_, 'tcx>) -> Ty<'tcx> {
501501
let tcx = self.cx.tcx();
502502
let place_ty = mir::Place::ty_from(place_ref.local, place_ref.projection, *self.mir, tcx);
503503
self.monomorphize(&place_ty.ty)

src/librustc_codegen_ssa/mir/rvalue.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
467467
mir::Rvalue::Discriminant(ref place) => {
468468
let discr_ty = rvalue.ty(*self.mir, bx.tcx());
469469
let discr = self
470-
.codegen_place(&mut bx, &place.as_ref())
470+
.codegen_place(&mut bx, place.as_ref())
471471
.codegen_get_discr(&mut bx, discr_ty);
472472
(
473473
bx,
@@ -541,7 +541,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
541541
}
542542
}
543543
// use common size calculation for non zero-sized types
544-
let cg_value = self.codegen_place(bx, &place.as_ref());
544+
let cg_value = self.codegen_place(bx, place.as_ref());
545545
cg_value.len(bx.cx())
546546
}
547547

@@ -552,7 +552,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
552552
place: &mir::Place<'tcx>,
553553
mk_ptr_ty: impl FnOnce(TyCtxt<'tcx>, Ty<'tcx>) -> Ty<'tcx>,
554554
) -> (Bx, OperandRef<'tcx, Bx::Value>) {
555-
let cg_place = self.codegen_place(&mut bx, &place.as_ref());
555+
let cg_place = self.codegen_place(&mut bx, place.as_ref());
556556

557557
let ty = cg_place.layout.ty;
558558

src/librustc_codegen_ssa/mir/statement.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
4141
}
4242
}
4343
} else {
44-
let cg_dest = self.codegen_place(&mut bx, &place.as_ref());
44+
let cg_dest = self.codegen_place(&mut bx, place.as_ref());
4545
self.codegen_rvalue(bx, cg_dest, rvalue)
4646
}
4747
}
4848
mir::StatementKind::SetDiscriminant { box ref place, variant_index } => {
49-
self.codegen_place(&mut bx, &place.as_ref())
49+
self.codegen_place(&mut bx, place.as_ref())
5050
.codegen_set_discr(&mut bx, variant_index);
5151
bx
5252
}
@@ -70,7 +70,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
7070
let outputs = asm
7171
.outputs
7272
.iter()
73-
.map(|output| self.codegen_place(&mut bx, &output.as_ref()))
73+
.map(|output| self.codegen_place(&mut bx, output.as_ref()))
7474
.collect();
7575

7676
let input_vals = asm.inputs.iter().fold(

src/librustc_mir/borrow_check/constraint_generation.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<'cg, 'cx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'tcx> {
9797
));
9898

9999
// If there are borrows on this now dead local, we need to record them as `killed`.
100-
if let StatementKind::StorageDead(ref local) = statement.kind {
100+
if let StatementKind::StorageDead(local) = statement.kind {
101101
record_killed_borrows_for_local(
102102
all_facts,
103103
self.borrow_set,
@@ -212,7 +212,7 @@ impl<'cx, 'cg, 'tcx> ConstraintGeneration<'cx, 'cg, 'tcx> {
212212
local, location
213213
);
214214

215-
if let Some(borrow_indices) = self.borrow_set.local_map.get(local) {
215+
if let Some(borrow_indices) = self.borrow_set.local_map.get(&local) {
216216
for &borrow_index in borrow_indices {
217217
let places_conflict = places_conflict::places_conflict(
218218
self.infcx.tcx,
@@ -239,10 +239,10 @@ fn record_killed_borrows_for_local(
239239
all_facts: &mut AllFacts,
240240
borrow_set: &BorrowSet<'_>,
241241
location_table: &LocationTable,
242-
local: &Local,
242+
local: Local,
243243
location: Location,
244244
) {
245-
if let Some(borrow_indices) = borrow_set.local_map.get(local) {
245+
if let Some(borrow_indices) = borrow_set.local_map.get(&local) {
246246
all_facts.killed.reserve(borrow_indices.len());
247247
for &borrow_index in borrow_indices {
248248
let location_index = location_table.mid_index(location);

src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
604604
cursor = proj_base;
605605

606606
match elem {
607-
ProjectionElem::Field(field, _) if union_ty(local, proj_base).is_some() => {
608-
return Some((PlaceRef { local, projection: proj_base }, field));
607+
ProjectionElem::Field(field, _)
608+
if union_ty(*local, proj_base).is_some() =>
609+
{
610+
return Some((
611+
PlaceRef { local: *local, projection: proj_base },
612+
field,
613+
));
609614
}
610615
_ => {}
611616
}
@@ -622,14 +627,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
622627
cursor = proj_base;
623628

624629
if let ProjectionElem::Field(field, _) = elem {
625-
if let Some(union_ty) = union_ty(local, proj_base) {
630+
if let Some(union_ty) = union_ty(*local, proj_base) {
626631
if field != target_field
627-
&& local == target_base.local
632+
&& *local == target_base.local
628633
&& proj_base == target_base.projection
629634
{
630635
// FIXME when we avoid clone reuse describe_place closure
631636
let describe_base_place = self
632-
.describe_place(PlaceRef { local, projection: proj_base })
637+
.describe_place(PlaceRef {
638+
local: *local,
639+
projection: proj_base,
640+
})
633641
.unwrap_or_else(|| "_".to_owned());
634642

635643
return Some((
@@ -686,12 +694,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
686694
let borrow_span = borrow_spans.var_or_use();
687695

688696
assert!(root_place.projection.is_empty());
689-
let proper_span = self.body.local_decls[*root_place.local].source_info.span;
697+
let proper_span = self.body.local_decls[root_place.local].source_info.span;
690698

691699
let root_place_projection = self.infcx.tcx.intern_place_elems(root_place.projection);
692700

693701
if self.access_place_error_reported.contains(&(
694-
Place { local: *root_place.local, projection: root_place_projection },
702+
Place { local: root_place.local, projection: root_place_projection },
695703
borrow_span,
696704
)) {
697705
debug!(
@@ -702,7 +710,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
702710
}
703711

704712
self.access_place_error_reported.insert((
705-
Place { local: *root_place.local, projection: root_place_projection },
713+
Place { local: root_place.local, projection: root_place_projection },
706714
borrow_span,
707715
));
708716

@@ -1139,7 +1147,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11391147
let root_place =
11401148
self.prefixes(borrow.borrowed_place.as_ref(), PrefixSet::All).last().unwrap();
11411149
let local = root_place.local;
1142-
match self.body.local_kind(*local) {
1150+
match self.body.local_kind(local) {
11431151
LocalKind::ReturnPointer | LocalKind::Temp => {
11441152
("temporary value".to_string(), "temporary value created here".to_string())
11451153
}
@@ -1513,17 +1521,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15131521
StorageDeadOrDrop::LocalStorageDead
15141522
| StorageDeadOrDrop::BoxedStorageDead => {
15151523
assert!(
1516-
Place::ty_from(&place.local, proj_base, *self.body, tcx)
1517-
.ty
1518-
.is_box(),
1524+
Place::ty_from(place.local, proj_base, *self.body, tcx).ty.is_box(),
15191525
"Drop of value behind a reference or raw pointer"
15201526
);
15211527
StorageDeadOrDrop::BoxedStorageDead
15221528
}
15231529
StorageDeadOrDrop::Destructor(_) => base_access,
15241530
},
15251531
ProjectionElem::Field(..) | ProjectionElem::Downcast(..) => {
1526-
let base_ty = Place::ty_from(&place.local, proj_base, *self.body, tcx).ty;
1532+
let base_ty = Place::ty_from(place.local, proj_base, *self.body, tcx).ty;
15271533
match base_ty.kind {
15281534
ty::Adt(def, _) if def.has_dtor(tcx) => {
15291535
// Report the outermost adt with a destructor

0 commit comments

Comments
 (0)