@@ -19,11 +19,13 @@ impl GcBox {
1919 /// **SAFETY:** The pointer must point to a valid `GcBoxInner` allocated
2020 /// in a `Box`.
2121 #[ inline( always) ]
22- pub ( crate ) unsafe fn erase < T : ?Sized > ( ptr : NonNull < GcBoxInner < T > > ) -> Self { unsafe {
23- // This cast is sound because `GcBoxInner` is `repr(C)`.
24- let erased = ptr. as_ptr ( ) as * mut GcBoxInner < ( ) > ;
25- Self ( NonNull :: new_unchecked ( erased) )
26- } }
22+ pub ( crate ) unsafe fn erase < T : ?Sized > ( ptr : NonNull < GcBoxInner < T > > ) -> Self {
23+ unsafe {
24+ // This cast is sound because `GcBoxInner` is `repr(C)`.
25+ let erased = ptr. as_ptr ( ) as * mut GcBoxInner < ( ) > ;
26+ Self ( NonNull :: new_unchecked ( erased) )
27+ }
28+ }
2729
2830 /// Gets a pointer to the value stored inside this box.
2931 /// `T` must be the same type that was used with `erase`, so that
@@ -47,31 +49,33 @@ impl GcBox {
4749 ///
4850 /// **SAFETY**: `Self::drop_in_place` must not have been called.
4951 #[ inline( always) ]
50- pub ( crate ) unsafe fn trace_value ( & self , cc : & crate :: Collection ) { unsafe {
51- ( self . header ( ) . vtable ( ) . trace_value ) ( * self , cc)
52- } }
52+ pub ( crate ) unsafe fn trace_value ( & self , cc : & crate :: Collection ) {
53+ unsafe { ( self . header ( ) . vtable ( ) . trace_value ) ( * self , cc) }
54+ }
5355
5456 /// Drops the stored value.
5557 ///
5658 /// **SAFETY**: once called, no GC pointers should access the stored value
5759 /// (but accessing the `GcBox` itself is still safe).
5860 #[ inline( always) ]
59- pub ( crate ) unsafe fn drop_in_place ( & mut self ) { unsafe {
60- ( self . header ( ) . vtable ( ) . drop_value ) ( * self )
61- } }
61+ pub ( crate ) unsafe fn drop_in_place ( & mut self ) {
62+ unsafe { ( self . header ( ) . vtable ( ) . drop_value ) ( * self ) }
63+ }
6264
6365 /// Deallocates the box. Failing to call `Self::drop_in_place` beforehand
6466 /// will cause the stored value to be leaked.
6567 ///
6668 /// **SAFETY**: once called, this `GcBox` should never be accessed by any GC
6769 /// pointers again.
6870 #[ inline( always) ]
69- pub ( crate ) unsafe fn dealloc ( self ) { unsafe {
70- let layout = self . header ( ) . vtable ( ) . box_layout ;
71- let ptr = self . 0 . as_ptr ( ) as * mut u8 ;
72- // SAFETY: the pointer was `Box`-allocated with this layout.
73- alloc:: alloc:: dealloc ( ptr, layout) ;
74- } }
71+ pub ( crate ) unsafe fn dealloc ( self ) {
72+ unsafe {
73+ let layout = self . header ( ) . vtable ( ) . box_layout ;
74+ let ptr = self . 0 . as_ptr ( ) as * mut u8 ;
75+ // SAFETY: the pointer was `Box`-allocated with this layout.
76+ alloc:: alloc:: dealloc ( ptr, layout) ;
77+ }
78+ }
7579}
7680
7781pub ( crate ) struct GcBoxHeader {
0 commit comments