Skip to content

Commit

Permalink
style: Use PhantomData<T> in servo_arc.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed May 10, 2019
1 parent 1fba297 commit 29cecf6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion components/servo_arc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,14 @@ const STATIC_REFCOUNT: usize = usize::MAX;
/// See the documentation for [`Arc`] in the standard library. Unlike the
/// standard library `Arc`, this `Arc` does not support weak reference counting.
///
/// See the discussion in https://github.com/rust-lang/rust/pull/60594 for the
/// usage of PhantomData.
///
/// [`Arc`]: https://doc.rust-lang.org/stable/std/sync/struct.Arc.html
#[repr(C)]
pub struct Arc<T: ?Sized> {
p: ptr::NonNull<ArcInner<T>>,
phantom: PhantomData<T>,
}

/// An `Arc` that is known to be uniquely owned
Expand Down Expand Up @@ -169,6 +173,7 @@ impl<T> Arc<T> {
unsafe {
Arc {
p: ptr::NonNull::new_unchecked(Box::into_raw(x)),
phantom: PhantomData,
}
}
}
Expand Down Expand Up @@ -198,6 +203,7 @@ impl<T> Arc<T> {
let ptr = (ptr as *const u8).offset(-offset_of!(ArcInner<T>, data));
Arc {
p: ptr::NonNull::new_unchecked(ptr as *mut ArcInner<T>),
phantom: PhantomData,
}
}

Expand All @@ -224,6 +230,7 @@ impl<T> Arc<T> {

Arc {
p: ptr::NonNull::new_unchecked(ptr),
phantom: PhantomData,
}
}

Expand Down Expand Up @@ -334,6 +341,7 @@ impl<T: ?Sized> Clone for Arc<T> {
unsafe {
Arc {
p: ptr::NonNull::new_unchecked(self.ptr()),
phantom: PhantomData,
}
}
}
Expand Down Expand Up @@ -687,6 +695,7 @@ impl<H, T> Arc<HeaderSlice<H, [T]>> {
unsafe {
Arc {
p: ptr::NonNull::new_unchecked(ptr),
phantom: PhantomData,
}
}
}
Expand Down Expand Up @@ -768,6 +777,7 @@ type HeaderSliceWithLength<H, T> = HeaderSlice<HeaderWithLength<H>, T>;
#[repr(C)]
pub struct ThinArc<H, T> {
ptr: ptr::NonNull<ArcInner<HeaderSliceWithLength<H, [T; 1]>>>,
phantom: PhantomData<(H, T)>,
}

unsafe impl<H: Sync + Send, T: Sync + Send> Send for ThinArc<H, T> {}
Expand Down Expand Up @@ -797,6 +807,7 @@ impl<H, T> ThinArc<H, T> {
let transient = unsafe {
NoDrop::new(Arc {
p: ptr::NonNull::new_unchecked(thin_to_thick(self.ptr.as_ptr())),
phantom: PhantomData,
})
};

Expand Down Expand Up @@ -875,7 +886,7 @@ impl<H, T> Clone for ThinArc<H, T> {
impl<H, T> Drop for ThinArc<H, T> {
#[inline]
fn drop(&mut self) {
let _ = Arc::from_thin(ThinArc { ptr: self.ptr });
let _ = Arc::from_thin(ThinArc { ptr: self.ptr, phantom: PhantomData, });
}
}

Expand All @@ -896,6 +907,7 @@ impl<H, T> Arc<HeaderSliceWithLength<H, [T]>> {
ptr: unsafe {
ptr::NonNull::new_unchecked(thin_ptr as *mut ArcInner<HeaderSliceWithLength<H, [T; 1]>>)
},
phantom: PhantomData,
}
}

Expand All @@ -908,6 +920,7 @@ impl<H, T> Arc<HeaderSliceWithLength<H, [T]>> {
unsafe {
Arc {
p: ptr::NonNull::new_unchecked(ptr),
phantom: PhantomData,
}
}
}
Expand Down

0 comments on commit 29cecf6

Please sign in to comment.