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
§

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
§

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
§

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
§

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
§

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.