diff --git a/src/lib.rs b/src/lib.rs index c9b8275..c137eb7 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. @@ -168,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)] @@ -266,6 +265,6 @@ impl ListHead { #[inline(always)] const fn offset() -> isize { - const { -(offset_of!(Inner, list) as isize) } + -(offset_of!(Inner, list) as isize) } }