1313//! Invariants are encoded as ([`Aliasing`], [`Alignment`], [`Validity`])
1414//! triples implementing the [`Invariants`] trait.
1515
16- use super :: * ;
17-
1816/// The invariants of a [`Ptr`][super::Ptr].
1917pub trait Invariants : Sealed {
2018 type Aliasing : Aliasing ;
@@ -82,6 +80,15 @@ pub trait Aliasing:
8280 /// Aliasing>::Variance<'a, T>` to inherit this variance.
8381 #[ doc( hidden) ]
8482 type Variance < ' a , T : ' a + ?Sized > ;
83+
84+ // #[doc(hidden)]
85+ // type Applied<'a, T: 'a + ?Sized>;
86+
87+ // #[doc(hidden)]
88+ // fn into_ptr<'a, T: 'a + ?Sized>(ptr: Self::Applied<'a, T>) -> PtrInner<'a, T>;
89+
90+ // #[doc(hidden)]
91+ // unsafe fn from_ptr<'a, T: 'a + ?Sized>(ptr: PtrInner<'a, T>) -> Self::Applied<'a, T>;
8592}
8693
8794#[ doc( hidden) ]
@@ -136,14 +143,7 @@ impl<
136143///
137144/// Given `A: Reference`, callers may assume that either `A = Shared` or `A =
138145/// Exclusive`.
139- pub trait Reference : Aliasing + Sealed {
140- fn with < ' a , T , I , S , E , O > ( ptr : Ptr < ' a , T , I > , shared : S , exclusive : E ) -> O
141- where
142- T : ' a + ?Sized ,
143- I : Invariants < Aliasing = Self > ,
144- S : FnOnce ( Ptr < ' a , T , I :: WithAliasing < Shared > > ) -> O ,
145- E : FnOnce ( Ptr < ' a , T , I :: WithAliasing < Exclusive > > ) -> O ;
146- }
146+ pub trait Reference : ReadFoo + Sealed { }
147147
148148/// It is unknown whether any invariant holds.
149149pub enum Unknown { }
@@ -171,18 +171,7 @@ impl Aliasing for Shared {
171171 const IS_EXCLUSIVE : bool = false ;
172172 type Variance < ' a , T : ' a + ?Sized > = & ' a T ;
173173}
174- impl Reference for Shared {
175- #[ inline( always) ]
176- fn with < ' a , T , I , S , E , O > ( ptr : Ptr < ' a , T , I > , shared : S , _exclusive : E ) -> O
177- where
178- T : ' a + ?Sized ,
179- I : Invariants < Aliasing = Shared > ,
180- S : FnOnce ( Ptr < ' a , T , I :: WithAliasing < Shared > > ) -> O ,
181- E : FnOnce ( Ptr < ' a , T , I :: WithAliasing < Exclusive > > ) -> O ,
182- {
183- shared ( ptr. unify_invariants ( ) )
184- }
185- }
174+ impl Reference for Shared { }
186175
187176/// The `Ptr<'a, T>` adheres to the aliasing rules of a `&'a mut T`.
188177///
@@ -197,16 +186,41 @@ impl Aliasing for Exclusive {
197186 const IS_EXCLUSIVE : bool = true ;
198187 type Variance < ' a , T : ' a + ?Sized > = & ' a mut T ;
199188}
200- impl Reference for Exclusive {
201- #[ inline( always) ]
202- fn with < ' a , T , I , S , E , O > ( ptr : Ptr < ' a , T , I > , _shared : S , exclusive : E ) -> O
203- where
204- T : ' a + ?Sized ,
205- I : Invariants < Aliasing = Exclusive > ,
206- S : FnOnce ( Ptr < ' a , T , I :: WithAliasing < Shared > > ) -> O ,
207- E : FnOnce ( Ptr < ' a , T , I :: WithAliasing < Exclusive > > ) -> O ,
208- {
209- exclusive ( ptr. unify_invariants ( ) )
189+ impl Reference for Exclusive { }
190+
191+ #[ cfg( feature = "alloc" ) ]
192+ pub use _alloc:: * ;
193+ #[ cfg( feature = "alloc" ) ]
194+ mod _alloc {
195+ use alloc:: boxed:: Box as Bx ;
196+
197+ use super :: * ;
198+
199+ pub enum Box { }
200+ impl AliasingInner for Box {
201+ // type MappedTo<M: AliasingMapping> = M::FromBox;
202+ }
203+ impl Aliasing for Box {
204+ const IS_EXCLUSIVE : bool = true ;
205+ type Variance < ' a , T : ' a + ?Sized > = Bx < T > ;
206+ }
207+ }
208+
209+ #[ cfg( feature = "std" ) ]
210+ pub use _std:: * ;
211+ #[ cfg( feature = "std" ) ]
212+ mod _std {
213+ use std:: sync:: Arc as Ac ;
214+
215+ use super :: * ;
216+
217+ pub enum Arc { }
218+ impl AliasingInner for Arc {
219+ // type MappedTo<M: AliasingMapping> = M::FromArc;
220+ }
221+ impl Aliasing for Arc {
222+ const IS_EXCLUSIVE : bool = true ;
223+ type Variance < ' a , T : ' a + ?Sized > = Ac < T > ;
210224 }
211225}
212226
@@ -261,6 +275,27 @@ impl ValidityInner for Valid {
261275 type MappedTo < M : ValidityMapping > = M :: FromValid ;
262276}
263277
278+ // Aliasing modes that permit reading at all (ie, everything but Inaccessible).
279+ pub trait ReadFoo : Aliasing { }
280+ impl ReadFoo for Shared { }
281+ impl ReadFoo for Exclusive { }
282+ #[ cfg( feature = "alloc" ) ]
283+ impl ReadFoo for Box { }
284+ #[ cfg( feature = "std" ) ]
285+ impl ReadFoo for Arc { }
286+
287+ // Shared, Arc, etc
288+ pub trait SharedFoo : Aliasing { }
289+ impl SharedFoo for Shared { }
290+ #[ cfg( feature = "std" ) ]
291+ impl SharedFoo for Arc { }
292+
293+ // Exclusive, Box, etc
294+ pub trait ExclusiveFoo : Aliasing { }
295+ impl ExclusiveFoo for Exclusive { }
296+ #[ cfg( feature = "alloc" ) ]
297+ impl ExclusiveFoo for Box { }
298+
264299/// [`Ptr`](crate::Ptr) referents that permit unsynchronized read operations.
265300///
266301/// `T: Read<A, R>` implies that a pointer to `T` with aliasing `A` permits
@@ -285,8 +320,7 @@ define_because!(
285320 #[ doc( hidden) ]
286321 pub BecauseExclusive
287322) ;
288- // SAFETY: The aliasing parameter is `Exclusive`.
289- unsafe impl < T : ?Sized > Read < Exclusive , BecauseExclusive > for T { }
323+ unsafe impl < A : ExclusiveFoo , T : ?Sized > Read < A , BecauseExclusive > for T { }
290324
291325define_because ! (
292326 /// Unsynchronized reads are permitted because no live [`Ptr`](crate::Ptr)s
@@ -295,7 +329,7 @@ define_because!(
295329 pub BecauseImmutable
296330) ;
297331// SAFETY: `T: Immutable`.
298- unsafe impl < A : Reference , T : ?Sized + crate :: Immutable > Read < A , BecauseImmutable > for T { }
332+ unsafe impl < A : ReadFoo , T : ?Sized + crate :: Immutable > Read < A , BecauseImmutable > for T { }
299333
300334use sealed:: Sealed ;
301335mod sealed {
@@ -308,6 +342,10 @@ mod sealed {
308342 // impl Sealed for Inaccessible {}
309343 impl Sealed for Shared { }
310344 impl Sealed for Exclusive { }
345+ #[ cfg( feature = "alloc" ) ]
346+ impl Sealed for Box { }
347+ #[ cfg( feature = "std" ) ]
348+ impl Sealed for Arc { }
311349
312350 impl Sealed for Aligned { }
313351
0 commit comments