pub type List<T> = RawList<(), T>;
Expand description
List<T>
is a bit like &[T]
, but with some critical differences.
- IMPORTANT: Every
List<T>
is required to have unique contents. The type’s correctness relies on this, but it does not enforce it. Therefore, any code that creates aList<T>
must ensure uniqueness itself. In practice this is achieved by interning. - The length is stored within the
List<T>
, so&List<Ty>
is a thin pointer. - Because of this, you cannot get a
List<T>
that is a sub-list of anotherList<T>
. You can get a sub-slice&[T]
, however. List<T>
can be used withCopyTaggedPtr
, which is useful within structs whose size must be minimized.- Because of the uniqueness assumption, we can use the address of a
List<T>
for faster equality comparisons and hashing. T
must beCopy
. This letsList<T>
be stored in a dropless arena and iterators return aT
rather than a&T
.T
must not be zero-sized.
Aliased Type§
struct List<T> {
skel: ListSkeleton<(), T>,
opaque: OpaqueListContents,
}
Fields§
§skel: ListSkeleton<(), T>
§opaque: OpaqueListContents
Implementations§
source§impl<'tcx> List<PolyExistentialPredicate<'tcx>>
impl<'tcx> List<PolyExistentialPredicate<'tcx>>
sourcepub fn principal(&self) -> Option<Binder<'tcx, ExistentialTraitRef<'tcx>>>
pub fn principal(&self) -> Option<Binder<'tcx, ExistentialTraitRef<'tcx>>>
Returns the “principal DefId
” of this set of existential predicates.
A Rust trait object type consists (in addition to a lifetime bound) of a set of trait bounds, which are separated into any number of auto-trait bounds, and at most one non-auto-trait bound. The non-auto-trait bound is called the “principal” of the trait object.
Only the principal can have methods or type parameters (because auto traits can have neither of them). This is important, because it means the auto traits can be treated as an unordered set (methods would force an order for the vtable, while relating traits with type parameters without knowing the order to relate them in is a rather non-trivial task).
For example, in the trait object dyn std::fmt::Debug + Sync
, the
principal bound is Some(std::fmt::Debug)
, while the auto-trait bounds
are the set {Sync}
.
It is also possible to have a “trivial” trait object that
consists only of auto traits, with no principal - for example,
dyn Send + Sync
. In that case, the set of auto-trait bounds
is {Send, Sync}
, while there is no principal. These trait objects
have a “trivial” vtable consisting of just the size, alignment,
and destructor.
pub fn principal_def_id(&self) -> Option<DefId>
pub fn projection_bounds<'a>( &'a self, ) -> impl Iterator<Item = Binder<'tcx, ExistentialProjection<'tcx>>> + 'a
pub fn auto_traits<'a>( &'a self, ) -> impl Iterator<Item = DefId> + Captures<'tcx> + 'a
pub fn without_auto_traits( &self, ) -> impl Iterator<Item = PolyExistentialPredicate<'tcx>> + '_
Trait Implementations§
source§impl<'tcx> BoundExistentialPredicates<TyCtxt<'tcx>> for &'tcx List<PolyExistentialPredicate<'tcx>>
impl<'tcx> BoundExistentialPredicates<TyCtxt<'tcx>> for &'tcx List<PolyExistentialPredicate<'tcx>>
fn principal_def_id(self) -> Option<DefId>
fn principal(self) -> Option<PolyExistentialTraitRef<'tcx>>
fn auto_traits(self) -> impl IntoIterator<Item = DefId>
fn projection_bounds( self, ) -> impl IntoIterator<Item = Binder<'tcx, ExistentialProjection<'tcx>>>
source§impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for &'tcx List<(VariantIdx, FieldIdx)>
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for &'tcx List<(VariantIdx, FieldIdx)>
source§impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for &'tcx List<PolyExistentialPredicate<'tcx>>
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for &'tcx List<PolyExistentialPredicate<'tcx>>
source§impl<'tcx> Display for &'tcx List<PolyExistentialPredicate<'tcx>>
impl<'tcx> Display for &'tcx List<PolyExistentialPredicate<'tcx>>
source§impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for List<(VariantIdx, FieldIdx)>
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for List<(VariantIdx, FieldIdx)>
source§impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for List<PolyExistentialPredicate<'tcx>>
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for List<PolyExistentialPredicate<'tcx>>
source§impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for List<BoundVariableKind>
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for List<BoundVariableKind>
source§impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for List<LocalDefId>
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for List<LocalDefId>
source§impl<'tcx> Relate<TyCtxt<'tcx>> for &'tcx List<PolyExistentialPredicate<'tcx>>
impl<'tcx> Relate<TyCtxt<'tcx>> for &'tcx List<PolyExistentialPredicate<'tcx>>
fn relate<R: TypeRelation<TyCtxt<'tcx>>>( relation: &mut R, a: Self, b: Self, ) -> RelateResult<'tcx, Self>
source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for &'tcx List<PolyExistentialPredicate<'tcx>>
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for &'tcx List<PolyExistentialPredicate<'tcx>>
source§fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
self,
folder: &mut F,
) -> Result<Self, F::Error>
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, folder: &mut F, ) -> Result<Self, F::Error>
source§fn fold_with<F>(self, folder: &mut F) -> Selfwhere
F: TypeFolder<I>,
fn fold_with<F>(self, folder: &mut F) -> Selfwhere
F: TypeFolder<I>,
try_fold_with
for use with infallible
folders. Do not override this method, to ensure coherence with
try_fold_with
.source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for &'tcx List<Const<'tcx>>
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for &'tcx List<Const<'tcx>>
source§fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
self,
folder: &mut F,
) -> Result<Self, F::Error>
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, folder: &mut F, ) -> Result<Self, F::Error>
source§fn fold_with<F>(self, folder: &mut F) -> Selfwhere
F: TypeFolder<I>,
fn fold_with<F>(self, folder: &mut F) -> Selfwhere
F: TypeFolder<I>,
try_fold_with
for use with infallible
folders. Do not override this method, to ensure coherence with
try_fold_with
.source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for &'tcx List<LocalDefId>
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for &'tcx List<LocalDefId>
source§fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
self,
_folder: &mut F,
) -> Result<Self, F::Error>
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, _folder: &mut F, ) -> Result<Self, F::Error>
source§fn fold_with<F>(self, folder: &mut F) -> Selfwhere
F: TypeFolder<I>,
fn fold_with<F>(self, folder: &mut F) -> Selfwhere
F: TypeFolder<I>,
try_fold_with
for use with infallible
folders. Do not override this method, to ensure coherence with
try_fold_with
.source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for &'tcx List<PlaceElem<'tcx>>
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for &'tcx List<PlaceElem<'tcx>>
source§fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
self,
folder: &mut F,
) -> Result<Self, F::Error>
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, folder: &mut F, ) -> Result<Self, F::Error>
source§fn fold_with<F>(self, folder: &mut F) -> Selfwhere
F: TypeFolder<I>,
fn fold_with<F>(self, folder: &mut F) -> Selfwhere
F: TypeFolder<I>,
try_fold_with
for use with infallible
folders. Do not override this method, to ensure coherence with
try_fold_with
.source§impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for &'tcx List<Ty<'tcx>>
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for &'tcx List<Ty<'tcx>>
source§fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
self,
folder: &mut F,
) -> Result<Self, F::Error>
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, folder: &mut F, ) -> Result<Self, F::Error>
source§fn fold_with<F>(self, folder: &mut F) -> Selfwhere
F: TypeFolder<I>,
fn fold_with<F>(self, folder: &mut F) -> Selfwhere
F: TypeFolder<I>,
try_fold_with
for use with infallible
folders. Do not override this method, to ensure coherence with
try_fold_with
.source§impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>>> TypeVisitable<TyCtxt<'tcx>> for &'tcx List<T>
impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>>> TypeVisitable<TyCtxt<'tcx>> for &'tcx List<T>
source§fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.