impl<Tag: Provenance> std::fmt::Display for ImmTy<'_, Tag> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
/// Helper function for printing a scalar to a FmtPrinter
- fn p<'a, 'tcx, F: std::fmt::Write, Tag: Provenance>(
- cx: FmtPrinter<'a, 'tcx, F>,
+ fn p<'a, 'tcx, Tag: Provenance>(
+ cx: FmtPrinter<'a, 'tcx>,
s: ScalarMaybeUninit<Tag>,
ty: Ty<'tcx>,
- ) -> Result<FmtPrinter<'a, 'tcx, F>, std::fmt::Error> {
+ ) -> Result<FmtPrinter<'a, 'tcx>, std::fmt::Error> {
match s {
ScalarMaybeUninit::Scalar(Scalar::Int(int)) => {
cx.pretty_print_const_scalar_int(int, ty, true)
match self.imm {
Immediate::Scalar(s) => {
if let Some(ty) = tcx.lift(self.layout.ty) {
- let cx = FmtPrinter::new(tcx, f, Namespace::ValueNS);
- p(cx, s, ty)?;
+ let cx = FmtPrinter::new(tcx, Namespace::ValueNS);
+ f.write_str(&p(cx, s, ty)?.into_buffer())?;
return Ok(());
}
- write!(f, "{}: {}", s, self.layout.ty)
+ write!(f, "{:x}: {}", s, self.layout.ty)
}
Immediate::ScalarPair(a, b) => {
// FIXME(oli-obk): at least print tuples and slices nicely
- write!(f, "({}, {}): {}", a, b, self.layout.ty,)
+ write!(f, "({:x}, {:x}): {}", a, b, self.layout.ty,)
}
}
})
op: &OpTy<'tcx, M::PointerTag>,
variant: VariantIdx,
) -> InterpResult<'tcx, OpTy<'tcx, M::PointerTag>> {
- // Downcasts only change the layout
Ok(match op.try_as_mplace() {
Ok(ref mplace) => self.mplace_downcast(mplace, variant)?.into(),
Err(..) => {
+ // Downcasts only change the layout.
+ // (In particular, no check about whether this is even the active variant -- that's by design,
+ // see https://github.com/rust-lang/rust/issues/93688#issuecomment-1032929496.)
let layout = op.layout.for_variant(self, variant);
OpTy { layout, ..*op }
}
Err(dbg_val) => {
// So this is a pointer then, and casting to an int failed.
// Can only happen during CTFE.
- let ptr = self.scalar_to_ptr(tag_val);
// The niche must be just 0, and the ptr not null, then we know this is
// okay. Everything else, we conservatively reject.
let ptr_valid = niche_start == 0
&& variants_start == variants_end
- && !self.memory.ptr_may_be_null(ptr);
+ && !self.scalar_may_be_null(tag_val);
if !ptr_valid {
throw_ub!(InvalidTag(dbg_val))
}