Skip to content

Commit 18b961f

Browse files
committed
Run rustfmt
1 parent 75883db commit 18b961f

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

src/hole.rs

+28-20
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ impl HoleList {
2727
assert!(size_of::<Hole>() == Self::min_size());
2828

2929
let ptr = hole_addr as *mut Hole;
30-
mem::replace(&mut *ptr,
31-
Hole {
32-
size: hole_size,
33-
next: None,
34-
});
30+
mem::replace(
31+
&mut *ptr,
32+
Hole {
33+
size: hole_size,
34+
next: None,
35+
},
36+
);
3537

3638
HoleList {
3739
first: Hole {
@@ -79,7 +81,9 @@ impl HoleList {
7981
/// Returns information about the first hole for test purposes.
8082
#[cfg(test)]
8183
pub fn first_hole(&self) -> Option<(usize, usize)> {
82-
self.first.next.as_ref().map(|hole| (hole.as_ptr() as usize, unsafe { hole.as_ref().size }))
84+
self.first.next.as_ref().map(|hole| {
85+
(hole.as_ptr() as usize, unsafe { hole.as_ref().size })
86+
})
8387
}
8488
}
8589

@@ -141,11 +145,13 @@ fn split_hole(hole: HoleInfo, required_layout: Layout) -> Option<Allocation> {
141145
} else {
142146
// the required alignment causes some padding before the allocation
143147
let aligned_addr = align_up(hole.addr + HoleList::min_size(), required_align);
144-
(aligned_addr,
145-
Some(HoleInfo {
146-
addr: hole.addr,
147-
size: aligned_addr - hole.addr,
148-
}))
148+
(
149+
aligned_addr,
150+
Some(HoleInfo {
151+
addr: hole.addr,
152+
size: aligned_addr - hole.addr,
153+
}),
154+
)
149155
};
150156

151157
let aligned_hole = {
@@ -191,9 +197,9 @@ fn split_hole(hole: HoleInfo, required_layout: Layout) -> Option<Allocation> {
191197
/// found (and returns it).
192198
fn allocate_first_fit(mut previous: &mut Hole, layout: Layout) -> Result<Allocation, AllocErr> {
193199
loop {
194-
let allocation: Option<Allocation> = previous.next
195-
.as_mut()
196-
.and_then(|current| split_hole(unsafe { current.as_ref() }.info(), layout.clone()));
200+
let allocation: Option<Allocation> = previous.next.as_mut().and_then(|current| {
201+
split_hole(unsafe { current.as_ref() }.info(), layout.clone())
202+
});
197203
match allocation {
198204
Some(allocation) => {
199205
// hole is big enough, so remove it from the list by updating the previous pointer
@@ -206,9 +212,7 @@ fn allocate_first_fit(mut previous: &mut Hole, layout: Layout) -> Result<Allocat
206212
}
207213
None => {
208214
// this was the last hole, so no hole is big enough -> allocation not possible
209-
return Err(AllocErr::Exhausted {
210-
request: layout,
211-
});
215+
return Err(AllocErr::Exhausted { request: layout });
212216
}
213217
}
214218
}
@@ -232,11 +236,15 @@ fn deallocate(mut hole: &mut Hole, addr: usize, mut size: usize) {
232236

233237
// Each freed block must be handled by the previous hole in memory. Thus the freed
234238
// address must be always behind the current hole.
235-
assert!(hole_addr + hole.size <= addr,
236-
"invalid deallocation (probably a double free)");
239+
assert!(
240+
hole_addr + hole.size <= addr,
241+
"invalid deallocation (probably a double free)"
242+
);
237243

238244
// get information about the next block
239-
let next_hole_info = hole.next.as_ref().map(|next| unsafe { next.as_ref().info() });
245+
let next_hole_info = hole.next
246+
.as_ref()
247+
.map(|next| unsafe { next.as_ref().info() });
240248

241249
match next_hole_info {
242250
Some(next) if hole_addr + hole.size == addr && addr + size == next.addr => {

src/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn allocate_double_usize() {
6161
fn allocate_and_free_double_usize() {
6262
let mut heap = new_heap();
6363

64-
let layout = Layout::from_size_align(size_of::<usize>() * 2, align_of::<usize>()).unwrap();
64+
let layout = Layout::from_size_align(size_of::<usize>() * 2, align_of::<usize>()).unwrap();
6565
let x = heap.allocate_first_fit(layout.clone()).unwrap();
6666
unsafe {
6767
*(x as *mut (usize, usize)) = (0xdeafdeadbeafbabe, 0xdeafdeadbeafbabe);

0 commit comments

Comments
 (0)