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

Commit da3f0d0

Browse files
committed
make MPlaceTy non-Copy
1 parent 77ff1b8 commit da3f0d0

File tree

11 files changed

+28
-28
lines changed

11 files changed

+28
-28
lines changed

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
5858
ecx.push_stack_frame(
5959
cid.instance,
6060
body,
61-
&ret.into(),
61+
&ret.clone().into(),
6262
StackPopCleanup::Root { cleanup: false },
6363
)?;
6464

@@ -356,7 +356,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
356356
// Since evaluation had no errors, validate the resulting constant.
357357
// This is a separate `try` block to provide more targeted error reporting.
358358
let validation: Result<_, InterpErrorInfo<'_>> = try {
359-
let mut ref_tracking = RefTracking::new(mplace);
359+
let mut ref_tracking = RefTracking::new(mplace.clone());
360360
let mut inner = false;
361361
while let Some((mplace, path)) = ref_tracking.todo.pop() {
362362
let mode = match tcx.static_mutability(cid.instance.def_id()) {

compiler/rustc_const_eval/src/const_eval/valtrees.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn branches<'tcx>(
2121
) -> ValTreeCreationResult<'tcx> {
2222
let place = match variant {
2323
Some(variant) => ecx.project_downcast(place, variant).unwrap(),
24-
None => *place,
24+
None => place.clone(),
2525
};
2626
let variant = variant.map(|variant| Some(ty::ValTree::Leaf(ScalarInt::from(variant.as_u32()))));
2727
debug!(?place, ?variant);
@@ -290,7 +290,7 @@ pub fn valtree_to_const_value<'tcx>(
290290
debug!(?place);
291291

292292
valtree_into_mplace(&mut ecx, &mut place, valtree);
293-
dump_place(&ecx, place.into());
293+
dump_place(&ecx, place.clone().into());
294294
intern_const_alloc_recursive(&mut ecx, InternKind::Constant, &place).unwrap();
295295

296296
match ty.kind() {
@@ -352,7 +352,7 @@ fn valtree_into_mplace<'tcx>(
352352
debug!(?pointee_place);
353353

354354
valtree_into_mplace(ecx, &mut pointee_place, valtree);
355-
dump_place(ecx, pointee_place.into());
355+
dump_place(ecx, pointee_place.clone().into());
356356
intern_const_alloc_recursive(ecx, InternKind::Constant, &pointee_place).unwrap();
357357

358358
let imm = match inner_ty.kind() {
@@ -389,7 +389,7 @@ fn valtree_into_mplace<'tcx>(
389389
Some(variant_idx),
390390
)
391391
}
392-
_ => (*place, branches, None),
392+
_ => (place.clone(), branches, None),
393393
};
394394
debug!(?place_adjusted, ?branches);
395395

compiler/rustc_const_eval/src/interpret/intern.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ pub fn intern_const_alloc_recursive<
358358
Some(ret.layout.ty),
359359
);
360360

361-
ref_tracking.track((*ret, base_intern_mode), || ());
361+
ref_tracking.track((ret.clone(), base_intern_mode), || ());
362362

363363
while let Some(((mplace, mode), _)) = ref_tracking.todo.pop() {
364364
let res = InternVisitor {
@@ -464,7 +464,7 @@ impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx, !>>
464464
) -> InterpResult<'tcx, ()>,
465465
) -> InterpResult<'tcx, ConstAllocation<'tcx>> {
466466
let dest = self.allocate(layout, MemoryKind::Stack)?;
467-
f(self, &dest.into())?;
467+
f(self, &dest.clone().into())?;
468468
let mut alloc = self.memory.alloc_map.remove(&dest.ptr.provenance.unwrap()).unwrap().1;
469469
alloc.mutability = Mutability::Not;
470470
Ok(self.tcx.mk_const_alloc(alloc))

compiler/rustc_const_eval/src/interpret/operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
476476
if let Some(val) = self.read_immediate_from_mplace_raw(mplace)? {
477477
Right(val)
478478
} else {
479-
Left(*mplace)
479+
Left(mplace.clone())
480480
}
481481
}
482482
Right(val) => Right(val),

compiler/rustc_const_eval/src/interpret/place.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub struct MemPlace<Prov: Provenance = AllocId> {
8181
}
8282

8383
/// A MemPlace with its layout. Constructing it is only possible in this module.
84-
#[derive(Copy, Clone, Hash, Eq, PartialEq, Debug)]
84+
#[derive(Clone, Hash, Eq, PartialEq, Debug)]
8585
pub struct MPlaceTy<'tcx, Prov: Provenance = AllocId> {
8686
mplace: MemPlace<Prov>,
8787
pub layout: TyAndLayout<'tcx>,
@@ -452,7 +452,7 @@ where
452452
}
453453

454454
let mplace = self.ref_to_mplace(&val)?;
455-
self.check_mplace(mplace)?;
455+
self.check_mplace(&mplace)?;
456456
Ok(mplace)
457457
}
458458

@@ -483,7 +483,7 @@ where
483483
}
484484

