Skip to content

Commit b84620f

Browse files
authored
extend comments
1 parent 1b374df commit b84620f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/tools/miri/src/alloc_bytes.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ pub struct MiriAllocBytes {
1414
layout: alloc::Layout,
1515
/// Pointer to the allocation contents.
1616
/// Invariant:
17-
/// * If `self.layout.size() == 0`, then `self.ptr` is some suitably aligned pointer
18-
/// that was allocated with the same layout but `size == 1`.
17+
/// * If `self.layout.size() == 0`, then `self.ptr` was allocated with the equivalent layout with size 1.
1918
/// * Otherwise, `self.ptr` points to memory allocated with `self.layout`.
2019
ptr: *mut u8,
2120
}
@@ -30,6 +29,8 @@ impl Clone for MiriAllocBytes {
3029

3130
impl Drop for MiriAllocBytes {
3231
fn drop(&mut self) {
32+
// We have to reconstruct the actual layout used for allocation.
33+
// (`Deref` relies on `size` so we can't just always set it to at least 1.)
3334
let alloc_layout = if self.layout.size() == 0 {
3435
Layout::from_size_align(1, self.layout.align()).unwrap()
3536
} else {

0 commit comments

Comments
 (0)