Skip to content

Commit 7996f37

Browse files
committed
error IncorrectAllocationInformation
1 parent 2d7d90a commit 7996f37

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

src/librustc/mir/interpret/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::hir;
44
use crate::hir::map::definitions::DefPathData;
55
use crate::mir;
66
use crate::ty::{self, Ty, layout};
7-
use crate::ty::layout::{Size, Align, LayoutError};
7+
use crate::ty::layout::{Size, MemoryPosition, Align, LayoutError};
88
use crate::ty::query::TyCtxtAt;
99

1010
use backtrace::Backtrace;
@@ -438,7 +438,7 @@ pub enum UnsupportedOpInfo<'tcx> {
438438
DeallocatedWrongMemoryKind(String, String),
439439
ReallocateNonBasePtr,
440440
DeallocateNonBasePtr,
441-
IncorrectAllocationInformation(Size, Size, Align, Align),
441+
IncorrectAllocationInformation(MemoryPosition, MemoryPosition),
442442
HeapAllocZeroBytes,
443443
HeapAllocNonPowerOfTwoAlignment(u64),
444444
ReadFromReturnPointer,
@@ -484,10 +484,10 @@ impl fmt::Debug for UnsupportedOpInfo<'tcx> {
484484
write!(f, "expected primitive type, got {}", ty),
485485
PathNotFound(ref path) =>
486486
write!(f, "cannot find path {:?}", path),
487-
IncorrectAllocationInformation(size, size2, align, align2) =>
487+
IncorrectAllocationInformation(expect, got) =>
488488
write!(f, "incorrect alloc info: expected size {} and align {}, \
489489
got size {} and align {}",
490-
size.bytes(), align.bytes(), size2.bytes(), align2.bytes()),
490+
expect.size.bytes(), expect.align.bytes(), got.size.bytes(), got.align.bytes()),
491491
InvalidMemoryAccess =>
492492
write!(f, "tried to access memory through an invalid pointer"),
493493
DanglingPointerDeref =>

src/librustc/ty/layout.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,6 +2466,11 @@ impl_stable_hash_for!(struct crate::ty::layout::LayoutPositionPref {
24662466
align
24672467
});
24682468

2469+
impl_stable_hash_for!(struct crate::ty::layout::MemoryPosition {
2470+
size,
2471+
align
2472+
});
2473+
24692474
impl<'tcx> HashStable<StableHashingContext<'tcx>> for Align {
24702475
fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) {
24712476
self.bytes().hash_stable(hcx, hasher);

src/librustc_mir/interpret/memory.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,10 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
268268
format!("{:?}", kind),
269269
))
270270
}
271-
if let Some(MemoryPosition {size, align}) = old_mem_pos {
272-
if size != alloc.size || align != alloc.align {
273-
let bytes = alloc.size;
274-
throw_unsup!(IncorrectAllocationInformation(size, bytes, align, alloc.align))
271+
if let Some(mem_pos) = old_mem_pos {
272+
if mem_pos != MemoryPosition::new(alloc.size, alloc.align) {
273+
let got_mem_pos = MemoryPosition::new(alloc.size, alloc.align);
274+
throw_unsup!(IncorrectAllocationInformation(mem_pos, got_mem_pos))
275275
}
276276
}
277277

0 commit comments

Comments
 (0)