rustc_const_eval/interpret/
eval_context.rs

1use std::assert_matches::debug_assert_matches;
2
3use either::{Left, Right};
4use rustc_abi::{Align, HasDataLayout, Size, TargetDataLayout};
5use rustc_errors::DiagCtxtHandle;
6use rustc_hir::def_id::DefId;
7use rustc_middle::mir::interpret::{ErrorHandled, InvalidMetaKind, ReportedErrorInfo};
8use rustc_middle::query::TyCtxtAt;
9use rustc_middle::ty::layout::{
10    self, FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers, TyAndLayout,
11};
12use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypingEnv, Variance};
13use rustc_middle::{mir, span_bug};
14use rustc_session::Limit;
15use rustc_span::Span;
16use rustc_target::callconv::FnAbi;
17use tracing::{debug, trace};
18
19use super::{
20    Frame, FrameInfo, GlobalId, InterpErrorInfo, InterpErrorKind, InterpResult, MPlaceTy, Machine,
21    MemPlaceMeta, Memory, OpTy, Place, PlaceTy, PointerArithmetic, Projectable, Provenance,
22    err_inval, interp_ok, throw_inval, throw_ub, throw_ub_custom,
23};
24use crate::{ReportErrorExt, fluent_generated as fluent, util};
25
26pub struct InterpCx<'tcx, M: Machine<'tcx>> {
27    /// Stores the `Machine` instance.
28    ///
29    /// Note: the stack is provided by the machine.
30    pub machine: M,
31
32    /// The results of the type checker, from rustc.
33    /// The span in this is the "root" of the evaluation, i.e., the const
34    /// we are evaluating (if this is CTFE).
35    pub tcx: TyCtxtAt<'tcx>,
36
37    /// The current context in case we're evaluating in a
38    /// polymorphic context. This always uses `ty::TypingMode::PostAnalysis`.
39    pub(super) typing_env: ty::TypingEnv<'tcx>,
40
41    /// The virtual memory system.
42    pub memory: Memory<'tcx, M>,
43
44    /// The recursion limit (cached from `tcx.recursion_limit(())`)
45    pub recursion_limit: Limit,
46}
47
48impl<'tcx, M: Machine<'tcx>> HasDataLayout for InterpCx<'tcx, M> {
49    #[inline]
50    fn data_layout(&self) -> &TargetDataLayout {
51        &self.tcx.data_layout
52    }
53}
54
55impl<'tcx, M> layout::HasTyCtxt<'tcx> for InterpCx<'tcx, M>
56where
57    M: Machine<'tcx>,
58{
59    #[inline]
60    fn tcx(&self) -> TyCtxt<'tcx> {
61        *self.tcx
62    }
63}
64
65impl<'tcx, M> layout::HasTypingEnv<'tcx> for InterpCx<'tcx, M>
66where
67    M: Machine<'tcx>,
68{
69    fn typing_env(&self) -> ty::TypingEnv<'tcx> {
70        self.typing_env
71    }
72}
73
74impl<'tcx, M: Machine<'tcx>> LayoutOfHelpers<'tcx> for InterpCx<'tcx, M> {
75    type LayoutOfResult = Result<TyAndLayout<'tcx>, InterpErrorKind<'tcx>>;
76
77    #[inline]
78    fn layout_tcx_at_span(&self) -> Span {
79        // Using the cheap root span for performance.
80        self.tcx.span
81    }
82
83    #[inline]
84    fn handle_layout_err(
85        &self,
86        err: LayoutError<'tcx>,
87        _: Span,
88        _: Ty<'tcx>,
89    ) -> InterpErrorKind<'tcx> {
90        err_inval!(Layout(err))
91    }
92}
93
94impl<'tcx, M: Machine<'tcx>> FnAbiOfHelpers<'tcx> for InterpCx<'tcx, M> {
95    type FnAbiOfResult = Result<&'tcx FnAbi<'tcx, Ty<'tcx>>, InterpErrorKind<'tcx>>;
96
97    fn handle_fn_abi_err(
98        &self,
99        err: FnAbiError<'tcx>,
100        _span: Span,
101        _fn_abi_request: FnAbiRequest<'tcx>,
102    ) -> InterpErrorKind<'tcx> {
103        match err {
104            FnAbiError::Layout(err) => err_inval!(Layout(err)),
105        }
106    }
107}
108
109/// Test if it is valid for a MIR assignment to assign `src`-typed place to `dest`-typed value.
110/// This test should be symmetric, as it is primarily about layout compatibility.
111pub(super) fn mir_assign_valid_types<'tcx>(
112    tcx: TyCtxt<'tcx>,
113    typing_env: TypingEnv<'tcx>,
114    src: TyAndLayout<'tcx>,
115    dest: TyAndLayout<'tcx>,
116) -> bool {
117    // Type-changing assignments can happen when subtyping is used. While
118    // all normal lifetimes are erased, higher-ranked types with their
119    // late-bound lifetimes are still around and can lead to type
120    // differences.
121    if util::relate_types(tcx, typing_env, Variance::Covariant, src.ty, dest.ty) {
122        // Make sure the layout is equal, too -- just to be safe. Miri really
123        // needs layout equality. For performance reason we skip this check when
124        // the types are equal. Equal types *can* have different layouts when
125        // enum downcast is involved (as enum variants carry the type of the
126        // enum), but those should never occur in assignments.
127        if cfg!(debug_assertions) || src.ty != dest.ty {
128            assert_eq!(src.layout, dest.layout);
129        }
130        true
131    } else {
132        false
133    }
134}
135
136/// Use the already known layout if given (but sanity check in debug mode),
137/// or compute the layout.
138#[cfg_attr(not(debug_assertions), inline(always))]
139pub(super) fn from_known_layout<'tcx>(
140    tcx: TyCtxtAt<'tcx>,
141    typing_env: TypingEnv<'tcx>,
142    known_layout: Option<TyAndLayout<'tcx>>,
143    compute: impl FnOnce() -> InterpResult<'tcx, TyAndLayout<'tcx>>,
144) -> InterpResult<'tcx, TyAndLayout<'tcx>> {
145    match known_layout {
146        None => compute(),
147        Some(known_layout) => {
148            if cfg!(debug_assertions) {
149                let check_layout = compute()?;
150                if !mir_assign_valid_types(tcx.tcx, typing_env, check_layout, known_layout) {
151                    span_bug!(
152                        tcx.span,
153                        "expected type differs from actual type.\nexpected: {}\nactual: {}",
154                        known_layout.ty,
155                        check_layout.ty,
156                    );
157                }
158            }
159            interp_ok(known_layout)
160        }
161    }
162}
163
164/// Turn the given error into a human-readable string. Expects the string to be printed, so if
165/// `RUSTC_CTFE_BACKTRACE` is set this will show a backtrace of the rustc internals that
166/// triggered the error.
167///
168/// This is NOT the preferred way to render an error; use `report` from `const_eval` instead.
169/// However, this is useful when error messages appear in ICEs.
170pub fn format_interp_error<'tcx>(dcx: DiagCtxtHandle<'_>, e: InterpErrorInfo<'tcx>) -> String {
171    let (e, backtrace) = e.into_parts();
172    backtrace.print_backtrace();
173    // FIXME(fee1-dead), HACK: we want to use the error as title therefore we can just extract the
174    // label and arguments from the InterpError.
175    #[allow(rustc::untranslatable_diagnostic)]
176    let mut diag = dcx.struct_allow("");
177    let msg = e.diagnostic_message();
178    e.add_args(&mut diag);
179    let s = dcx.eagerly_translate_to_string(msg, diag.args.iter());
180    diag.cancel();
181    s
182}
183
184impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
185    pub fn new(
186        tcx: TyCtxt<'tcx>,
187        root_span: Span,
188        typing_env: ty::TypingEnv<'tcx>,
189        machine: M,
190    ) -> Self {
191        // Const eval always happens in post analysis mode in order to be able to use the hidden types of
192        // opaque types. This is needed for trivial things like `size_of`, but also for using associated
193        // types that are not specified in the opaque type. We also use MIR bodies whose opaque types have
194        // already been revealed, so we'd be able to at least partially observe the hidden types anyways.
195        debug_assert_matches!(typing_env.typing_mode, ty::TypingMode::PostAnalysis);
196        InterpCx {
197            machine,
198            tcx: tcx.at(root_span),
199            typing_env,
200            memory: Memory::new(),
201            recursion_limit: tcx.recursion_limit(),
202        }
203    }
204
205    /// Returns the span of the currently executed statement/terminator.
206    /// This is the span typically used for error reporting.
207    #[inline(always)]
208    pub fn cur_span(&self) -> Span {
209        // This deliberately does *not* honor `requires_caller_location` since it is used for much
210        // more than just panics.
211        self.stack().last().map_or(self.tcx.span, |f| f.current_span())
212    }
213
214    pub(crate) fn stack(&self) -> &[Frame<'tcx, M::Provenance, M::FrameExtra>] {
215        M::stack(self)
216    }
217
218    #[inline(always)]
219    pub(crate) fn stack_mut(&mut self) -> &mut Vec<Frame<'tcx, M::Provenance, M::FrameExtra>> {
220        M::stack_mut(self)
221    }
222
223    #[inline(always)]
224    pub fn frame_idx(&self) -> usize {
225        let stack = self.stack();
226        assert!(!stack.is_empty());
227        stack.len() - 1
228    }
229
230    #[inline(always)]
231    pub fn frame(&self) -> &Frame<'tcx, M::Provenance, M::FrameExtra> {
232        self.stack().last().expect("no call frames exist")
233    }
234
235    #[inline(always)]
236    pub fn frame_mut(&mut self) -> &mut Frame<'tcx, M::Provenance, M::FrameExtra> {
237        self.stack_mut().last_mut().expect("no call frames exist")
238    }
239
240    #[inline(always)]
241    pub fn body(&self) -> &'tcx mir::Body<'tcx> {
242        self.frame().body
243    }
244
245    #[inline]
246    pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
247        ty.is_freeze(*self.tcx, self.typing_env)
248    }
249
250    pub fn load_mir(
251        &self,
252        instance: ty::InstanceKind<'tcx>,
253        promoted: Option<mir::Promoted>,
254    ) -> InterpResult<'tcx, &'tcx mir::Body<'tcx>> {
255        trace!("load mir(instance={:?}, promoted={:?})", instance, promoted);
256        let body = if let Some(promoted) = promoted {
257            let def = instance.def_id();
258            &self.tcx.promoted_mir(def)[promoted]
259        } else {
260            M::load_mir(self, instance)?
261        };
262        // do not continue if typeck errors occurred (can only occur in local crate)
263        if let Some(err) = body.tainted_by_errors {
264            throw_inval!(AlreadyReported(ReportedErrorInfo::non_const_eval_error(err)));
265        }
266        interp_ok(body)
267    }
268
269    /// Call this on things you got out of the MIR (so it is as generic as the current
270    /// stack frame), to bring it into the proper environment for this interpreter.
271    pub fn instantiate_from_current_frame_and_normalize_erasing_regions<
272        T: TypeFoldable<TyCtxt<'tcx>>,
273    >(
274        &self,
275        value: T,
276    ) -> Result<T, ErrorHandled> {
277        self.instantiate_from_frame_and_normalize_erasing_regions(self.frame(), value)
278    }
279
280    /// Call this on things you got out of the MIR (so it is as generic as the provided
281    /// stack frame), to bring it into the proper environment for this interpreter.
282    pub fn instantiate_from_frame_and_normalize_erasing_regions<T: TypeFoldable<TyCtxt<'tcx>>>(
283        &self,
284        frame: &Frame<'tcx, M::Provenance, M::FrameExtra>,
285        value: T,
286    ) -> Result<T, ErrorHandled> {
287        frame
288            .instance
289            .try_instantiate_mir_and_normalize_erasing_regions(
290                *self.tcx,
291                self.typing_env,
292                ty::EarlyBinder::bind(value),
293            )
294            .map_err(|_| ErrorHandled::TooGeneric(self.cur_span()))
295    }
296
297    /// The `args` are assumed to already be in our interpreter "universe".
298    pub(super) fn resolve(
299        &self,
300        def: DefId,
301        args: GenericArgsRef<'tcx>,
302    ) -> InterpResult<'tcx, ty::Instance<'tcx>> {
303        trace!("resolve: {:?}, {:#?}", def, args);
304        trace!("typing_env: {:#?}", self.typing_env);
305        trace!("args: {:#?}", args);
306        match ty::Instance::try_resolve(*self.tcx, self.typing_env, def, args) {
307            Ok(Some(instance)) => interp_ok(instance),
308            Ok(None) => throw_inval!(TooGeneric),
309
310            // FIXME(eddyb) this could be a bit more specific than `AlreadyReported`.
311            Err(error_guaranteed) => throw_inval!(AlreadyReported(
312                ReportedErrorInfo::non_const_eval_error(error_guaranteed)
313            )),
314        }
315    }
316
317    /// Walks up the callstack from the intrinsic's callsite, searching for the first callsite in a
318    /// frame which is not `#[track_caller]`. This matches the `caller_location` intrinsic,
319    /// and is primarily intended for the panic machinery.
320    pub(crate) fn find_closest_untracked_caller_location(&self) -> Span {
321        for frame in self.stack().iter().rev() {
322            debug!("find_closest_untracked_caller_location: checking frame {:?}", frame.instance);
323
324            // Assert that the frame we look at is actually executing code currently
325            // (`loc` is `Right` when we are unwinding and the frame does not require cleanup).
326            let loc = frame.loc.left().unwrap();
327
328            // This could be a non-`Call` terminator (such as `Drop`), or not a terminator at all
329            // (such as `box`). Use the normal span by default.
330            let mut source_info = *frame.body.source_info(loc);
331
332            // If this is a `Call` terminator, use the `fn_span` instead.
333            let block = &frame.body.basic_blocks[loc.block];
334            if loc.statement_index == block.statements.len() {
335                debug!(
336                    "find_closest_untracked_caller_location: got terminator {:?} ({:?})",
337                    block.terminator(),
338                    block.terminator().kind,
339                );
340                if let mir::TerminatorKind::Call { fn_span, .. } = block.terminator().kind {
341                    source_info.span = fn_span;
342                }
343            }
344
345            let caller_location = if frame.instance.def.requires_caller_location(*self.tcx) {
346                // We use `Err(())` as indication that we should continue up the call stack since
347                // this is a `#[track_caller]` function.
348                Some(Err(()))
349            } else {
350                None
351            };
352            if let Ok(span) =
353                frame.body.caller_location_span(source_info, caller_location, *self.tcx, Ok)
354            {
355                return span;
356            }
357        }
358
359        span_bug!(self.cur_span(), "no non-`#[track_caller]` frame found")
360    }
361
362    /// Returns the actual dynamic size and alignment of the place at the given type.
363    /// Only the "meta" (metadata) part of the place matters.
364    /// This can fail to provide an answer for extern types.
365    pub(super) fn size_and_align_of(
366        &self,
367        metadata: &MemPlaceMeta<M::Provenance>,
368        layout: &TyAndLayout<'tcx>,
369    ) -> InterpResult<'tcx, Option<(Size, Align)>> {
370        if layout.is_sized() {
371            return interp_ok(Some((layout.size, layout.align.abi)));
372        }
373        match layout.ty.kind() {
374            ty::Adt(..) | ty::Tuple(..) => {
375                // First get the size of all statically known fields.
376                // Don't use type_of::sizing_type_of because that expects t to be sized,
377                // and it also rounds up to alignment, which we want to avoid,
378                // as the unsized field's alignment could be smaller.
379                assert!(!layout.ty.is_simd());
380                assert!(layout.fields.count() > 0);
381                trace!("DST layout: {:?}", layout);
382
383                let unsized_offset_unadjusted = layout.fields.offset(layout.fields.count() - 1);
384                let sized_align = layout.align.abi;
385
386                // Recurse to get the size of the dynamically sized field (must be
387                // the last field). Can't have foreign types here, how would we
388                // adjust alignment and size for them?
389                let field = layout.field(self, layout.fields.count() - 1);
390                let Some((unsized_size, mut unsized_align)) =
391                    self.size_and_align_of(metadata, &field)?
392                else {
393                    // A field with an extern type. We don't know the actual dynamic size
394                    // or the alignment.
395                    return interp_ok(None);
396                };
397
398                // # First compute the dynamic alignment
399
400                // Packed type alignment needs to be capped.
401                if let ty::Adt(def, _) = layout.ty.kind() {
402                    if let Some(packed) = def.repr().pack {
403                        unsized_align = unsized_align.min(packed);
404                    }
405                }
406
407                // Choose max of two known alignments (combined value must
408                // be aligned according to more restrictive of the two).
409                let full_align = sized_align.max(unsized_align);
410
411                // # Then compute the dynamic size
412
413                let unsized_offset_adjusted = unsized_offset_unadjusted.align_to(unsized_align);
414                let full_size = (unsized_offset_adjusted + unsized_size).align_to(full_align);
415
416                // Just for our sanitiy's sake, assert that this is equal to what codegen would compute.
417                assert_eq!(
418                    full_size,
419                    (unsized_offset_unadjusted + unsized_size).align_to(full_align)
420                );
421
422                // Check if this brought us over the size limit.
423                if full_size > self.max_size_of_val() {
424                    throw_ub!(InvalidMeta(InvalidMetaKind::TooBig));
425                }
426                interp_ok(Some((full_size, full_align)))
427            }
428            ty::Dynamic(expected_trait, _, ty::Dyn) => {
429                let vtable = metadata.unwrap_meta().to_pointer(self)?;
430                // Read size and align from vtable (already checks size).
431                interp_ok(Some(self.get_vtable_size_and_align(vtable, Some(expected_trait))?))
432            }
433
434            ty::Slice(_) | ty::Str => {
435                let len = metadata.unwrap_meta().to_target_usize(self)?;
436                let elem = layout.field(self, 0);
437
438                // Make sure the slice is not too big.
439                let size = elem.size.bytes().saturating_mul(len); // we rely on `max_size_of_val` being smaller than `u64::MAX`.
440                let size = Size::from_bytes(size);
441                if size > self.max_size_of_val() {
442                    throw_ub!(InvalidMeta(InvalidMetaKind::SliceTooBig));
443                }
444                interp_ok(Some((size, elem.align.abi)))
445            }
446
447            ty::Foreign(_) => interp_ok(None),
448
449            _ => span_bug!(self.cur_span(), "size_and_align_of::<{}> not supported", layout.ty),
450        }
451    }
452    #[inline]
453    pub fn size_and_align_of_mplace(
454        &self,
455        mplace: &MPlaceTy<'tcx, M::Provenance>,
456    ) -> InterpResult<'tcx, Option<(Size, Align)>> {
457        self.size_and_align_of(&mplace.meta(), &mplace.layout)
458    }
459
460    /// Jump to the given block.
461    #[inline]
462    pub fn go_to_block(&mut self, target: mir::BasicBlock) {
463        self.frame_mut().loc = Left(mir::Location { block: target, statement_index: 0 });
464    }
465
466    /// *Return* to the given `target` basic block.
467    /// Do *not* use for unwinding! Use `unwind_to_block` instead.
468    ///
469    /// If `target` is `None`, that indicates the function cannot return, so we raise UB.
470    pub fn return_to_block(&mut self, target: Option<mir::BasicBlock>) -> InterpResult<'tcx> {
471        if let Some(target) = target {
472            self.go_to_block(target);
473            interp_ok(())
474        } else {
475            throw_ub!(Unreachable)
476        }
477    }
478
479    /// *Unwind* to the given `target` basic block.
480    /// Do *not* use for returning! Use `return_to_block` instead.
481    ///
482    /// If `target` is `UnwindAction::Continue`, that indicates the function does not need cleanup
483    /// during unwinding, and we will just keep propagating that upwards.
484    ///
485    /// If `target` is `UnwindAction::Unreachable`, that indicates the function does not allow
486    /// unwinding, and doing so is UB.
487    #[cold] // usually we have normal returns, not unwinding
488    pub fn unwind_to_block(&mut self, target: mir::UnwindAction) -> InterpResult<'tcx> {
489        self.frame_mut().loc = match target {
490            mir::UnwindAction::Cleanup(block) => Left(mir::Location { block, statement_index: 0 }),
491            mir::UnwindAction::Continue => Right(self.frame_mut().body.span),
492            mir::UnwindAction::Unreachable => {
493                throw_ub_custom!(fluent::const_eval_unreachable_unwind);
494            }
495            mir::UnwindAction::Terminate(reason) => {
496                self.frame_mut().loc = Right(self.frame_mut().body.span);
497                M::unwind_terminate(self, reason)?;
498                // This might have pushed a new stack frame, or it terminated execution.
499                // Either way, `loc` will not be updated.
500                return interp_ok(());
501            }
502        };
503        interp_ok(())
504    }
505
506    /// Call a query that can return `ErrorHandled`. Should be used for statics and other globals.
507    /// (`mir::Const`/`ty::Const` have `eval` methods that can be used directly instead.)
508    pub fn ctfe_query<T>(
509        &self,
510        query: impl FnOnce(TyCtxtAt<'tcx>) -> Result<T, ErrorHandled>,
511    ) -> Result<T, ErrorHandled> {
512        // Use a precise span for better cycle errors.
513        query(self.tcx.at(self.cur_span())).map_err(|err| {
514            err.emit_note(*self.tcx);
515            err
516        })
517    }
518
519    pub fn eval_global(
520        &self,
521        instance: ty::Instance<'tcx>,
522    ) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
523        let gid = GlobalId { instance, promoted: None };
524        let val = if self.tcx.is_static(gid.instance.def_id()) {
525            let alloc_id = self.tcx.reserve_and_set_static_alloc(gid.instance.def_id());
526
527            let ty = instance.ty(self.tcx.tcx, self.typing_env);
528            mir::ConstAlloc { alloc_id, ty }
529        } else {
530            self.ctfe_query(|tcx| tcx.eval_to_allocation_raw(self.typing_env.as_query_input(gid)))?
531        };
532        self.raw_const_to_mplace(val)
533    }
534
535    pub fn eval_mir_constant(
536        &self,
537        val: &mir::Const<'tcx>,
538        span: Span,
539        layout: Option<TyAndLayout<'tcx>>,
540    ) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
541        M::eval_mir_constant(self, *val, span, layout, |ecx, val, span, layout| {
542            let const_val = val.eval(*ecx.tcx, ecx.typing_env, span).map_err(|err| {
543                if M::ALL_CONSTS_ARE_PRECHECKED {
544                    match err {
545                        ErrorHandled::TooGeneric(..) => {},
546                        ErrorHandled::Reported(reported, span) => {
547                            if reported.is_allowed_in_infallible() {
548                                // These errors can just sometimes happen, even when the expression
549                                // is nominally "infallible", e.g. when running out of memory
550                                // or when some layout could not be computed.
551                            } else {
552                                // Looks like the const is not captured by `required_consts`, that's bad.
553                                span_bug!(span, "interpret const eval failure of {val:?} which is not in required_consts");
554                            }
555                        }
556                    }
557                }
558                err.emit_note(*ecx.tcx);
559                err
560            })?;
561            ecx.const_val_to_op(const_val, val.ty(), layout)
562        })
563    }
564
565    #[must_use]
566    pub fn dump_place(&self, place: &PlaceTy<'tcx, M::Provenance>) -> PlacePrinter<'_, 'tcx, M> {
567        PlacePrinter { ecx: self, place: *place.place() }
568    }
569
570    #[must_use]
571    pub fn generate_stacktrace(&self) -> Vec<FrameInfo<'tcx>> {
572        Frame::generate_stacktrace_from_stack(self.stack())
573    }
574
575    pub fn adjust_nan<F1, F2>(&self, f: F2, inputs: &[F1]) -> F2
576    where
577        F1: rustc_apfloat::Float + rustc_apfloat::FloatConvert<F2>,
578        F2: rustc_apfloat::Float,
579    {
580        if f.is_nan() { M::generate_nan(self, inputs) } else { f }
581    }
582}
583
584#[doc(hidden)]
585/// Helper struct for the `dump_place` function.
586pub struct PlacePrinter<'a, 'tcx, M: Machine<'tcx>> {
587    ecx: &'a InterpCx<'tcx, M>,
588    place: Place<M::Provenance>,
589}
590
591impl<'a, 'tcx, M: Machine<'tcx>> std::fmt::Debug for PlacePrinter<'a, 'tcx, M> {
592    fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
593        match self.place {
594            Place::Local { local, offset, locals_addr } => {
595                debug_assert_eq!(locals_addr, self.ecx.frame().locals_addr());
596                let mut allocs = Vec::new();
597                write!(fmt, "{local:?}")?;
598                if let Some(offset) = offset {
599                    write!(fmt, "+{:#x}", offset.bytes())?;
600                }
601                write!(fmt, ":")?;
602
603                self.ecx.frame().locals[local].print(&mut allocs, fmt)?;
604
605                write!(fmt, ": {:?}", self.ecx.dump_allocs(allocs.into_iter().flatten().collect()))
606            }
607            Place::Ptr(mplace) => match mplace.ptr.provenance.and_then(Provenance::get_alloc_id) {
608                Some(alloc_id) => {
609                    write!(fmt, "by ref {:?}: {:?}", mplace.ptr, self.ecx.dump_alloc(alloc_id))
610                }
611                ptr => write!(fmt, " integral by ref: {ptr:?}"),
612            },
613        }
614    }
615}