@@ -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 = {
@@ -191,9 +197,9 @@ fn split_hole(hole: HoleInfo, required_layout: Layout) -> Option<Allocation> {
191
197
/// found (and returns it).
192
198
fn allocate_first_fit ( mut previous : & mut Hole , layout : Layout ) -> Result < Allocation , AllocErr > {
193
199
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
+ } ) ;
197
203
match allocation {
198
204
Some ( allocation) => {
199
205
// 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
206
212
}
207
213
None => {
208
214
// 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 } ) ;
212
216
}
213
217
}
214
218
}
@@ -232,11 +236,15 @@ fn deallocate(mut hole: &mut Hole, addr: usize, mut size: usize) {
232
236
233
237
// Each freed block must be handled by the previous hole in memory. Thus the freed
234
238
// 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
+ ) ;
237
243
238
244
// 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 ( ) } ) ;
240
248
241
249
match next_hole_info {
242
250
Some ( next) if hole_addr + hole. size == addr && addr + size == next. addr => {
0 commit comments