Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
The Miri Cronjob Bot committed Mar 10, 2024
1 parent bca5e33 commit 2ecfbae
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/tools/miri/tests/pass/box-custom-alloc-aliasing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
use std::{
alloc::{AllocError, Allocator, Layout},
cell::{Cell, UnsafeCell},
mem,
ptr::{self, addr_of, NonNull},
thread::{self, ThreadId},
mem,
};

const BIN_SIZE: usize = 8;
Expand All @@ -33,7 +33,7 @@ impl MyBin {
}
// Cast the *entire* thing to a raw pointer to not restrict its provenance.
let bin = self as *const MyBin;
let base_ptr = UnsafeCell::raw_get(unsafe{ addr_of!((*bin).memory )}).cast::<usize>();
let base_ptr = UnsafeCell::raw_get(unsafe { addr_of!((*bin).memory) }).cast::<usize>();
let ptr = unsafe { NonNull::new_unchecked(base_ptr.add(top)) };
self.top.set(top + 1);
Some(ptr.cast())
Expand Down Expand Up @@ -64,22 +64,14 @@ impl MyAllocator {
MyAllocator {
thread_id,
bins: Box::new(
[MyBin {
top: Cell::new(0),
thread_id,
memory: UnsafeCell::default(),
}; 1],
[MyBin { top: Cell::new(0), thread_id, memory: UnsafeCell::default() }; 1],
),
}
}

// Pretends to be expensive finding a suitable bin for the layout.
fn find_bin(&self, layout: Layout) -> Option<&MyBin> {
if layout == Layout::new::<usize>() {
Some(&self.bins[0])
} else {
None
}
if layout == Layout::new::<usize>() { Some(&self.bins[0]) } else { None }
}
}

Expand Down

0 comments on commit 2ecfbae

Please sign in to comment.