@@ -27,11 +27,13 @@ impl HoleList {
27
27
assert ! ( size_of:: <Hole >( ) == Self :: min_size( ) ) ;
28
28
29
29
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
+ ) ;
35
37
36
38
HoleList {
37
39
first : Hole {
@@ -79,7 +81,9 @@ impl HoleList {
79
81
/// Returns information about the first hole for test purposes.
80
82
#[ cfg( test) ]
81
83
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
+ } )
83
87
}
84
88
}
85
89
@@ -141,11 +145,13 @@ fn split_hole(hole: HoleInfo, required_layout: Layout) -> Option<Allocation> {
141
145
} else {
142
146
// the required alignment causes some padding before the allocation
143
147
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
+ )
149
155
} ;
150
156
151
157
let aligned_hole = {
@@ -192,9 +198,9 @@ fn split_hole(hole: HoleInfo, required_layout: Layout) -> Option<Allocation> {
192
198
/// found (and returns it).
193
199
fn allocate_first_fit ( mut previous : & mut Hole , layout : Layout ) -> Result < Allocation , AllocErr > {
194
200
loop {
195
- let allocation: Option < Allocation > = previous. next
196
- . as_mut ( )
197
- . and_then ( |current| split_hole ( unsafe { current . as_ref ( ) } . info ( ) , layout . clone ( ) ) ) ;
201
+ let allocation: Option < Allocation > = previous. next . as_mut ( ) . and_then ( |current| {
202
+ split_hole ( unsafe { current . as_ref ( ) } . info ( ) , layout . clone ( ) )
203
+ } ) ;
198
204
match allocation {
199
205
Some ( allocation) => {
200
206
// hole is big enough, so remove it from the list by updating the previous pointer
@@ -207,9 +213,7 @@ fn allocate_first_fit(mut previous: &mut Hole, layout: Layout) -> Result<Allocat
207
213
}
208
214
None => {
209
215
// this was the last hole, so no hole is big enough -> allocation not possible
210
- return Err ( AllocErr :: Exhausted {
211
- request : layout,
212
- } ) ;
216
+ return Err ( AllocErr :: Exhausted { request : layout } ) ;
213
217
}
214
218
}
215
219
}
@@ -233,11 +237,15 @@ fn deallocate(mut hole: &mut Hole, addr: usize, mut size: usize) {
233
237
234
238
// Each freed block must be handled by the previous hole in memory. Thus the freed
235
239
// address must be always behind the current hole.
236
- assert ! ( hole_addr + hole. size <= addr,
237
- "invalid deallocation (probably a double free)" ) ;
240
+ assert ! (
241
+ hole_addr + hole. size <= addr,
242
+ "invalid deallocation (probably a double free)"
243
+ ) ;
238
244
239
245
// get information about the next block
240
- let next_hole_info = hole. next . as_ref ( ) . map ( |next| unsafe { next. as_ref ( ) . info ( ) } ) ;
246
+ let next_hole_info = hole. next
247
+ . as_ref ( )
248
+ . map ( |next| unsafe { next. as_ref ( ) . info ( ) } ) ;
241
249
242
250
match next_hole_info {
243
251
Some ( next) if hole_addr + hole. size == addr && addr + size == next. addr => {
0 commit comments