Skip to content

Commit f60ec83

Browse files
committed
interpret: add From<&MplaceTy> for PlaceTy
1 parent 66c83ff commit f60ec83

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

compiler/rustc_const_eval/src/const_eval/valtrees.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ fn valtree_into_mplace<'tcx>(
346346
ty::FnDef(_, _) => {
347347
ecx.write_immediate(
348348
Immediate::Scalar(ScalarMaybeUninit::Scalar(Scalar::ZST)),
349-
&(*place).into(),
349+
&place.into(),
350350
)
351351
.unwrap();
352352
}
@@ -355,7 +355,7 @@ fn valtree_into_mplace<'tcx>(
355355
debug!("writing trivial valtree {:?} to place {:?}", scalar_int, place);
356356
ecx.write_immediate(
357357
Immediate::Scalar(ScalarMaybeUninit::Scalar(scalar_int.into())),
358-
&(*place).into(),
358+
&place.into(),
359359
)
360360
.unwrap();
361361
}
@@ -382,7 +382,7 @@ fn valtree_into_mplace<'tcx>(
382382
};
383383
debug!(?imm);
384384

385-
ecx.write_immediate(imm, &(*place).into()).unwrap();
385+
ecx.write_immediate(imm, &place.into()).unwrap();
386386
}
387387
ty::Adt(_, _) | ty::Tuple(_) | ty::Array(_, _) | ty::Str | ty::Slice(_) => {
388388
let branches = valtree.unwrap_branch();
@@ -464,11 +464,11 @@ fn valtree_into_mplace<'tcx>(
464464

465465
if let Some(variant_idx) = variant_idx {
466466
// don't forget filling the place with the discriminant of the enum
467-
ecx.write_discriminant(variant_idx, &(*place).into()).unwrap();
467+
ecx.write_discriminant(variant_idx, &place.into()).unwrap();
468468
}
469469

470470
debug!("dump of place after writing discriminant:");
471-
dump_place(ecx, (*place).into());
471+
dump_place(ecx, place.into());
472472
}
473473
_ => bug!("shouldn't have created a ValTree for {:?}", ty),
474474
}

compiler/rustc_const_eval/src/interpret/intern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx, const_eval::Memory
195195
let tcx = self.ecx.tcx;
196196
let ty = mplace.layout.ty;
197197
if let ty::Ref(_, referenced_ty, ref_mutability) = *ty.kind() {
198-
let value = self.ecx.read_immediate(&(*mplace).into())?;
198+
let value = self.ecx.read_immediate(&mplace.into())?;
199199
let mplace = self.ecx.ref_to_mplace(&value)?;
200200
assert_eq!(mplace.layout.ty, referenced_ty);
201201
// Handle trait object vtables.

compiler/rustc_const_eval/src/interpret/operand.rs

+7
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,13 @@ impl<'tcx, Tag: Provenance> From<&'_ MPlaceTy<'tcx, Tag>> for OpTy<'tcx, Tag> {
204204
}
205205
}
206206

207+
impl<'tcx, Tag: Provenance> From<&'_ mut MPlaceTy<'tcx, Tag>> for OpTy<'tcx, Tag> {
208+
#[inline(always)]
209+
fn from(mplace: &mut MPlaceTy<'tcx, Tag>) -> Self {
210+
OpTy { op: Operand::Indirect(**mplace), layout: mplace.layout }
211+
}
212+
}
213+
207214
impl<'tcx, Tag: Provenance> From<ImmTy<'tcx, Tag>> for OpTy<'tcx, Tag> {
208215
#[inline(always)]
209216
fn from(val: ImmTy<'tcx, Tag>) -> Self {

compiler/rustc_const_eval/src/interpret/place.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,21 @@ impl<'tcx, Tag: Provenance> std::ops::Deref for MPlaceTy<'tcx, Tag> {
118118
impl<'tcx, Tag: Provenance> From<MPlaceTy<'tcx, Tag>> for PlaceTy<'tcx, Tag> {
119119
#[inline(always)]
120120
fn from(mplace: MPlaceTy<'tcx, Tag>) -> Self {
121-
PlaceTy { place: Place::Ptr(mplace.mplace), layout: mplace.layout }
121+
PlaceTy { place: Place::Ptr(*mplace), layout: mplace.layout }
122+
}
123+
}
124+
125+
impl<'tcx, Tag: Provenance> From<&'_ MPlaceTy<'tcx, Tag>> for PlaceTy<'tcx, Tag> {
126+
#[inline(always)]
127+
fn from(mplace: &MPlaceTy<'tcx, Tag>) -> Self {
128+
PlaceTy { place: Place::Ptr(**mplace), layout: mplace.layout }
129+
}
130+
}
131+
132+
impl<'tcx, Tag: Provenance> From<&'_ mut MPlaceTy<'tcx, Tag>> for PlaceTy<'tcx, Tag> {
133+
#[inline(always)]
134+
fn from(mplace: &mut MPlaceTy<'tcx, Tag>) -> Self {
135+
PlaceTy { place: Place::Ptr(**mplace), layout: mplace.layout }
122136
}
123137
}
124138

compiler/rustc_const_eval/src/interpret/visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> Value<'mir, 'tcx, M>
9292
&self,
9393
_ecx: &InterpCx<'mir, 'tcx, M>,
9494
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
95-
Ok((*self).into())
95+
Ok(self.into())
9696
}
9797

9898
#[inline(always)]

0 commit comments

Comments
 (0)