Skip to content

Commit 810dbf7

Browse files
committed
take mir::PlaceElem by value
1 parent da57ced commit 810dbf7

File tree

15 files changed

+58
-58
lines changed

15 files changed

+58
-58
lines changed

src/librustc_codegen_ssa/mir/analyze.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
104104
) {
105105
let cx = self.fx.cx;
106106

107-
if let [proj_base @ .., elem] = place_ref.projection {
107+
if let &[ref proj_base @ .., elem] = place_ref.projection {
108108
let mut base_context = if context.is_mutating_use() {
109109
PlaceContext::MutatingUse(MutatingUseContext::Projection)
110110
} else {
@@ -186,7 +186,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
186186
// now that we have moved to the "slice of projections" representation.
187187
if let mir::ProjectionElem::Index(local) = elem {
188188
self.visit_local(
189-
local,
189+
&local,
190190
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
191191
location,
192192
);

src/librustc_codegen_ssa/mir/place.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
429429
self.codegen_consume(bx, mir::PlaceRef { local, projection: proj_base })
430430
.deref(bx.cx())
431431
}
432-
mir::PlaceRef { local, projection: [proj_base @ .., elem] } => {
432+
mir::PlaceRef { local, projection: &[ref proj_base @ .., elem] } => {
433433
// FIXME turn this recursion into iteration
434434
let cg_base =
435435
self.codegen_place(bx, mir::PlaceRef { local, projection: proj_base });
@@ -440,7 +440,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
440440
cg_base.project_field(bx, field.index())
441441
}
442442
mir::ProjectionElem::Index(index) => {
443-
let index = &mir::Operand::Copy(mir::Place::from(*index));
443+
let index = &mir::Operand::Copy(mir::Place::from(index));
444444
let index = self.codegen_operand(bx, index);
445445
let llindex = index.immediate();
446446
cg_base.project_index(bx, llindex)
@@ -450,22 +450,22 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
450450
from_end: false,
451451
min_length: _,
452452
} => {
453-
let lloffset = bx.cx().const_usize(*offset as u64);
453+
let lloffset = bx.cx().const_usize(offset as u64);
454454
cg_base.project_index(bx, lloffset)
455455
}
456456
mir::ProjectionElem::ConstantIndex {
457457
offset,
458458
from_end: true,
459459
min_length: _,
460460
} => {
461-
let lloffset = bx.cx().const_usize(*offset as u64);
461+
let lloffset = bx.cx().const_usize(offset as u64);
462462
let lllen = cg_base.len(bx.cx());
463463
let llindex = bx.sub(lllen, lloffset);
464464
cg_base.project_index(bx, llindex)
465465
}
466466
mir::ProjectionElem::Subslice { from, to, from_end } => {
467467
let mut subslice =
468-
cg_base.project_index(bx, bx.cx().const_usize(*from as u64));
468+
cg_base.project_index(bx, bx.cx().const_usize(from as u64));
469469
let projected_ty =
470470
PlaceTy::from_ty(cg_base.layout.ty).projection_ty(tcx, elem).ty;
471471
subslice.layout = bx.cx().layout_of(self.monomorphize(&projected_ty));
@@ -474,7 +474,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
474474
assert!(from_end, "slice subslices should be `from_end`");
475475
subslice.llextra = Some(bx.sub(
476476
cg_base.llextra.unwrap(),
477-
bx.cx().const_usize((*from as u64) + (*to as u64)),
477+
bx.cx().const_usize((from as u64) + (to as u64)),
478478
));
479479
}
480480

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

488488
subslice
489489
}
490-
mir::ProjectionElem::Downcast(_, v) => cg_base.project_downcast(bx, *v),
490+
mir::ProjectionElem::Downcast(_, v) => cg_base.project_downcast(bx, v),
491491
}
492492
}
493493
};

src/librustc_middle/mir/tcx.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ impl<'tcx> PlaceTy<'tcx> {
5656
/// Convenience wrapper around `projection_ty_core` for
5757
/// `PlaceElem`, where we can just use the `Ty` that is already
5858
/// stored inline on field projection elems.
59-
pub fn projection_ty(self, tcx: TyCtxt<'tcx>, elem: &PlaceElem<'tcx>) -> PlaceTy<'tcx> {
60-
self.projection_ty_core(tcx, ty::ParamEnv::empty(), elem, |_, _, ty| ty)
59+
pub fn projection_ty(self, tcx: TyCtxt<'tcx>, elem: PlaceElem<'tcx>) -> PlaceTy<'tcx> {
60+
self.projection_ty_core(tcx, ty::ParamEnv::empty(), &elem, |_, _, ty| ty)
6161
}
6262

6363
/// `place_ty.projection_ty_core(tcx, elem, |...| { ... })`
@@ -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
}

