X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_const_eval%2Fsrc%2Finterpret%2Fvalidity.rs;h=08102585a7b743342e526dbecd5ec94145105e7b;hb=27b7b3dcd6b0dddc1dae6d4412f05c4aec8aa72f;hp=847694cbd10cbaa2ad09859f5634cb15583a0fdb;hpb=ec82bc199611e7f1cf3acd612a65eed81d22636b;p=rust.git diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index 847694cbd10..08102585a7b 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -427,7 +427,7 @@ fn check_safe_pointer( err_ub!(DanglingIntPointer(0, _)) => { "a null {kind}" }, err_ub!(DanglingIntPointer(i, _)) => - { "a dangling {kind} (address 0x{i:x} is unallocated)" }, + { "a dangling {kind} (address {i:#x} is unallocated)" }, err_ub!(PointerOutOfBounds { .. }) => { "a dangling {kind} (going beyond the bounds of its allocation)" }, // This cannot happen during const-eval (because interning already detects @@ -593,16 +593,6 @@ fn try_visit_primitive( self.check_safe_pointer(value, "reference")?; Ok(true) } - ty::Adt(def, ..) if def.is_box() => { - let unique = self.ecx.operand_field(value, 0)?; - let nonnull = self.ecx.operand_field(&unique, 0)?; - let ptr = self.ecx.operand_field(&nonnull, 0)?; - self.check_safe_pointer(&ptr, "box")?; - - // Check other fields of Box - self.walk_value(value)?; - Ok(true) - } ty::FnPtr(_sig) => { let value = try_validation!( self.ecx.read_scalar(value).and_then(|v| v.check_init()), @@ -813,6 +803,12 @@ fn visit_union( Ok(()) } + #[inline] + fn visit_box(&mut self, op: &OpTy<'tcx, M::PointerTag>) -> InterpResult<'tcx> { + self.check_safe_pointer(op, "box")?; + Ok(()) + } + #[inline] fn visit_value(&mut self, op: &OpTy<'tcx, M::PointerTag>) -> InterpResult<'tcx> { trace!("visit_value: {:?}, {:?}", *op, op.layout); @@ -821,8 +817,6 @@ fn visit_value(&mut self, op: &OpTy<'tcx, M::PointerTag>) -> InterpResult<'tcx> if self.try_visit_primitive(op)? { return Ok(()); } - // Sanity check: `builtin_deref` does not know any pointers that are not primitive. - assert!(op.layout.ty.builtin_deref(true).is_none()); // Special check preventing `UnsafeCell` in the inner part of constants if let Some(def) = op.layout.ty.ty_adt_def() { @@ -947,7 +941,7 @@ fn visit_aggregate( // element that byte belongs to so we can // provide an index. let i = usize::try_from( - access.uninit_offset.bytes() / layout.size.bytes(), + access.uninit.start.bytes() / layout.size.bytes(), ) .unwrap(); self.path.push(PathElem::ArrayElem(i));