From 0f4594fe28a322bfd53beb008d187fb3575f9287 Mon Sep 17 00:00:00 2001 From: Congyu Date: Sun, 18 Feb 2024 11:03:57 +0800 Subject: [PATCH 1/2] remove '[feature(offset_of)]' as it is stablized in 1.87 nightly --- src/lib.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c9b8275..3c4459c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,3 @@ -#![feature(offset_of)] -#![feature(inline_const)] use std::{ marker::PhantomData, mem::{offset_of, MaybeUninit}, @@ -132,7 +130,7 @@ impl Drop for LinkNode { impl ListHead { #[inline(always)] unsafe fn ptr(&mut self) -> NonNull> { - NonNull::new_unchecked(self as *mut ListHead) + NonNull::from(self) } /// Called when node is created. @@ -266,6 +264,6 @@ impl ListHead { #[inline(always)] const fn offset() -> isize { - const { -(offset_of!(Inner, list) as isize) } + -(offset_of!(Inner, list) as isize) } } From 5ba71ed84dac24e5647aab8dcab87d2f6af28991 Mon Sep 17 00:00:00 2001 From: Congyu Date: Sun, 18 Feb 2024 11:11:08 +0800 Subject: [PATCH 2/2] improve add() function --- src/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 3c4459c..c137eb7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -166,12 +166,13 @@ impl ListHead { /// is still complete. #[inline(always)] unsafe fn add(&mut self, other: &mut ListHead) { + let next = self.next.assume_init_mut().as_mut(); + let other_ptr = other.ptr(); + other.prev.write(self.ptr()); other.next = self.next; - - let next = self.next.assume_init_mut().as_mut(); - next.prev.write(other.ptr()); - self.next.write(other.ptr()); + next.prev.write(other_ptr); + self.next.write(other_ptr); } #[inline(always)]