rustc_middle::ty

Type Alias List

source
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 a List<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 another List<T>. You can get a sub-slice &[T], however.
  • List<T> can be used with CopyTaggedPtr, 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 be Copy. This lets List<T> be stored in a dropless arena and iterators return a T 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>>

source

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.

source

pub fn principal_def_id(&self) -> Option<DefId>

source

pub fn projection_bounds<'a>( &'a self, ) -> impl Iterator<Item = Binder<'tcx, ExistentialProjection<'tcx>>> + 'a

source

pub fn auto_traits<'a>( &'a self, ) -> impl Iterator<Item = DefId> + Captures<'tcx> + 'a

source

pub fn without_auto_traits( &self, ) -> impl Iterator<Item = PolyExistentialPredicate<'tcx>> + '_

Trait Implementations§

source§

impl<'tcx> BoundExistentialPredicates<TyCtxt<'tcx>> for &'tcx List<PolyExistentialPredicate<'tcx>>

source§

impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for &'tcx List<(VariantIdx, FieldIdx)>

source§

fn decode(decoder: &mut D) -> Self

source§

impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for &'tcx List<PolyExistentialPredicate<'tcx>>

source§

fn decode(decoder: &mut D) -> Self

source§

impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for &'tcx List<BoundVariableKind>

source§

fn decode(decoder: &mut D) -> Self

source§

impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for &'tcx List<FieldIdx>

source§

fn decode(decoder: &mut D) -> Self

source§

impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for &'tcx List<LocalDefId>

source§

fn decode(d: &mut D) -> Self

source§

impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for &'tcx List<Ty<'tcx>>

source§

fn decode(decoder: &mut D) -> Self

source§

impl<T> Default for &List<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'tcx> Display for &'tcx List<PolyExistentialPredicate<'tcx>>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'tcx> Display for &'tcx List<Ty<'tcx>>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> EraseType for &List<T>

source§

type Result = [u8; 8]

source§

impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for &'a List<PolyExistentialPredicate<'a>>

source§

type Lifted = &'tcx RawList<(), Binder<TyCtxt<'tcx>, ExistentialPredicate<TyCtxt<'tcx>>>>

source§

fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted>

source§

impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for &'a List<BoundVariableKind>

source§

impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for &'a List<GenericArg<'a>>

source§

type Lifted = &'tcx RawList<(), GenericArg<'tcx>>

source§

fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted>

source§

impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for &'a List<Ty<'a>>

source§

type Lifted = &'tcx RawList<(), Ty<'tcx>>

source§

fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted>

source§

impl<'tcx, P: Printer<'tcx>> Print<'tcx, P> for &'tcx List<PolyExistentialPredicate<'tcx>>

source§

impl<'tcx, P: PrettyPrinter<'tcx>> Print<'tcx, P> for &'tcx List<Ty<'tcx>>

source§

impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for List<(VariantIdx, FieldIdx)>

source§

fn decode(decoder: &mut D) -> &'tcx Self

source§

impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for List<PolyExistentialPredicate<'tcx>>

source§

fn decode(decoder: &mut D) -> &'tcx Self

source§

impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for List<BoundVariableKind>

source§

fn decode(decoder: &mut D) -> &'tcx Self

source§

impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for List<Const<'tcx>>

source§

fn decode(decoder: &mut D) -> &'tcx Self

source§

impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for List<FieldIdx>

source§

fn decode(decoder: &mut D) -> &'tcx Self

source§

impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for List<LocalDefId>

source§

fn decode(decoder: &mut D) -> &'tcx Self

source§

impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for List<Ty<'tcx>>

source§

fn decode(decoder: &mut D) -> &'tcx Self

source§

impl<'tcx> Relate<TyCtxt<'tcx>> for &'tcx List<PolyExistentialPredicate<'tcx>>

source§

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>>

source§

fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, folder: &mut F, ) -> Result<Self, F::Error>

The entry point for folding. To fold a value t with a folder f call: t.try_fold_with(f). Read more
source§

fn fold_with<F>(self, folder: &mut F) -> Self
where F: TypeFolder<I>,

A convenient alternative to 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>>

source§

fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, folder: &mut F, ) -> Result<Self, F::Error>

The entry point for folding. To fold a value t with a folder f call: t.try_fold_with(f). Read more
source§

fn fold_with<F>(self, folder: &mut F) -> Self
where F: TypeFolder<I>,

A convenient alternative to 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>

source§

fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, _folder: &mut F, ) -> Result<Self, F::Error>

The entry point for folding. To fold a value t with a folder f call: t.try_fold_with(f). Read more
source§

fn fold_with<F>(self, folder: &mut F) -> Self
where F: TypeFolder<I>,

A convenient alternative to 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>>

source§

fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, folder: &mut F, ) -> Result<Self, F::Error>

The entry point for folding. To fold a value t with a folder f call: t.try_fold_with(f). Read more
source§

fn fold_with<F>(self, folder: &mut F) -> Self
where F: TypeFolder<I>,

A convenient alternative to 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>>

source§

fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>( self, folder: &mut F, ) -> Result<Self, F::Error>

The entry point for folding. To fold a value t with a folder f call: t.try_fold_with(f). Read more
source§

fn fold_with<F>(self, folder: &mut F) -> Self
where F: TypeFolder<I>,

A convenient alternative to 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>

source§

fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result

The entry point for visiting. To visit a value t with a visitor v call: t.visit_with(v). Read more
source§

impl<'tcx> Tys<TyCtxt<'tcx>> for &'tcx List<Ty<'tcx>>

source§

fn inputs(self) -> &'tcx [Ty<'tcx>]

source§

fn output(self) -> Ty<'tcx>

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.