Skip to content

Commit b3b4672

Browse files
committed
Run rustfmt
1 parent 3d91766 commit b3b4672

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

src/hole.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use core::ptr::NonNull;
1+
use core::alloc::{AllocErr, Layout, Opaque};
22
use core::mem::size_of;
3-
use core::alloc::{Layout, Opaque, AllocErr};
3+
use core::ptr::NonNull;
44

55
use super::align_up;
66

@@ -27,7 +27,10 @@ impl HoleList {
2727
assert!(size_of::<Hole>() == Self::min_size());
2828

2929
let ptr = hole_addr as *mut Hole;
30-
ptr.write(Hole { size: hole_size, next: None, });
30+
ptr.write(Hole {
31+
size: hole_size,
32+
next: None,
33+
});
3134

3235
HoleList {
3336
first: Hole {
@@ -75,7 +78,10 @@ impl HoleList {
7578
/// Returns information about the first hole for test purposes.
7679
#[cfg(test)]
7780
pub fn first_hole(&self) -> Option<(usize, usize)> {
78-
self.first.next.as_ref().map(|hole| ((*hole) as *const Hole as usize, hole.size))
81+
self.first
82+
.next
83+
.as_ref()
84+
.map(|hole| ((*hole) as *const Hole as usize, hole.size))
7985
}
8086
}
8187

@@ -185,9 +191,10 @@ fn split_hole(hole: HoleInfo, required_layout: Layout) -> Option<Allocation> {
185191
/// found (and returns it).
186192
fn allocate_first_fit(mut previous: &mut Hole, layout: Layout) -> Result<Allocation, AllocErr> {
187193
loop {
188-
let allocation: Option<Allocation> = previous.next.as_mut().and_then(|current| {
189-
split_hole(current.info(), layout.clone())
190-
});
194+
let allocation: Option<Allocation> = previous
195+
.next
196+
.as_mut()
197+
.and_then(|current| split_hole(current.info(), layout.clone()));
191198
match allocation {
192199
Some(allocation) => {
193200
// hole is big enough, so remove it from the list by updating the previous pointer

src/lib.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ extern crate std;
1010
#[cfg(feature = "use_spin")]
1111
extern crate spin;
1212

13-
use hole::{Hole, HoleList};
13+
use core::alloc::{Alloc, AllocErr, GlobalAlloc, Layout, Opaque};
1414
use core::mem;
15-
use core::ptr::NonNull;
1615
#[cfg(feature = "use_spin")]
1716
use core::ops::Deref;
18-
use core::alloc::{Alloc, GlobalAlloc, AllocErr, Layout, Opaque};
17+
use core::ptr::NonNull;
18+
use hole::{Hole, HoleList};
1919
#[cfg(feature = "use_spin")]
2020
use spin::Mutex;
2121

@@ -121,7 +121,8 @@ impl Heap {
121121
pub unsafe fn extend(&mut self, by: usize) {
122122
let top = self.top();
123123
let layout = Layout::from_size_align(by, 1).unwrap();
124-
self.holes.deallocate(NonNull::new_unchecked(top as *mut Opaque), layout);
124+
self.holes
125+
.deallocate(NonNull::new_unchecked(top as *mut Opaque), layout);
125126
self.size += by;
126127
}
127128
}
@@ -175,13 +176,17 @@ impl Deref for LockedHeap {
175176
#[cfg(feature = "use_spin")]
176177
unsafe impl GlobalAlloc for LockedHeap {
177178
unsafe fn alloc(&self, layout: Layout) -> *mut Opaque {
178-
self.0.lock().allocate_first_fit(layout).ok().map_or(0 as *mut Opaque, |allocation| {
179-
allocation.as_ptr()
180-
})
179+
self.0
180+
.lock()
181+
.allocate_first_fit(layout)
182+
.ok()
183+
.map_or(0 as *mut Opaque, |allocation| allocation.as_ptr())
181184
}
182185

183186
unsafe fn dealloc(&self, ptr: *mut Opaque, layout: Layout) {
184-
self.0.lock().deallocate(NonNull::new_unchecked(ptr), layout)
187+
self.0
188+
.lock()
189+
.deallocate(NonNull::new_unchecked(ptr), layout)
185190
}
186191

187192
fn oom(&self) -> ! {

src/test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use std::prelude::v1::*;
2-
use std::mem::{size_of, align_of};
3-
use core::alloc::Layout;
41
use super::*;
2+
use core::alloc::Layout;
3+
use std::mem::{align_of, size_of};
4+
use std::prelude::v1::*;
55

66
fn new_heap() -> Heap {
77
const HEAP_SIZE: usize = 1000;

0 commit comments

Comments
 (0)