Skip to content

Commit 8b576c3

Browse files
committed
fix: add #[must_use] to volatile types
Signed-off-by: Martin Kröning <[email protected]>
1 parent 8be2e20 commit 8b576c3

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

src/volatile_ptr/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ mod very_unstable;
2424
/// to `ReadWrite`, which allows all operations.
2525
///
2626
/// The size of this struct is the same as the size of the contained reference.
27+
#[must_use]
2728
#[repr(transparent)]
2829
pub struct VolatilePtr<'a, T, A = ReadWrite>
2930
where

src/volatile_ptr/operations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ where
192192
/// // DON'T DO THIS:
193193
/// let mut readout = 0;
194194
/// unsafe {
195-
/// volatile.map(|value| {
195+
/// let _ = volatile.map(|value| {
196196
/// readout = *value.as_ptr(); // non-volatile read, might lead to bugs
197197
/// value
198198
/// });

src/volatile_ptr/tests.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn test_slice() {
128128
fn test_bounds_check_1() {
129129
let val: &mut [u32] = &mut [1, 2, 3];
130130
let volatile = unsafe { VolatilePtr::new(NonNull::from(val)) };
131-
volatile.index(3);
131+
let _ = volatile.index(3);
132132
}
133133

134134
#[cfg(feature = "unstable")]
@@ -138,7 +138,7 @@ fn test_bounds_check_2() {
138138
let val: &mut [u32] = &mut [1, 2, 3];
139139
let volatile = unsafe { VolatilePtr::new(NonNull::from(val)) };
140140
#[allow(clippy::reversed_empty_ranges)]
141-
volatile.index(2..1);
141+
let _ = volatile.index(2..1);
142142
}
143143

144144
#[cfg(feature = "unstable")]
@@ -147,7 +147,7 @@ fn test_bounds_check_2() {
147147
fn test_bounds_check_3() {
148148
let val: &mut [u32] = &mut [1, 2, 3];
149149
let volatile = unsafe { VolatilePtr::new(NonNull::from(val)) };
150-
volatile.index(4..); // `3..` is is still ok (see next test)
150+
let _ = volatile.index(4..); // `3..` is is still ok (see next test)
151151
}
152152

153153
#[cfg(feature = "unstable")]
@@ -164,7 +164,7 @@ fn test_bounds_check_4() {
164164
fn test_bounds_check_5() {
165165
let val: &mut [u32] = &mut [1, 2, 3];
166166
let volatile = unsafe { VolatilePtr::new(NonNull::from(val)) };
167-
volatile.index(..4);
167+
let _ = volatile.index(..4);
168168
}
169169

170170
#[cfg(feature = "unstable")]

src/volatile_ref.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use core::{cmp::Ordering, fmt, hash, marker::PhantomData, ptr::NonNull};
2525
/// to `ReadWrite`, which allows all operations.
2626
///
2727
/// The size of this struct is the same as the size of the contained reference.
28+
#[must_use]
2829
#[repr(transparent)]
2930
pub struct VolatileRef<'a, T, A = ReadWrite>
3031
where

0 commit comments

Comments
 (0)