Skip to content

Commit

Permalink
Fixed most warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Tamschi committed Jul 25, 2024
1 parent 251ea12 commit 4f3f0fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ impl PartialEq for TipToe {

impl Eq for TipToe {}

#[allow(clippy::non_canonical_partial_ord_impl)]
impl PartialOrd for TipToe {
fn partial_cmp(&self, _: &Self) -> Option<cmp::Ordering> {
Some(cmp::Ordering::Equal)
Expand Down Expand Up @@ -152,6 +153,7 @@ pub mod ref_counter_api {
mod private {
#[cfg(not(feature = "sync"))]
use core::cell::Cell;
use core::ptr;
#[cfg(feature = "sync")]
use core::sync::atomic::AtomicUsize;

Expand All @@ -165,7 +167,7 @@ pub mod ref_counter_api {

fn refcount_ptr(&self) -> *mut usize {
#[cfg(feature = "sync")]
return self.refcount() as *const AtomicUsize as *mut usize;
return ptr::from_ref::<AtomicUsize>(self.refcount()) as *mut usize;
#[cfg(not(feature = "sync"))]
return self.refcount().as_ptr();
}
Expand Down Expand Up @@ -266,6 +268,7 @@ pub mod ref_counter_api {
/// and then dropping the resulting instance.
#[inline]
unsafe fn decrement(&self) -> DecrementFollowup {
#[allow(clippy::blocks_in_conditions)]
match {
#[cfg(feature = "sync")]
{
Expand Down Expand Up @@ -303,6 +306,7 @@ pub mod ref_counter_api {
/// Calling this method is equivalent to calling [`Rc::from_raw`](`crate::Rc::from_raw`)
/// and then dropping the resulting instance.
unsafe fn decrement_relaxed(&self) -> DecrementFollowup {
#[allow(clippy::blocks_in_conditions)]
match {
#[cfg(feature = "sync")]
{
Expand All @@ -329,6 +333,7 @@ pub mod ref_counter_api {
///
/// Dropping the [`Exclusivity`] performs a write to a remembered address, so **the borrowed instance must not be moved** until then.
unsafe fn acquire(&self) -> Option<Exclusivity> {
#[allow(clippy::blocks_in_conditions)]
match {
#[cfg(feature = "sync")]
{
Expand Down Expand Up @@ -358,6 +363,7 @@ pub mod ref_counter_api {
/// This is only suitable for synchronous reference-counting.
#[must_use]
fn acquire_relaxed(&self) -> Option<Exclusivity> {
#[allow(clippy::blocks_in_conditions)]
match {
#[cfg(feature = "sync")]
{
Expand Down
14 changes: 7 additions & 7 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use core::{
mem::{self, ManuallyDrop},
ops::Deref,
pin::Pin,
ptr::NonNull,
ptr::{self, NonNull},
};
use tap::{Pipe, Tap};

Expand Down Expand Up @@ -335,7 +335,7 @@ impl<T: ?Sized + IntrusivelyCountable> Arc<T> {
/// `inner` must be a reference to a reference to an instance managed by [`Arc`].
#[must_use]
pub unsafe fn borrow_from_inner_ref<'a>(inner: &'a &'a T) -> &'a Self {
&*(inner as *const &T).cast::<Self>()
&*ptr::from_ref::<&T>(inner).cast::<Self>()
}

/// Unsafely borrows a shared reference to a [`Pin<Arc>`]-managed instance as [`Pin<Arc>`].
Expand All @@ -347,7 +347,7 @@ impl<T: ?Sized + IntrusivelyCountable> Arc<T> {
/// `inner` must be a reference to a reference to an instance managed by [`Pin<Arc>`].
#[must_use]
pub unsafe fn borrow_pin_from_inner_ref<'a>(inner: &'a &'a T) -> &'a Pin<Self> {
&*(inner as *const &T).cast::<Pin<Self>>()
&*ptr::from_ref::<&T>(inner).cast::<Pin<Self>>()
}

/// Unwraps the payload pointer contained in the current instance.
Expand Down Expand Up @@ -378,7 +378,7 @@ impl<T: ?Sized + IntrusivelyCountable> Arc<T> {
/// Checks whether two instances of [`Arc<T>`] point to the same instance.
#[must_use]
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
this.pointer == other.pointer
ptr::addr_eq(this.pointer.as_ptr(), other.pointer.as_ptr())
}

/// Ensures the payload is exclusively pointed to by this [`Arc<T>`], cloning it if necessary,
Expand All @@ -392,7 +392,7 @@ impl<T: ?Sized + IntrusivelyCountable> Arc<T> {
// Safety:
// No effective encapsulation change happens.
// `Self::pin` does call `IntrusivelyCountable::ref_counter`, but this is legal as that method is not allowed to have effects.
(&**this).managed_clone().pipe(Self::pin)
(**this).managed_clone().pipe(Self::pin)
};

// This could be done faster, but whether that's significant is up to benchmarking it.
Expand All @@ -401,7 +401,7 @@ impl<T: ?Sized + IntrusivelyCountable> Arc<T> {

ExclusivePin::new(exclusivity, unsafe {
Pin::new_unchecked(
(*(this as *mut Pin<Self>).cast::<Arc<T>>())
(*ptr::from_mut::<Pin<Self>>(this).cast::<Arc<T>>())
.pointer
.as_mut(),
)
Expand All @@ -415,7 +415,7 @@ impl<T: ?Sized + IntrusivelyCountable> Arc<T> {
unsafe { this.ref_counter().acquire() }.map(|exclusivity| {
ExclusivePin::new(exclusivity, unsafe {
Pin::new_unchecked(
(*(this as *mut Pin<Self>).cast::<Arc<T>>())
(*ptr::from_mut::<Pin<Self>>(this).cast::<Arc<T>>())
.pointer
.as_mut(),
)
Expand Down

0 comments on commit 4f3f0fd

Please sign in to comment.