From 1c5aac2b308445c7a03cdf9ff4b5457f7adbf1fb Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 7 Dec 2014 11:11:15 -0500 Subject: [PATCH] libarena: use unboxed closures --- src/libarena/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 95c4dff323e..1f4df1fd0a5 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -28,6 +28,7 @@ html_root_url = "http://doc.rust-lang.org/nightly/")] #![feature(unsafe_destructor)] +#![feature(unboxed_closures)] #![allow(missing_docs)] extern crate alloc; @@ -209,7 +210,7 @@ impl Arena { } #[inline] - fn alloc_copy(&self, op: || -> T) -> &mut T { + fn alloc_copy(&self, op: F) -> &mut T where F: FnOnce() -> T { unsafe { let ptr = self.alloc_copy_inner(mem::size_of::(), mem::min_align_of::()); @@ -263,7 +264,7 @@ impl Arena { } #[inline] - fn alloc_noncopy(&self, op: || -> T) -> &mut T { + fn alloc_noncopy(&self, op: F) -> &mut T where F: FnOnce() -> T { unsafe { let tydesc = get_tydesc::(); let (ty_ptr, ptr) = @@ -287,7 +288,7 @@ impl Arena { /// Allocates a new item in the arena, using `op` to initialize the value, /// and returns a reference to it. #[inline] - pub fn alloc(&self, op: || -> T) -> &mut T { + pub fn alloc(&self, op: F) -> &mut T where F: FnOnce() -> T { unsafe { if intrinsics::needs_drop::() { self.alloc_noncopy(op) @@ -339,7 +340,7 @@ fn test_arena_destructors_fail() { arena.alloc(|| { [0u8, 1u8, 2u8] }); } // Now, panic while allocating - arena.alloc::>(|| { + arena.alloc::, _>(|| { panic!(); }); }