Skip to content

Commit 7b63986

Browse files
Apply suggestions from code review
Co-authored-by: nikomatsakis <[email protected]>
1 parent 39e29ce commit 7b63986

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/liballoc/alloc.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,16 @@ unsafe impl AllocRef for Global {
215215
}
216216
ReallocPlacement::MayMove => {
217217
// `realloc` probably checks for `new_size > size` or something similar.
218-
unsafe {
218+
let ptr = unsafe {
219219
intrinsics::assume(new_size > size);
220-
let ptr = realloc(ptr.as_ptr(), layout, new_size);
221-
let memory =
222-
MemoryBlock { ptr: NonNull::new(ptr).ok_or(AllocErr)?, size: new_size };
220+
realloc(ptr.as_ptr(), layout, new_size)
221+
};
222+
let memory =
223+
MemoryBlock { ptr: NonNull::new(ptr).ok_or(AllocErr)?, size: new_size };
224+
unsafe {
223225
init.init_offset(memory, size);
224-
Ok(memory)
225226
}
227+
Ok(memory)
226228
}
227229
}
228230
}
@@ -255,11 +257,11 @@ unsafe impl AllocRef for Global {
255257
}
256258
ReallocPlacement::MayMove => {
257259
// `realloc` probably checks for `new_size < size` or something similar.
258-
unsafe {
260+
let ptr = unsafe {
259261
intrinsics::assume(new_size < size);
260-
let ptr = realloc(ptr.as_ptr(), layout, new_size);
261-
Ok(MemoryBlock { ptr: NonNull::new(ptr).ok_or(AllocErr)?, size: new_size })
262-
}
262+
realloc(ptr.as_ptr(), layout, new_size)
263+
};
264+
Ok(MemoryBlock { ptr: NonNull::new(ptr).ok_or(AllocErr)?, size: new_size })
263265
}
264266
}
265267
}

0 commit comments

Comments
 (0)