Skip to content

Commit c258665

Browse files
committed
Explicitly annotate unsafe blocks in unsafe fns
This is a warning now that rust-lang/rfcs#2585 has landed.
1 parent 2b94e03 commit c258665

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

library/alloc/src/boehm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ pub(crate) struct BoehmGcAllocator;
1313
#[unstable(feature = "allocator_api", issue = "32838")]
1414
unsafe impl GlobalAlloc for BoehmAllocator {
1515
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
16-
GC_malloc_uncollectable(layout.size()) as *mut u8
16+
unsafe { GC_malloc_uncollectable(layout.size()) as *mut u8 }
1717
}
1818

1919
unsafe fn dealloc(&self, ptr: *mut u8, _: Layout) {
20-
GC_free(ptr as *mut c_void);
20+
unsafe { GC_free(ptr as *mut c_void) };
2121
}
2222

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

library/alloc/src/gc.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<T> Gc<MaybeUninit<T>> {
9999
/// behaviour.
100100
pub unsafe fn assume_init(self) -> Gc<T> {
101101
let ptr = self.ptr.as_ptr() as *mut GcBox<MaybeUninit<T>>;
102-
Gc::from_inner((&mut *ptr).assume_init())
102+
unsafe { Gc::from_inner((&mut *ptr).assume_init()) }
103103
}
104104
}
105105

@@ -139,7 +139,9 @@ impl<T> GcBox<T> {
139139

140140
fn register_finalizer(&mut self) {
141141
unsafe extern "C" fn fshim<T>(obj: *mut c_void, _meta: *mut c_void) {
142-
ManuallyDrop::drop(&mut *(obj as *mut ManuallyDrop<T>));
142+
unsafe {
143+
ManuallyDrop::drop(&mut *(obj as *mut ManuallyDrop<T>));
144+
}
143145
}
144146

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

0 commit comments

Comments
 (0)