Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![cfg_attr(feature = "unstable", allow(internal_features))]
#![warn(missing_docs)]
#![warn(clippy::missing_const_for_fn)]
#![deny(unsafe_op_in_unsafe_fn)]
#![doc(test(attr(deny(warnings))))]
#![doc(test(attr(allow(dead_code))))]
Expand Down
4 changes: 2 additions & 2 deletions src/volatile_ptr/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ where
/// - The given pointer must be valid.
/// - No other thread must have access to the given pointer. This must remain true
/// for the whole lifetime of the `VolatilePtr`.
pub unsafe fn new(pointer: NonNull<T>) -> VolatilePtr<'a, T, ReadWrite> {
pub const unsafe fn new(pointer: NonNull<T>) -> VolatilePtr<'a, T, ReadWrite> {
unsafe { VolatilePtr::new_restricted(ReadWrite, pointer) }
}

Expand Down Expand Up @@ -156,7 +156,7 @@ where
/// assert_eq!(unsafe { *unwrapped }, 50); // non volatile access, be careful!
/// ```
#[must_use]
pub fn as_raw_ptr(self) -> NonNull<T> {
pub const fn as_raw_ptr(self) -> NonNull<T> {
self.pointer
}

Expand Down
10 changes: 5 additions & 5 deletions src/volatile_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ where
/// chosen and does not necessarily reflect the actual lifetime of the data. In particular,
/// while this `VolatileRef` exists, the memory the pointer points to must not get accessed
/// (_read or written_) through any other pointer.
pub unsafe fn new(pointer: NonNull<T>) -> Self {
pub const unsafe fn new(pointer: NonNull<T>) -> Self {
unsafe { VolatileRef::new_restricted(ReadWrite, pointer) }
}

Expand Down Expand Up @@ -101,11 +101,11 @@ where
/// so the compiler is allowed to insert non-volatile reads. This might lead to undesired
/// (or even undefined?) behavior when accessing volatile data. So to be safe, only create
/// raw pointers to volatile data and use the [`Self::new`] constructor instead.
pub fn from_ref(reference: &'a T) -> VolatileRef<'a, T, ReadOnly>
pub const fn from_ref(reference: &'a T) -> VolatileRef<'a, T, ReadOnly>
where
T: 'a,
{
unsafe { VolatileRef::new_restricted(ReadOnly, reference.into()) }
unsafe { VolatileRef::new_restricted(ReadOnly, NonNull::from_ref(reference)) }
}

/// Creates a `VolatileRef` from the given mutable reference.
Expand All @@ -115,11 +115,11 @@ where
/// so the compiler is allowed to insert non-volatile reads. This might lead to undesired
/// (or even undefined?) behavior when accessing volatile data. So to be safe, only create
/// raw pointers to volatile data and use the [`Self::new`] constructor instead.
pub fn from_mut_ref(reference: &'a mut T) -> Self
pub const fn from_mut_ref(reference: &'a mut T) -> Self
where
T: 'a,
{
unsafe { VolatileRef::new(reference.into()) }
unsafe { VolatileRef::new(NonNull::from_ref(reference)) }
}

const unsafe fn new_generic<A>(pointer: NonNull<T>) -> VolatileRef<'a, T, A> {
Expand Down
Loading