Skip to content

Commit

Permalink
fix: add #[must_use] to volatile types
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Apr 25, 2024
1 parent 8be2e20 commit 8b576c3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/volatile_ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/volatile_ptr/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// });
Expand Down
8 changes: 4 additions & 4 deletions src/volatile_ptr/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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")]
Expand All @@ -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")]
Expand All @@ -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")]
Expand Down
1 change: 1 addition & 0 deletions src/volatile_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8b576c3

Please sign in to comment.