Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: remove unused NonNull imports #48

Merged
merged 3 commits into from
Apr 21, 2024
Merged
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
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
//! [in the `unsafe-code-guidelines` repository](https://github.com/rust-lang/unsafe-code-guidelines/issues/411).

#![no_std]
#![cfg_attr(feature = "unstable", feature(core_intrinsics))]

Check warning on line 35 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (unstable)

the feature `core_intrinsics` is internal to the compiler or standard library

Check warning on line 35 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (unstable)

the feature `core_intrinsics` is internal to the compiler or standard library

Check warning on line 35 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (very_unstable)

the feature `core_intrinsics` is internal to the compiler or standard library

Check warning on line 35 in src/lib.rs

View workflow job for this annotation

GitHub Actions / Test Suite (very_unstable)

the feature `core_intrinsics` is internal to the compiler or standard library
#![cfg_attr(feature = "unstable", feature(slice_range))]
#![cfg_attr(feature = "unstable", feature(slice_ptr_get))]
#![cfg_attr(feature = "very_unstable", feature(const_trait_impl))]
Expand All @@ -41,6 +41,9 @@
#![cfg_attr(feature = "very_unstable", feature(effects))]
#![warn(missing_docs)]
#![deny(unsafe_op_in_unsafe_fn)]
#![doc(test(attr(deny(warnings))))]
#![doc(test(attr(allow(dead_code))))]
#![doc(test(attr(allow(unused_variables))))]

