diff --git a/src/volatile_ptr/mod.rs b/src/volatile_ptr/mod.rs index f625192..c34a2bd 100644 --- a/src/volatile_ptr/mod.rs +++ b/src/volatile_ptr/mod.rs @@ -24,6 +24,7 @@ mod very_unstable; /// to `ReadWrite`, which allows all operations. /// /// The size of this struct is the same as the size of the contained reference. +#[must_use] #[repr(transparent)] pub struct VolatilePtr<'a, T, A = ReadWrite> where diff --git a/src/volatile_ptr/operations.rs b/src/volatile_ptr/operations.rs index 05fbb5b..b3f0e0d 100644 --- a/src/volatile_ptr/operations.rs +++ b/src/volatile_ptr/operations.rs @@ -82,6 +82,7 @@ where /// }; /// assert_eq!(pointer.read(), 42); /// ``` + #[must_use] pub fn read(self) -> T where T: Copy, @@ -154,6 +155,7 @@ where /// /// assert_eq!(unsafe { *unwrapped }, 50); // non volatile access, be careful! /// ``` + #[must_use] pub fn as_raw_ptr(self) -> NonNull { self.pointer } @@ -191,10 +193,12 @@ where /// /// // DON'T DO THIS: /// let mut readout = 0; - /// unsafe { volatile.map(|value| { - /// readout = *value.as_ptr(); // non-volatile read, might lead to bugs - /// value - /// })}; + /// unsafe { + /// let _ = volatile.map(|value| { + /// readout = *value.as_ptr(); // non-volatile read, might lead to bugs + /// value + /// }); + /// }; /// ``` /// /// ## Safety diff --git a/src/volatile_ptr/tests.rs b/src/volatile_ptr/tests.rs index 479bec3..689a5f6 100644 --- a/src/volatile_ptr/tests.rs +++ b/src/volatile_ptr/tests.rs @@ -128,7 +128,7 @@ fn test_slice() { fn test_bounds_check_1() { let val: &mut [u32] = &mut [1, 2, 3]; let volatile = unsafe { VolatilePtr::new(NonNull::from(val)) }; - volatile.index(3); + let _ = volatile.index(3); } #[cfg(feature = "unstable")] @@ -138,7 +138,7 @@ fn test_bounds_check_2() { let val: &mut [u32] = &mut [1, 2, 3]; let volatile = unsafe { VolatilePtr::new(NonNull::from(val)) }; #[allow(clippy::reversed_empty_ranges)] - volatile.index(2..1); + let _ = volatile.index(2..1); } #[cfg(feature = "unstable")] @@ -147,7 +147,7 @@ fn test_bounds_check_2() { fn test_bounds_check_3() { let val: &mut [u32] = &mut [1, 2, 3]; let volatile = unsafe { VolatilePtr::new(NonNull::from(val)) }; - volatile.index(4..); // `3..` is is still ok (see next test) + let _ = volatile.index(4..); // `3..` is is still ok (see next test) } #[cfg(feature = "unstable")] @@ -164,7 +164,7 @@ fn test_bounds_check_4() { fn test_bounds_check_5() { let val: &mut [u32] = &mut [1, 2, 3]; let volatile = unsafe { VolatilePtr::new(NonNull::from(val)) }; - volatile.index(..4); + let _ = volatile.index(..4); } #[cfg(feature = "unstable")] diff --git a/src/volatile_ref.rs b/src/volatile_ref.rs index 5de3287..c0e7a31 100644 --- a/src/volatile_ref.rs +++ b/src/volatile_ref.rs @@ -25,6 +25,7 @@ use core::{cmp::Ordering, fmt, hash, marker::PhantomData, ptr::NonNull}; /// to `ReadWrite`, which allows all operations. /// /// The size of this struct is the same as the size of the contained reference. +#[must_use] #[repr(transparent)] pub struct VolatileRef<'a, T, A = ReadWrite> where