src/librustc_middle/mir/visit.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ macro_rules! visit_place_fns {
903903
let mut projection = Cow::Borrowed(projection);
904904

905905
for i in 0..projection.len() {
906-
if let Some(elem) = projection.get(i) {
906+
if let Some(&elem) = projection.get(i) {
907907
if let Some(elem) = self.process_projection_elem(elem, location) {
908908
// This converts the borrowed projection into `Cow::Owned(_)` and returns a
909909
// clone of the projection so we can mutate and reintern later.
@@ -921,19 +921,19 @@ macro_rules! visit_place_fns {
921921

922922
fn process_projection_elem(
923923
&mut self,
924-
elem: &PlaceElem<'tcx>,
924+
elem: PlaceElem<'tcx>,
925925
location: Location,
926926
) -> Option<PlaceElem<'tcx>> {
927927
match elem {
928928
PlaceElem::Index(local) => {
929-
let mut new_local = *local;
929+
let mut new_local = local;
930930
self.visit_local(
931931
&mut new_local,
932932
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
933933
location,
934934
);
935935

936-
if new_local == *local { None } else { Some(PlaceElem::Index(new_local)) }
936+
if new_local == local { None } else { Some(PlaceElem::Index(new_local)) }
937937
}
938938
PlaceElem::Deref
939939
| PlaceElem::Field(..)
@@ -959,7 +959,7 @@ macro_rules! visit_place_fns {
959959
&mut self,
960960
local: Local,
961961
proj_base: &[PlaceElem<'tcx>],
962-
elem: &PlaceElem<'tcx>,
962+
elem: PlaceElem<'tcx>,
963963
context: PlaceContext,
964964
location: Location,
965965
) {
@@ -990,7 +990,7 @@ macro_rules! visit_place_fns {
990990
location: Location,
991991
) {
992992
let mut cursor = projection;
993-
while let [proj_base @ .., elem] = cursor {
993+
while let &[ref proj_base @ .., elem] = cursor {
994994
cursor = proj_base;
995995
self.visit_projection_elem(local, cursor, elem, context, location);
996996
}
@@ -1000,7 +1000,7 @@ macro_rules! visit_place_fns {
10001000
&mut self,
10011001
_local: Local,
10021002
_proj_base: &[PlaceElem<'tcx>],
1003-
elem: &PlaceElem<'tcx>,
1003+
elem: PlaceElem<'tcx>,
10041004
_context: PlaceContext,
10051005
location: Location,
10061006
) {
@@ -1010,7 +1010,7 @@ macro_rules! visit_place_fns {
10101010
}
10111011
ProjectionElem::Index(local) => {
10121012
self.visit_local(
1013-
local,
1013+
&local,
10141014
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
10151015
location,
10161016
);

src/librustc_mir/borrow_check/places_conflict.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fn place_components_conflict<'tcx>(
138138
}
139139

140140
// loop invariant: borrow_c is always either equal to access_c or disjoint from it.
141-
for (i, (borrow_c, access_c)) in
141+
for (i, (borrow_c, &access_c)) in
142142
borrow_place.projection.iter().zip(access_place.projection.iter()).enumerate()
143143
{
144144
debug!("borrow_conflicts_with_place: borrow_c = {:?}", borrow_c);
@@ -163,8 +163,8 @@ fn place_components_conflict<'tcx>(
163163
body,
164164
borrow_local,
165165
borrow_proj_base,
166-
&borrow_c,
167-
&access_c,
166+
borrow_c,
167+
access_c,
168168
bias,
169169
) {
170170
Overlap::Arbitrary => {
@@ -313,8 +313,8 @@ fn place_projection_conflict<'tcx>(
313313
body: &Body<'tcx>,
314314
pi1_local: Local,
315315
pi1_proj_base: &[PlaceElem<'tcx>],
316-
pi1_elem: &PlaceElem<'tcx>,
317-
pi2_elem: &PlaceElem<'tcx>,
316+
pi1_elem: PlaceElem<'tcx>,
317+
pi2_elem: PlaceElem<'tcx>,
318318
bias: PlaceConflictBias,
319319
) -> Overlap {
320320
match (pi1_elem, pi2_elem) {
@@ -420,24 +420,24 @@ fn place_projection_conflict<'tcx>(
420420
}
421421
}
422422
(
423-
&ProjectionElem::ConstantIndex {
423+
ProjectionElem::ConstantIndex {
424424
offset: offset_from_begin,
425425
min_length: min_length1,
426426
from_end: false,
427427
},
428-
&ProjectionElem::ConstantIndex {
428+
ProjectionElem::ConstantIndex {
429429
offset: offset_from_end,
430430
min_length: min_length2,
431431
from_end: true,
432432
},
433433
)
434434
| (
435-
&ProjectionElem::ConstantIndex {
435+
ProjectionElem::ConstantIndex {
436436
offset: offset_from_end,
437437
min_length: min_length1,
438438
from_end: true,
439439
},
440-
&ProjectionElem::ConstantIndex {
440+
ProjectionElem::ConstantIndex {
441441
offset: offset_from_begin,
442442
min_length: min_length2,
443443
from_end: false,

src/librustc_mir/borrow_check/renumber.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ impl<'a, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'tcx> {
6666

6767
fn process_projection_elem(
6868
&mut self,
69-
elem: &PlaceElem<'tcx>,
69+
elem: PlaceElem<'tcx>,
7070
_: Location,
7171
) -> Option<PlaceElem<'tcx>> {
7272
if let PlaceElem::Field(field, ty) = elem {
73-
let new_ty = self.renumber_regions(ty);
73+
let new_ty = self.renumber_regions(&ty);
7474

75-
if new_ty != *ty {
76-
return Some(PlaceElem::Field(*field, new_ty));
75+
if new_ty != ty {
76+
return Some(PlaceElem::Field(field, new_ty));
7777
}
7878
}
7979

src/librustc_mir/borrow_check/type_check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
497497
return PlaceTy::from_ty(self.tcx().types.err);
498498
}
499499
}
500-
place_ty = self.sanitize_projection(place_ty, &elem, place, location)
500+
place_ty = self.sanitize_projection(place_ty, elem, place, location)
501501
}
502502

503503
if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
@@ -611,14 +611,14 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
611611
fn sanitize_projection(
612612
&mut self,
613613
base: PlaceTy<'tcx>,
614-
pi: &PlaceElem<'tcx>,
614+
pi: PlaceElem<'tcx>,
615615
place: &Place<'tcx>,
616616
location: Location,
617617
) -> PlaceTy<'tcx> {
618618
debug!("sanitize_projection: {:?} {:?} {:?}", base, pi, place);
619619
let tcx = self.tcx();
620620
let base_ty = base.ty;
621-
match *pi {
621+
match pi {
622622
ProjectionElem::Deref => {
623623
let deref_ty = base_ty.builtin_deref(true);
624624
PlaceTy::from_ty(deref_ty.map(|t| t.ty).unwrap_or_else(|| {

src/librustc_mir/dataflow/drop_flag_effects.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ pub fn move_path_children_matching<'tcx, F>(
1212
mut cond: F,
1313
) -> Option<MovePathIndex>
1414
where
15-
F: FnMut(&mir::PlaceElem<'tcx>) -> bool,
15+
F: FnMut(mir::PlaceElem<'tcx>) -> bool,
1616
{
1717
let mut next_child = move_data.move_paths[path].first_child;
1818
while let Some(child_index) = next_child {
1919
let move_path_children = &move_data.move_paths[child_index];
20-
if let Some(elem) = move_path_children.place.projection.last() {
20+
if let Some(&elem) = move_path_children.place.projection.last() {
2121
if cond(elem) {
2222
return Some(child_index);
2323
}

src/librustc_mir/dataflow/move_paths/builder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
158158
};
159159

160160
if union_path.is_none() {
161-
base = self.add_move_path(base, &elem, |tcx| Place {
161+
base = self.add_move_path(base, elem, |tcx| Place {
162162
local: place.local,
163163
projection: tcx.intern_place_elems(&place.projection[..i + 1]),
164164
});
@@ -176,7 +176,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
176176
fn add_move_path(
177177
&mut self,
178178
base: MovePathIndex,
179-
elem: &PlaceElem<'tcx>,
179+
elem: PlaceElem<'tcx>,
180180
mk_place: impl FnOnce(TyCtxt<'tcx>) -> Place<'tcx>,
181181
) -> MovePathIndex {
182182
let MoveDataBuilder {
@@ -485,7 +485,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
485485
let elem =
486486
ProjectionElem::ConstantIndex { offset, min_length: len, from_end: false };
487487
let path =
488-
self.add_move_path(base_path, &elem, |tcx| tcx.mk_place_elem(base_place, elem));
488+
self.add_move_path(base_path, elem, |tcx| tcx.mk_place_elem(base_place, elem));
489489
self.record_move(place, path);
490490
}
491491
} else {

src/librustc_mir/interpret/operand.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
400400
pub fn operand_projection(
401401
&self,
402402
base: OpTy<'tcx, M::PointerTag>,
403-
proj_elem: &mir::PlaceElem<'tcx>,
403+
proj_elem: mir::PlaceElem<'tcx>,
404404
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
405405
use rustc_middle::mir::ProjectionElem::*;
406-
Ok(match *proj_elem {
406+
Ok(match proj_elem {
407407
Field(field, _) => self.operand_field(base, field.index())?,
408408
Downcast(_, variant) => self.operand_downcast(base, variant)?,
409409
Deref => self.deref_operand(base)?.into(),
@@ -466,7 +466,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
466466
let op = place
467467
.projection
468468
.iter()
469-
.try_fold(base_op, |op, elem| self.operand_projection(op, &elem))?;
469+
.try_fold(base_op, |op, elem| self.operand_projection(op, elem))?;
470470

471471
trace!("eval_place_to_op: got {:?}", *op);
472472
Ok(op)

src/librustc_mir/interpret/place.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,10 @@ where
517517
pub(super) fn mplace_projection(
518518
&self,
519519
base: MPlaceTy<'tcx, M::PointerTag>,
520-
proj_elem: &mir::PlaceElem<'tcx>,
520+
proj_elem: mir::PlaceElem<'tcx>,
521521
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
522522
use rustc_middle::mir::ProjectionElem::*;
523-
Ok(match *proj_elem {
523+
Ok(match proj_elem {
524524
Field(field, _) => self.mplace_field(base, field.index())?,
525525
Downcast(_, variant) => self.mplace_downcast(base, variant)?,
526526
Deref => self.deref_operand(base.into())?,
@@ -605,10 +605,10 @@ where
605605
pub fn place_projection(
606606
&mut self,
607607
base: PlaceTy<'tcx, M::PointerTag>,
608-
proj_elem: &mir::ProjectionElem<mir::Local, Ty<'tcx>>,
608+
&proj_elem: &mir::ProjectionElem<mir::Local, Ty<'tcx>>,
609609
) -> InterpResult<'tcx, PlaceTy<'tcx, M::PointerTag>> {
610610
use rustc_middle::mir::ProjectionElem::*;
611-
Ok(match *proj_elem {
611+
Ok(match proj_elem {
612612
Field(field, _) => self.place_field(base, field.index())?,
613613
Downcast(_, variant) => self.place_downcast(base, variant)?,
614614
Deref => self.deref_operand(self.place_to_op(base)?)?.into(),

src/librustc_mir/transform/check_consts/qualifs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ where
206206
F: FnMut(Local) -> bool,
207207
{
208208
let mut projection = place.projection;
209-
while let [ref proj_base @ .., proj_elem] = projection {
210-
match *proj_elem {
209+
while let &[ref proj_base @ .., proj_elem] = projection {
210+
match proj_elem {
211211
ProjectionElem::Index(index) if in_local(index) => return true,
212212

213213
ProjectionElem::Deref

src/librustc_mir/transform/check_consts/validation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
432432
&mut self,
433433
place_local: Local,
434434
proj_base: &[PlaceElem<'tcx>],
435-
elem: &PlaceElem<'tcx>,
435+
elem: PlaceElem<'tcx>,
436436
context: PlaceContext,
437437
location: Location,
438438
) {

0 commit comments

Comments
 (0)