pub use volatile_ptr::VolatilePtr;
pub use volatile_ref::VolatileRef;
Expand Down
6 changes: 2 additions & 4 deletions src/volatile_ptr/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
///
/// ```
/// use volatile::{VolatilePtr, map_field};
/// use core::ptr::NonNull;
///
/// struct Example { field_1: u32, field_2: u8, }
/// let mut value = Example { field_1: 15, field_2: 255 };
/// let mut volatile = unsafe { VolatilePtr::new((&mut value).into()) };
/// let volatile = unsafe { VolatilePtr::new((&mut value).into()) };
///
/// // construct a volatile reference to a field
/// let field_2 = map_field!(volatile.field_2);
Expand All @@ -20,12 +19,11 @@
/// Creating `VolatilePtr`s to unaligned field in packed structs is not allowed:
/// ```compile_fail
/// use volatile::{VolatilePtr, map_field};
/// use core::ptr::NonNull;
///
/// #[repr(packed)]
/// struct Example { field_1: u8, field_2: usize, }
/// let mut value = Example { field_1: 15, field_2: 255 };
/// let mut volatile = unsafe { VolatilePtr::new((&mut value).into()) };
/// let volatile = unsafe { VolatilePtr::new((&mut value).into()) };
///
/// // Constructing a volatile reference to an unaligned field doesn't compile.
/// let field_2 = map_field!(volatile.field_2);
Expand Down
24 changes: 9 additions & 15 deletions src/volatile_ptr/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ where
///
/// ```rust
/// use volatile::VolatilePtr;
/// use core::ptr::NonNull;
///
/// let mut value = 42;
/// let mut volatile = unsafe { VolatilePtr::new((&mut value).into()) };
/// let volatile = unsafe { VolatilePtr::new((&mut value).into()) };
/// volatile.write(50);
///
/// assert_eq!(volatile.read(), 50);
Expand All @@ -124,10 +123,9 @@ where
///
/// ```rust
/// use volatile::VolatilePtr;
/// use core::ptr::NonNull;
///
/// let mut value = 42;
/// let mut volatile = unsafe { VolatilePtr::new((&mut value).into()) };
/// let volatile = unsafe { VolatilePtr::new((&mut value).into()) };
/// volatile.update(|val| val + 1);
///
/// assert_eq!(volatile.read(), 43);
Expand All @@ -148,10 +146,9 @@ where
///
/// ```
/// use volatile::VolatilePtr;
/// use core::ptr::NonNull;
///
/// let mut value = 42;
/// let mut volatile = unsafe { VolatilePtr::new((&mut value).into()) };
/// let volatile = unsafe { VolatilePtr::new((&mut value).into()) };
/// volatile.write(50);
/// let unwrapped: *mut i32 = volatile.as_raw_ptr().as_ptr();
///
Expand All @@ -177,7 +174,7 @@ where
///
/// struct Example { field_1: u32, field_2: u8, }
/// let mut value = Example { field_1: 15, field_2: 255 };
/// let mut volatile = unsafe { VolatilePtr::new((&mut value).into()) };
/// let volatile = unsafe { VolatilePtr::new((&mut value).into()) };
///
/// // construct a volatile pointer to a field
/// let field_2 = unsafe { volatile.map(|ptr| NonNull::new(core::ptr::addr_of_mut!((*ptr.as_ptr()).field_2)).unwrap()) };
Expand All @@ -188,10 +185,9 @@ where
///
/// ```
/// use volatile::VolatilePtr;
/// use core::ptr::NonNull;
///
/// let mut value = 5;
/// let mut volatile = unsafe { VolatilePtr::new((&mut value).into()) };
/// let volatile = unsafe { VolatilePtr::new((&mut value).into()) };
///
/// // DON'T DO THIS:
/// let mut readout = 0;
Expand Down Expand Up @@ -228,7 +224,7 @@ where
/// use volatile::VolatilePtr;
///
/// let mut value: i16 = -4;
/// let mut volatile = unsafe { VolatilePtr::new((&mut value).into()) };
/// let volatile = unsafe { VolatilePtr::new((&mut value).into()) };
///
/// let read_only = volatile.restrict::<ReadOnly>();
/// assert_eq!(read_only.read(), -4);
Expand All @@ -247,10 +243,9 @@ where
///
/// ```
/// use volatile::VolatilePtr;
/// use core::ptr::NonNull;
///
/// let mut value: i16 = -4;
/// let mut volatile = unsafe { VolatilePtr::new((&mut value).into()) };
/// let volatile = unsafe { VolatilePtr::new((&mut value).into()) };
///
/// let read_only = volatile.read_only();
/// assert_eq!(read_only.read(), -4);
Expand All @@ -268,14 +263,13 @@ where
///
/// ```
/// use volatile::{VolatilePtr, map_field};
/// use core::ptr::NonNull;
///
/// struct Example { field_1: u32, field_2: u8, }
/// let mut value = Example { field_1: 15, field_2: 255 };
/// let mut volatile = unsafe { VolatilePtr::new((&mut value).into()) };
/// let volatile = unsafe { VolatilePtr::new((&mut value).into()) };
///
/// // construct a volatile write-only pointer to `field_2`
/// let mut field_2 = map_field!(volatile.field_2).write_only();
/// let field_2 = map_field!(volatile.field_2).write_only();
/// field_2.write(14);
/// // field_2.read(); // compile-time error
/// ```
Expand Down
8 changes: 4 additions & 4 deletions src/volatile_ptr/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl<'a, T, A> VolatilePtr<'a, [T], A> {
/// let mut dst = [0, 0];
/// // the `Volatile` type does not work with arrays, so convert `dst` to a slice
/// let slice = &mut dst[..];
/// let mut volatile = unsafe { VolatilePtr::new(NonNull::from(slice)) };
/// let volatile = unsafe { VolatilePtr::new(NonNull::from(slice)) };
/// // Because the slices have to be the same length,
/// // we slice the source slice from four elements
/// // to two. It will panic if we don't do this.
Expand Down Expand Up @@ -212,8 +212,8 @@ impl<'a, T, A> VolatilePtr<'a, [T], A> {
/// use core::ptr::NonNull;
///
/// let mut byte_array = *b"Hello, World!";
/// let mut slice: &mut [u8] = &mut byte_array[..];
/// let mut volatile = unsafe { VolatilePtr::new(NonNull::from(slice)) };
/// let slice: &mut [u8] = &mut byte_array[..];
/// let volatile = unsafe { VolatilePtr::new(NonNull::from(slice)) };
/// volatile.copy_within(1..5, 8);
///
/// assert_eq!(&byte_array, b"Hello, Wello!");
Expand Down Expand Up @@ -347,7 +347,7 @@ impl<A> VolatilePtr<'_, [u8], A> {
/// use core::ptr::NonNull;
///
/// let mut vec = vec![0; 10];
/// let mut buf = unsafe { VolatilePtr::new(NonNull::from(vec.as_mut_slice())) };
/// let buf = unsafe { VolatilePtr::new(NonNull::from(vec.as_mut_slice())) };
/// buf.fill(1);
/// assert_eq!(unsafe { buf.as_raw_ptr().as_mut() }, &mut vec![1; 10]);
/// ```
Expand Down
8 changes: 3 additions & 5 deletions src/volatile_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
/// use volatile::VolatileRef;
///
/// let mut value: i16 = -4;
/// let mut volatile = VolatileRef::from_mut_ref(&mut value);
/// let volatile = VolatileRef::from_mut_ref(&mut value);
///
/// let read_only = volatile.restrict::<ReadOnly>();
/// assert_eq!(read_only.as_ptr().read(), -4);
Expand All @@ -226,10 +226,9 @@
///
/// ```
/// use volatile::VolatileRef;
/// use core::ptr::NonNull;
///
/// let mut value: i16 = -4;
/// let mut volatile = VolatileRef::from_mut_ref(&mut value);
/// let volatile = VolatileRef::from_mut_ref(&mut value);
///
/// let read_only = volatile.read_only();
/// assert_eq!(read_only.as_ptr().read(), -4);
Expand All @@ -247,12 +246,11 @@
///
/// ```
/// use volatile::{VolatileRef};
/// use core::ptr::NonNull;
///
/// #[derive(Clone, Copy)]
/// struct Example { field_1: u32, field_2: u8, }
/// let mut value = Example { field_1: 15, field_2: 255 };
/// let mut volatile = VolatileRef::from_mut_ref(&mut value);
/// let volatile = VolatileRef::from_mut_ref(&mut value);
///
/// let write_only = volatile.write_only();
/// // write_only.as_ptr().read(); // compile-time error
Expand Down Expand Up @@ -316,7 +314,7 @@
T: ?Sized,
{
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(Ord::cmp(&self.pointer.as_ptr(), &other.pointer.as_ptr()))

Check warning on line 317 in src/volatile_ref.rs

View workflow job for this annotation

GitHub Actions / Test Suite (unstable)

ambiguous wide pointer comparison, the comparison includes metadata which may not be expected

Check warning on line 317 in src/volatile_ref.rs

View workflow job for this annotation

GitHub Actions / Test Suite (very_unstable)

ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
}
}

Expand All @@ -325,7 +323,7 @@
T: ?Sized,
{
fn cmp(&self, other: &Self) -> Ordering {
Ord::cmp(&self.pointer.as_ptr(), &other.pointer.as_ptr())

Check warning on line 326 in src/volatile_ref.rs

View workflow job for this annotation

GitHub Actions / Test Suite (unstable)

ambiguous wide pointer comparison, the comparison includes metadata which may not be expected

Check warning on line 326 in src/volatile_ref.rs

View workflow job for this annotation

GitHub Actions / Test Suite (very_unstable)

ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
}
}

Expand Down
Loading