From 8be2e2001f11bad97bf3483403b3aab0b967535a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 24 Apr 2024 13:16:09 +0200 Subject: [PATCH 1/4] style(docs): format `map` example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/volatile_ptr/operations.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/volatile_ptr/operations.rs b/src/volatile_ptr/operations.rs index 54c172d..0e69bbd 100644 --- a/src/volatile_ptr/operations.rs +++ b/src/volatile_ptr/operations.rs @@ -191,10 +191,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 { + /// volatile.map(|value| { + /// readout = *value.as_ptr(); // non-volatile read, might lead to bugs + /// value + /// }); + /// }; /// ``` /// /// ## Safety From 8b576c37bb041b6feec65291d9bc0cfc86d6590c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Wed, 24 Apr 2024 13:16:51 +0200 Subject: [PATCH 2/4] fix: add `#[must_use]` to volatile types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/volatile_ptr/mod.rs | 1 + src/volatile_ptr/operations.rs | 2 +- src/volatile_ptr/tests.rs | 8 ++++---- src/volatile_ref.rs | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/volatile_ptr/mod.rs b/src/volatile_ptr/mod.rs index 0f1cbad..de9bc99 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 0e69bbd..84abcca 100644 --- a/src/volatile_ptr/operations.rs +++ b/src/volatile_ptr/operations.rs @@ -192,7 +192,7 @@ where /// // DON'T DO THIS: /// let mut readout = 0; /// unsafe { - /// volatile.map(|value| { + /// let _ = volatile.map(|value| { /// readout = *value.as_ptr(); // non-volatile read, might lead to bugs /// value /// }); 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 836b87d..4de7968 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 From 8046e4d391f4530d83ee1cac4d760668ffaf3818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Thu, 25 Apr 2024 15:49:59 +0200 Subject: [PATCH 3/4] fix: add `#[must_use]` to `VolatilePtr::read` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/volatile_ptr/operations.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/volatile_ptr/operations.rs b/src/volatile_ptr/operations.rs index 84abcca..320bfd2 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, From da0f987353c4085380349ecb6529b5153cb49b9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Thu, 25 Apr 2024 15:53:23 +0200 Subject: [PATCH 4/4] fix: add `#[must_use]` to `VolatilePtr::as_raw_ptr` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/volatile_ptr/operations.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/volatile_ptr/operations.rs b/src/volatile_ptr/operations.rs index 320bfd2..2197134 100644 --- a/src/volatile_ptr/operations.rs +++ b/src/volatile_ptr/operations.rs @@ -155,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 }