From bafbac46f881ac3c96e61a902cb998a4ce387001 Mon Sep 17 00:00:00 2001 From: Kagamihime Date: Fri, 29 Dec 2017 23:04:21 +0100 Subject: [PATCH 1/2] rustfmt libarena/lib.rs --- src/libarena/lib.rs | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 2be7b1bc2e1..57a147b23fe 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -23,13 +23,11 @@ html_root_url = "https://doc.rust-lang.org/nightly/", test(no_crate_inject, attr(deny(warnings))))] #![deny(warnings)] - #![feature(alloc)] #![feature(core_intrinsics)] #![feature(dropck_eyepatch)] #![feature(generic_param_attrs)] #![cfg_attr(test, feature(test))] - #![allow(deprecated)] extern crate alloc; @@ -69,7 +67,9 @@ struct TypedArenaChunk { impl TypedArenaChunk { #[inline] unsafe fn new(capacity: usize) -> TypedArenaChunk { - TypedArenaChunk { storage: RawVec::with_capacity(capacity) } + TypedArenaChunk { + storage: RawVec::with_capacity(capacity), + } } /// Destroys this arena chunk. @@ -132,7 +132,9 @@ impl TypedArena { unsafe { if mem::size_of::() == 0 { - self.ptr.set(intrinsics::arith_offset(self.ptr.get() as *mut u8, 1) as *mut T); + self.ptr + .set(intrinsics::arith_offset(self.ptr.get() as *mut u8, 1) + as *mut T); let ptr = mem::align_of::() as *mut T; // Don't drop the object. This `write` is equivalent to `forget`. ptr::write(ptr, object); @@ -156,7 +158,9 @@ impl TypedArena { /// - Zero-length slices #[inline] pub fn alloc_slice(&self, slice: &[T]) -> &mut [T] - where T: Copy { + where + T: Copy, + { assert!(mem::size_of::() != 0); assert!(slice.len() != 0); @@ -320,7 +324,10 @@ impl DroplessArena { let (chunk, mut new_capacity); if let Some(last_chunk) = chunks.last_mut() { let used_bytes = self.ptr.get() as usize - last_chunk.start() as usize; - if last_chunk.storage.reserve_in_place(used_bytes, needed_bytes) { + if last_chunk + .storage + .reserve_in_place(used_bytes, needed_bytes) + { self.end.set(last_chunk.end()); return; } else { @@ -356,9 +363,9 @@ impl DroplessArena { let ptr = self.ptr.get(); // Set the pointer past ourselves - self.ptr.set(intrinsics::arith_offset( - self.ptr.get(), mem::size_of::() as isize - ) as *mut u8); + self.ptr.set( + intrinsics::arith_offset(self.ptr.get(), mem::size_of::() as isize) as *mut u8, + ); // Write into uninitialized memory. ptr::write(ptr as *mut T, object); &mut *(ptr as *mut T) @@ -373,7 +380,9 @@ impl DroplessArena { /// - Zero-length slices #[inline] pub fn alloc_slice(&self, slice: &[T]) -> &mut [T] - where T: Copy { + where + T: Copy, + { assert!(!mem::needs_drop::()); assert!(mem::size_of::() != 0); assert!(slice.len() != 0); @@ -389,7 +398,8 @@ impl DroplessArena { unsafe { let arena_slice = slice::from_raw_parts_mut(self.ptr.get() as *mut T, slice.len()); self.ptr.set(intrinsics::arith_offset( - self.ptr.get(), (slice.len() * mem::size_of::()) as isize + self.ptr.get(), + (slice.len() * mem::size_of::()) as isize, ) as *mut u8); arena_slice.copy_from_slice(slice); arena_slice @@ -454,8 +464,9 @@ mod tests { let arena = Wrap(TypedArena::new()); - let result = - arena.alloc_outer(|| Outer { inner: arena.alloc_inner(|| Inner { value: 10 }) }); + let result = arena.alloc_outer(|| Outer { + inner: arena.alloc_inner(|| Inner { value: 10 }), + }); assert_eq!(result.inner.value, 10); } From b2d0d184c3d69f499f3a2d4df1d99a548928ec53 Mon Sep 17 00:00:00 2001 From: Kagamihime Date: Fri, 29 Dec 2017 23:06:24 +0100 Subject: [PATCH 2/2] fixup --- src/libarena/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 57a147b23fe..a4d62617821 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -23,11 +23,13 @@ html_root_url = "https://doc.rust-lang.org/nightly/", test(no_crate_inject, attr(deny(warnings))))] #![deny(warnings)] + #![feature(alloc)] #![feature(core_intrinsics)] #![feature(dropck_eyepatch)] #![feature(generic_param_attrs)] #![cfg_attr(test, feature(test))] + #![allow(deprecated)] extern crate alloc;