485485
/// Check if this mplace is dereferenceable and sufficiently aligned.
486-
pub fn check_mplace(&self, mplace: MPlaceTy<'tcx, M::Provenance>) -> InterpResult<'tcx> {
486+
pub fn check_mplace(&self, mplace: &MPlaceTy<'tcx, M::Provenance>) -> InterpResult<'tcx> {
487487
let (size, _align) = self
488488
.size_and_align_of_mplace(&mplace)?
489489
.unwrap_or((mplace.layout.size, mplace.layout.align.abi));

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
634634
// Ensure the return place is aligned and dereferenceable, and protect it for
635635
// in-place return value passing.
636636
if let Either::Left(mplace) = destination.as_mplace_or_local() {
637-
self.check_mplace(mplace)?;
637+
self.check_mplace(&mplace)?;
638638
} else {
639639
// Nothing to do for locals, they are always properly allocated and aligned.
640640
}

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,19 @@ pub struct RefTracking<T, PATH = ()> {
136136
pub todo: Vec<(T, PATH)>,
137137
}
138138

139-
impl<T: Copy + Eq + Hash + std::fmt::Debug, PATH: Default> RefTracking<T, PATH> {
139+
impl<T: Clone + Eq + Hash + std::fmt::Debug, PATH: Default> RefTracking<T, PATH> {
140140
pub fn empty() -> Self {
141141
RefTracking { seen: FxHashSet::default(), todo: vec![] }
142142
}
143143
pub fn new(op: T) -> Self {
144144
let mut ref_tracking_for_consts =
145-
RefTracking { seen: FxHashSet::default(), todo: vec![(op, PATH::default())] };
145+
RefTracking { seen: FxHashSet::default(), todo: vec![(op.clone(), PATH::default())] };
146146
ref_tracking_for_consts.seen.insert(op);
147147
ref_tracking_for_consts
148148
}
149149

150150
pub fn track(&mut self, op: T, path: impl FnOnce() -> PATH) {
151-
if self.seen.insert(op) {
151+
if self.seen.insert(op.clone()) {
152152
trace!("Recursing below ptr {:#?}", op);
153153
let path = path();
154154
// Remember to come back to this later.

src/tools/miri/src/helpers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,14 +600,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
600600
/// necessary.
601601
fn last_error_place(&mut self) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> {
602602
let this = self.eval_context_mut();
603-
if let Some(errno_place) = this.active_thread_ref().last_error {
604-
Ok(errno_place)
603+
if let Some(errno_place) = this.active_thread_ref().last_error.as_ref() {
604+
Ok(errno_place.clone())
605605
} else {
606606
// Allocate new place, set initial value to 0.
607607
let errno_layout = this.machine.layouts.u32;
608608
let errno_place = this.allocate(errno_layout, MiriMemoryKind::Machine.into())?;
609609
this.write_scalar(Scalar::from_u32(0), &errno_place)?;
610-
this.active_thread_mut().last_error = Some(errno_place);
610+
this.active_thread_mut().last_error = Some(errno_place.clone());
611611
Ok(errno_place)
612612
}
613613
}
@@ -725,7 +725,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
725725

726726
let mplace = MPlaceTy::from_aligned_ptr(ptr, layout);
727727

728-
this.check_mplace(mplace)?;
728+
this.check_mplace(&mplace)?;
729729

730730
Ok(mplace)
731731
}

src/tools/miri/src/machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
668668
Self::add_extern_static(
669669
this,
670670
"environ",
671-
this.machine.env_vars.environ.unwrap().ptr,
671+
this.machine.env_vars.environ.as_ref().unwrap().ptr,
672672
);
673673
// A couple zero-initialized pointer-sized extern statics.
674674
// Most of them are for weak symbols, which we all set to null (indicating that the
@@ -685,7 +685,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
685685
Self::add_extern_static(
686686
this,
687687
"environ",
688-
this.machine.env_vars.environ.unwrap().ptr,
688+
this.machine.env_vars.environ.as_ref().unwrap().ptr,
689689
);
690690
}
691691
"android" => {

src/tools/miri/src/shims/env.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ impl<'tcx> EnvVars<'tcx> {
8787
ecx.deallocate_ptr(ptr, None, MiriMemoryKind::Runtime.into())?;
8888
}
8989
// Deallocate environ var list.
90-
let environ = ecx.machine.env_vars.environ.unwrap();
91-
let old_vars_ptr = ecx.read_pointer(&environ)?;
90+
let environ = ecx.machine.env_vars.environ.as_ref().unwrap();
91+
let old_vars_ptr = ecx.read_pointer(environ)?;
9292
ecx.deallocate_ptr(old_vars_ptr, None, MiriMemoryKind::Runtime.into())?;
9393
Ok(())
9494
}
@@ -431,8 +431,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
431431
fn update_environ(&mut self) -> InterpResult<'tcx> {
432432
let this = self.eval_context_mut();
433433
// Deallocate the old environ list, if any.
434-
if let Some(environ) = this.machine.env_vars.environ {
435-
let old_vars_ptr = this.read_pointer(&environ)?;
434+
if let Some(environ) = this.machine.env_vars.environ.as_ref() {
435+
let old_vars_ptr = this.read_pointer(environ)?;
436436
this.deallocate_ptr(old_vars_ptr, None, MiriMemoryKind::Runtime.into())?;
437437
} else {
438438
// No `environ` allocated yet, let's do that.
@@ -459,7 +459,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
459459
let place = this.project_field(&vars_place, idx)?;
460460
this.write_pointer(var, &place)?;
461461
}
462-
this.write_pointer(vars_place.ptr, &this.machine.env_vars.environ.unwrap())?;
462+
this.write_pointer(vars_place.ptr, &this.machine.env_vars.environ.clone().unwrap())?;
463463

464464
Ok(())
465465
}

src/tools/miri/src/shims/unix/macos/foreign_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
8686
"_NSGetEnviron" => {
8787
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
8888
this.write_pointer(
89-
this.machine.env_vars.environ.expect("machine must be initialized").ptr,
89+
this.machine.env_vars.environ.as_ref().expect("machine must be initialized").ptr,
9090
dest,
9191
)?;
9292
}

0 commit comments

Comments
 (0)