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

[pointer] Remove ReadReason from Read trait #2409

Merged
merged 1 commit into from
Feb 28, 2025
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
7 changes: 1 addition & 6 deletions src/pointer/invariant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,27 +155,22 @@ unsafe impl<ST: ?Sized, DT: ?Sized> CastableFrom<ST, Initialized, Initialized> f
///
/// As a consequence, if `T: Read<A, R>`, then any `Ptr<T, (A, ...)>` is
/// permitted to perform unsynchronized reads from its referent.
pub trait Read<A: Aliasing, R: ReadReason> {}
pub trait Read<A: Aliasing, R> {}

impl<A: Aliasing, T: ?Sized + crate::Immutable> Read<A, BecauseImmutable> for T {}
impl<T: ?Sized> Read<Exclusive, BecauseExclusive> for T {}

/// Used to disambiguate [`Read`] impls.
pub trait ReadReason: Sealed {}

/// Unsynchronized reads are permitted because only one live [`Ptr`](crate::Ptr)
/// or reference may exist to the referent bytes at a time.
#[derive(Copy, Clone, Debug)]
#[doc(hidden)]
pub enum BecauseExclusive {}
impl ReadReason for BecauseExclusive {}

/// Unsynchronized reads are permitted because no live [`Ptr`](crate::Ptr)s or
/// references permit interior mutation.
#[derive(Copy, Clone, Debug)]
#[doc(hidden)]
pub enum BecauseImmutable {}
impl ReadReason for BecauseImmutable {}

use sealed::Sealed;
mod sealed {
Expand Down
3 changes: 1 addition & 2 deletions src/pointer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub mod invariant;
mod ptr;

#[doc(hidden)]
pub use invariant::{BecauseExclusive, BecauseImmutable, Read, ReadReason};
pub use invariant::{BecauseExclusive, BecauseImmutable, Read};
#[doc(hidden)]
pub use ptr::Ptr;

Expand Down Expand Up @@ -48,7 +48,6 @@ where
pub fn read_unaligned<R>(self) -> T
where
T: Copy,
R: invariant::ReadReason,
T: invariant::Read<Aliasing, R>,
{
// SAFETY: By invariant on `MaybeAligned`, `raw` contains
Expand Down
6 changes: 0 additions & 6 deletions src/pointer/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,6 @@ mod _transitions {
T: TryFromBytes + Read<I::Aliasing, R>,
I::Aliasing: Reference,
I: Invariants<Validity = Initialized>,
R: crate::pointer::ReadReason,
{
// This call may panic. If that happens, it doesn't cause any soundness
// issues, as we have not generated any invalid state which we need to
Expand Down Expand Up @@ -897,8 +896,6 @@ mod _casts {
where
T: Read<I::Aliasing, R>,
U: 'a + ?Sized + Read<I::Aliasing, S> + CastableFrom<T, I::Validity, I::Validity>,
R: ReadReason,
S: ReadReason,
F: FnOnce(*mut T) -> *mut U,
{
// SAFETY: Because `T` and `U` both implement `Read<I::Aliasing, _>`,
Expand All @@ -921,7 +918,6 @@ mod _casts {
#[allow(clippy::wrong_self_convention)]
pub(crate) fn as_bytes<R>(self) -> Ptr<'a, [u8], (I::Aliasing, Aligned, Valid)>
where
R: ReadReason,
T: Read<I::Aliasing, R>,
I::Aliasing: Reference,
{
Expand Down Expand Up @@ -1019,7 +1015,6 @@ mod _casts {
CastError<Self, U>,
>
where
R: ReadReason,
I::Aliasing: Reference,
U: 'a + ?Sized + KnownLayout + Read<I::Aliasing, R>,
{
Expand Down Expand Up @@ -1082,7 +1077,6 @@ mod _casts {
where
I::Aliasing: Reference,
U: 'a + ?Sized + KnownLayout + Read<I::Aliasing, R>,
R: ReadReason,
{
// TODO(#67): Remove this allow. See NonNulSlicelExt for more
// details.
Expand Down
3 changes: 1 addition & 2 deletions src/util/macro_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use core::mem::{self, ManuallyDrop};
use core::ptr::{self, NonNull};

use crate::{
pointer::invariant::{self, BecauseExclusive, BecauseImmutable, Invariants, ReadReason},
pointer::invariant::{self, BecauseExclusive, BecauseImmutable, Invariants},
FromBytes, Immutable, IntoBytes, Ptr, TryFromBytes, ValidityError,
};

Expand Down Expand Up @@ -561,7 +561,6 @@ where
Dst: TryFromBytes + invariant::Read<I::Aliasing, R>,
I: Invariants<Validity = invariant::Initialized>,
I::Aliasing: invariant::Reference,
R: ReadReason,
{
static_assert!(Src, Dst => mem::size_of::<Dst>() == mem::size_of::<Src>());

Expand Down
Loading