From 1fba297bbc1816b4b5498c56bef3add4cf886666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 7 May 2019 03:16:21 +0000 Subject: [PATCH] style: ThinArc should use NonNull. If only for parallelism with Arc<>. Differential Revision: https://phabricator.services.mozilla.com/D30131 --- components/servo_arc/lib.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/components/servo_arc/lib.rs b/components/servo_arc/lib.rs index f4a929e23f8..7d89238603f 100644 --- a/components/servo_arc/lib.rs +++ b/components/servo_arc/lib.rs @@ -21,7 +21,7 @@ //! //! [1]: https://bugzilla.mozilla.org/show_bug.cgi?id=1360883 -// The semantics of `Arc` are alread documented in the Rust docs, so we don't +// The semantics of `Arc` are already documented in the Rust docs, so we don't // duplicate those here. #![allow(missing_docs)] @@ -767,7 +767,7 @@ type HeaderSliceWithLength = HeaderSlice, T>; /// via `HeaderSliceWithLength`. #[repr(C)] pub struct ThinArc { - ptr: *mut ArcInner>, + ptr: ptr::NonNull>>, } unsafe impl Send for ThinArc {} @@ -796,7 +796,7 @@ impl ThinArc { // Synthesize transient Arc, which never touches the refcount of the ArcInner. let transient = unsafe { NoDrop::new(Arc { - p: ptr::NonNull::new_unchecked(thin_to_thick(self.ptr)), + p: ptr::NonNull::new_unchecked(thin_to_thick(self.ptr.as_ptr())), }) }; @@ -851,7 +851,7 @@ impl ThinArc { if is_static { ptr::null() } else { - self.ptr as *const ArcInner as *const c_void + self.ptr.as_ptr() as *const ArcInner as *const c_void } } } @@ -861,7 +861,7 @@ impl Deref for ThinArc { #[inline] fn deref(&self) -> &Self::Target { - unsafe { &(*thin_to_thick(self.ptr)).data } + unsafe { &(*thin_to_thick(self.ptr.as_ptr())).data } } } @@ -893,7 +893,9 @@ impl Arc> { mem::forget(a); let thin_ptr = fat_ptr as *mut [usize] as *mut usize; ThinArc { - ptr: thin_ptr as *mut ArcInner>, + ptr: unsafe { + ptr::NonNull::new_unchecked(thin_ptr as *mut ArcInner>) + }, } } @@ -901,7 +903,7 @@ impl Arc> { /// is not modified. #[inline] pub fn from_thin(a: ThinArc) -> Self { - let ptr = thin_to_thick(a.ptr); + let ptr = thin_to_thick(a.ptr.as_ptr()); mem::forget(a); unsafe { Arc {