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>> + '_
Source§impl<'tcx> RawList<(), GenericArg<'tcx>>
impl<'tcx> RawList<(), GenericArg<'tcx>>
Sourcepub fn into_type_list(&self, tcx: TyCtxt<'tcx>) -> &'tcx List<Ty<'tcx>>
pub fn into_type_list(&self, tcx: TyCtxt<'tcx>) -> &'tcx List<Ty<'tcx>>
Sourcepub fn as_closure(&'tcx self) -> ClosureArgs<TyCtxt<'tcx>>
pub fn as_closure(&'tcx self) -> ClosureArgs<TyCtxt<'tcx>>
Interpret these generic args as the args of a closure type.
Closure args have a particular structure controlled by the
compiler that encodes information like the signature and closure kind;
see ty::ClosureArgs
struct for more comments.
Sourcepub fn as_coroutine_closure(&'tcx self) -> CoroutineClosureArgs<TyCtxt<'tcx>>
pub fn as_coroutine_closure(&'tcx self) -> CoroutineClosureArgs<TyCtxt<'tcx>>
Interpret these generic args as the args of a coroutine-closure type.
Coroutine-closure args have a particular structure controlled by the
compiler that encodes information like the signature and closure kind;
see ty::CoroutineClosureArgs
struct for more comments.
Sourcepub fn as_coroutine(&'tcx self) -> CoroutineArgs<TyCtxt<'tcx>>
pub fn as_coroutine(&'tcx self) -> CoroutineArgs<TyCtxt<'tcx>>
Interpret these generic args as the args of a coroutine type.
Coroutine args have a particular structure controlled by the
compiler that encodes information like the signature and coroutine kind;
see ty::CoroutineArgs
struct for more comments.
Sourcepub fn as_inline_const(&'tcx self) -> InlineConstArgs<'tcx>
pub fn as_inline_const(&'tcx self) -> InlineConstArgs<'tcx>
Interpret these generic args as the args of an inline const.
Inline const args have a particular structure controlled by the
compiler that encodes information like the inferred type;
see ty::InlineConstArgs
struct for more comments.
Sourcepub fn identity_for_item(
tcx: TyCtxt<'tcx>,
def_id: impl Into<DefId>,
) -> GenericArgsRef<'tcx>
pub fn identity_for_item( tcx: TyCtxt<'tcx>, def_id: impl Into<DefId>, ) -> GenericArgsRef<'tcx>
Creates an GenericArgs
that maps each generic parameter to itself.
Sourcepub fn for_item<F>(
tcx: TyCtxt<'tcx>,
def_id: DefId,
mk_kind: F,
) -> GenericArgsRef<'tcx>
pub fn for_item<F>( tcx: TyCtxt<'tcx>, def_id: DefId, mk_kind: F, ) -> GenericArgsRef<'tcx>
Creates an GenericArgs
for generic parameter definitions,
by calling closures to obtain each kind.
The closures get to observe the GenericArgs
as they’re
being built, which can be used to correctly
replace defaults of generic parameters.
pub fn extend_to<F>( &self, tcx: TyCtxt<'tcx>, def_id: DefId, mk_kind: F, ) -> GenericArgsRef<'tcx>
pub fn fill_item<F>( args: &mut SmallVec<[GenericArg<'tcx>; 8]>, tcx: TyCtxt<'tcx>, defs: &Generics, mk_kind: &mut F, )
pub fn fill_single<F>( args: &mut SmallVec<[GenericArg<'tcx>; 8]>, defs: &Generics, mk_kind: &mut F, )
pub fn extend_with_error( tcx: TyCtxt<'tcx>, def_id: DefId, original_args: &[GenericArg<'tcx>], ) -> GenericArgsRef<'tcx>
pub fn types(&'tcx self) -> impl DoubleEndedIterator<Item = Ty<'tcx>> + 'tcx
pub fn regions( &'tcx self, ) -> impl DoubleEndedIterator<Item = Region<'tcx>> + 'tcx
pub fn consts(&'tcx self) -> impl DoubleEndedIterator<Item = Const<'tcx>> + 'tcx
Sourcepub fn non_erasable_generics(
&'tcx self,
) -> impl DoubleEndedIterator<Item = GenericArgKind<'tcx>> + 'tcx
pub fn non_erasable_generics( &'tcx self, ) -> impl DoubleEndedIterator<Item = GenericArgKind<'tcx>> + 'tcx
Returns generic arguments that are not lifetimes or host effect params.
pub fn type_at(&self, i: usize) -> Ty<'tcx>
pub fn region_at(&self, i: usize) -> Region<'tcx>
pub fn const_at(&self, i: usize) -> Const<'tcx>
pub fn type_for_def(&self, def: &GenericParamDef) -> GenericArg<'tcx>
Sourcepub fn rebase_onto(
&self,
tcx: TyCtxt<'tcx>,
source_ancestor: DefId,
target_args: GenericArgsRef<'tcx>,
) -> GenericArgsRef<'tcx>
pub fn rebase_onto( &self, tcx: TyCtxt<'tcx>, source_ancestor: DefId, target_args: GenericArgsRef<'tcx>, ) -> GenericArgsRef<'tcx>
Transform from generic args for a child of source_ancestor
(e.g., a trait or impl) to args for the same child
in a different item, with target_args
as the base for
the target impl/trait, with the source child-specific
parameters (e.g., method parameters) on top of that base.
For example given:
trait X<S> { fn f<T>(); }
impl<U> X<U> for U { fn f<V>() {} }
- If
self
is[Self, S, T]
: the identity args off
in the trait. - If
source_ancestor
is the def_id of the trait. - If
target_args
is[U]
, the args for the impl. - Then we will return
[U, T]
, the arg forf
in the impl that are needed for it to match the trait.
pub fn truncate_to( &self, tcx: TyCtxt<'tcx>, generics: &Generics, ) -> GenericArgsRef<'tcx>
pub fn print_as_list(&self) -> String
Source§impl<H, T> RawList<H, T>
impl<H, T> RawList<H, T>
pub fn len(&self) -> usize
pub fn as_slice(&self) -> &[T]
Sourcepub(super) fn from_arena<'tcx>(
arena: &'tcx Arena<'tcx>,
header: H,
slice: &[T],
) -> &'tcx RawList<H, T>where
T: Copy,
pub(super) fn from_arena<'tcx>(
arena: &'tcx Arena<'tcx>,
header: H,
slice: &[T],
) -> &'tcx RawList<H, T>where
T: Copy,
Allocates a list from arena
and copies the contents of slice
into it.
WARNING: the contents must be unique, such that no list with these
contents has been previously created. If not, operations such as eq
and hash
might give incorrect results.
Panics if T
is Drop
, or T
is zero-sized, or the slice is empty
(because the empty list exists statically, and is available via
empty()
).
pub fn iter(&self) -> <&RawList<H, T> as IntoIterator>::IntoIterwhere
T: Copy,
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>
§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>
§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>
§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>
§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>
§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
Source§impl<H, T> PartialOrd for RawList<H, T>where
T: PartialOrd,
impl<H, T> PartialOrd for RawList<H, T>where
T: PartialOrd,
impl<H: DynSync, T: DynSync> DynSync for RawList<H, T>
impl<H, T: Eq> Eq for RawList<H, T>
impl<H: Sync, T: Sync> Sync for RawList<H, T>
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.