Skip to content

Commit 53deb0a

Browse files
committed
[pointer][invariant] Remove AliasingMapping
We previously used these to model `UnsafeCell` agreement, but that only works when we support an `Inaccessible` aliasing invariant, which we don't anymore. Future commits will use a different mechanism to model `UnsafeCell` agreement. There is no other circumstance under which a pointer can change its aliasing model. While we're here, make `Read` slightly more permissive, implemented for `A: Aliasing, T: Immutable` rather than just `A: Reference, T: Immutable`. Makes progress on #1122, #1866 gherrit-pr-id: I1ac2ae177a235083e33b09fc848423220d3da042
1 parent 4bd33fb commit 53deb0a

File tree

1 file changed

+4
-36
lines changed

1 file changed

+4
-36
lines changed

src/pointer/invariant.rs

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ impl<A: Aliasing, AA: Alignment, V: Validity> Invariants for (A, AA, V) {
5555
}
5656

5757
/// The aliasing invariant of a [`Ptr`][super::Ptr].
58+
///
59+
/// All aliasing invariants must permit reading from the bytes of a pointer's
60+
/// referent which are not covered by [`UnsafeCell`]s.
5861
pub trait Aliasing: Sealed {
5962
/// Is `Self` [`Exclusive`]?
6063
#[doc(hidden)]
@@ -65,9 +68,6 @@ pub trait Aliasing: Sealed {
6568
/// Aliasing>::Variance<'a, T>` to inherit this variance.
6669
#[doc(hidden)]
6770
type Variance<'a, T: 'a + ?Sized>;
68-
69-
#[doc(hidden)]
70-
type MappedTo<M: AliasingMapping>: Aliasing;
7171
}
7272

7373
/// The alignment invariant of a [`Ptr`][super::Ptr].
@@ -113,7 +113,6 @@ impl Aliasing for Inaccessible {
113113
//
114114
// [1] https://doc.rust-lang.org/1.81.0/reference/subtyping.html#variance
115115
type Variance<'a, T: 'a + ?Sized> = &'a T;
116-
type MappedTo<M: AliasingMapping> = M::FromInaccessible;
117116
}
118117

119118
/// The `Ptr<'a, T>` adheres to the aliasing rules of a `&'a T`.
@@ -128,7 +127,6 @@ pub enum Shared {}
128127
impl Aliasing for Shared {
129128
const IS_EXCLUSIVE: bool = false;
130129
type Variance<'a, T: 'a + ?Sized> = &'a T;
131-
type MappedTo<M: AliasingMapping> = M::FromShared;
132130
}
133131
impl Reference for Shared {}
134132

@@ -141,7 +139,6 @@ pub enum Exclusive {}
141139
impl Aliasing for Exclusive {
142140
const IS_EXCLUSIVE: bool = true;
143141
type Variance<'a, T: 'a + ?Sized> = &'a mut T;
144-
type MappedTo<M: AliasingMapping> = M::FromExclusive;
145142
}
146143
impl Reference for Exclusive {}
147144

@@ -230,7 +227,7 @@ define_because!(
230227
pub BecauseImmutable
231228
);
232229
// SAFETY: `T: Immutable`.
233-
unsafe impl<A: Reference, T: ?Sized + crate::Immutable> Read<A, BecauseImmutable> for T {}
230+
unsafe impl<A: Aliasing, T: ?Sized + crate::Immutable> Read<A, BecauseImmutable> for T {}
234231

235232
use sealed::Sealed;
236233
mod sealed {
@@ -257,23 +254,6 @@ pub use mapping::*;
257254
mod mapping {
258255
use super::*;
259256

260-
/// A mapping from one [`Aliasing`] type to another.
261-
///
262-
/// An `AliasingMapping` is a type-level map which maps one `Aliasing` type
263-
/// to another. It is always "total" in the sense of having a mapping for
264-
/// any `A: Aliasing`.
265-
///
266-
/// Given `A: Aliasing` and `M: AliasingMapping`, `M` can be applied to `A`
267-
/// as [`MappedAliasing<A, M>`](MappedAliasing).
268-
///
269-
/// Mappings are used by [`Ptr`](crate::Ptr) conversion methods to preserve
270-
/// or modify invariants as required by each method's semantics.
271-
pub trait AliasingMapping {
272-
type FromInaccessible: Aliasing;
273-
type FromShared: Aliasing;
274-
type FromExclusive: Aliasing;
275-
}
276-
277257
/// A mapping from one [`Alignment`] type to another.
278258
///
279259
/// An `AlignmentMapping` is a type-level map which maps one `Alignment`
@@ -308,10 +288,6 @@ mod mapping {
308288
type FromValid: Validity;
309289
}
310290

311-
/// The application of the [`AliasingMapping`] `M` to the [`Aliasing`] `A`.
312-
#[allow(type_alias_bounds)]
313-
pub type MappedAliasing<A: Aliasing, M: AliasingMapping> = A::MappedTo<M>;
314-
315291
/// The application of the [`AlignmentMapping`] `M` to the [`Alignment`] `A`.
316292
#[allow(type_alias_bounds)]
317293
pub type MappedAlignment<A: Alignment, M: AlignmentMapping> = A::MappedTo<M>;
@@ -320,14 +296,6 @@ mod mapping {
320296
#[allow(type_alias_bounds)]
321297
pub type MappedValidity<V: Validity, M: ValidityMapping> = V::MappedTo<M>;
322298

323-
impl<FromInaccessible: Aliasing, FromShared: Aliasing, FromExclusive: Aliasing> AliasingMapping
324-
for ((Inaccessible, FromInaccessible), (Shared, FromShared), (Exclusive, FromExclusive))
325-
{
326-
type FromInaccessible = FromInaccessible;
327-
type FromShared = FromShared;
328-
type FromExclusive = FromExclusive;
329-
}
330-
331299
impl<FromUnknown: Alignment, FromAligned: Alignment> AlignmentMapping
332300
for ((Unknown, FromUnknown), (Shared, FromAligned))
333301
{

0 commit comments

Comments
 (0)