Skip to content

Commit

Permalink
Explicitly annotate unsafe blocks in unsafe fns
Browse files Browse the repository at this point in the history
This is a warning now that rust-lang/rfcs#2585 has landed.
  • Loading branch information
jacob-hughes committed Sep 8, 2020
1 parent 2b94e03 commit c258665
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions library/alloc/src/boehm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ pub(crate) struct BoehmGcAllocator;
#[unstable(feature = "allocator_api", issue = "32838")]
unsafe impl GlobalAlloc for BoehmAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
GC_malloc_uncollectable(layout.size()) as *mut u8
unsafe { GC_malloc_uncollectable(layout.size()) as *mut u8 }
}

unsafe fn dealloc(&self, ptr: *mut u8, _: Layout) {
GC_free(ptr as *mut c_void);
unsafe { GC_free(ptr as *mut c_void) };
}

unsafe fn realloc(&self, ptr: *mut u8, _: Layout, new_size: usize) -> *mut u8 {
GC_realloc(ptr as *mut c_void, new_size) as *mut u8
unsafe { GC_realloc(ptr as *mut c_void, new_size) as *mut u8 }
}
}

Expand Down
8 changes: 5 additions & 3 deletions library/alloc/src/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<T> Gc<MaybeUninit<T>> {
/// behaviour.
pub unsafe fn assume_init(self) -> Gc<T> {
let ptr = self.ptr.as_ptr() as *mut GcBox<MaybeUninit<T>>;
Gc::from_inner((&mut *ptr).assume_init())
unsafe { Gc::from_inner((&mut *ptr).assume_init()) }
}
}

Expand Down Expand Up @@ -139,7 +139,9 @@ impl<T> GcBox<T> {

fn register_finalizer(&mut self) {
unsafe extern "C" fn fshim<T>(obj: *mut c_void, _meta: *mut c_void) {
ManuallyDrop::drop(&mut *(obj as *mut ManuallyDrop<T>));
unsafe {
ManuallyDrop::drop(&mut *(obj as *mut ManuallyDrop<T>));
}
}

unsafe {
Expand Down Expand Up @@ -192,7 +194,7 @@ impl<T> GcBox<MaybeUninit<T>> {
// is reclaimed, T will be dropped. We need to find its vptr and replace the
// GcDummyDrop vptr in the block header with it.
self.register_finalizer();
NonNull::new_unchecked(self as *mut _ as *mut GcBox<T>)
unsafe { NonNull::new_unchecked(self as *mut _ as *mut GcBox<T>) }
}
}

Expand Down

0 comments on commit c258665

Please sign in to comment.