Skip to content

Commit 1c5aac2

Browse files
author
Jorge Aparicio
committed
libarena: use unboxed closures
1 parent 341e7bc commit 1c5aac2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/libarena/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
html_root_url = "http://doc.rust-lang.org/nightly/")]
2929

3030
#![feature(unsafe_destructor)]
31+
#![feature(unboxed_closures)]
3132
#![allow(missing_docs)]
3233

3334
extern crate alloc;
@@ -209,7 +210,7 @@ impl Arena {
209210
}
210211

211212
#[inline]
212-
fn alloc_copy<T>(&self, op: || -> T) -> &mut T {
213+
fn alloc_copy<T, F>(&self, op: F) -> &mut T where F: FnOnce() -> T {
213214
unsafe {
214215
let ptr = self.alloc_copy_inner(mem::size_of::<T>(),
215216
mem::min_align_of::<T>());
@@ -263,7 +264,7 @@ impl Arena {
263264
}
264265

265266
#[inline]
266-
fn alloc_noncopy<T>(&self, op: || -> T) -> &mut T {
267+
fn alloc_noncopy<T, F>(&self, op: F) -> &mut T where F: FnOnce() -> T {
267268
unsafe {
268269
let tydesc = get_tydesc::<T>();
269270
let (ty_ptr, ptr) =
@@ -287,7 +288,7 @@ impl Arena {
287288
/// Allocates a new item in the arena, using `op` to initialize the value,
288289
/// and returns a reference to it.
289290
#[inline]
290-
pub fn alloc<T>(&self, op: || -> T) -> &mut T {
291+
pub fn alloc<T, F>(&self, op: F) -> &mut T where F: FnOnce() -> T {
291292
unsafe {
292293
if intrinsics::needs_drop::<T>() {
293294
self.alloc_noncopy(op)
@@ -339,7 +340,7 @@ fn test_arena_destructors_fail() {
339340
arena.alloc(|| { [0u8, 1u8, 2u8] });
340341
}
341342
// Now, panic while allocating
342-
arena.alloc::<Rc<int>>(|| {
343+
arena.alloc::<Rc<int>, _>(|| {
343344
panic!();
344345
});
345346
}

0 commit comments

Comments
 (0)