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>> + '_

Source§

impl<'tcx> RawList<(), GenericArg<'tcx>>

Source

pub fn into_type_list(&self, tcx: TyCtxt<'tcx>) -> &'tcx List<Ty<'tcx>>

Converts generic args to a type list.

§Panics

If any of the generic arguments are not types.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn for_item<F>( tcx: TyCtxt<'tcx>, def_id: DefId, mk_kind: F, ) -> GenericArgsRef<'tcx>
where F: FnMut(&GenericParamDef, &[GenericArg<'tcx>]) -> GenericArg<'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.

Source

pub fn extend_to<F>( &self, tcx: TyCtxt<'tcx>, def_id: DefId, mk_kind: F, ) -> GenericArgsRef<'tcx>
where F: FnMut(&GenericParamDef, &[GenericArg<'tcx>]) -> GenericArg<'tcx>,

Source

pub fn fill_item<F>( args: &mut SmallVec<[GenericArg<'tcx>; 8]>, tcx: TyCtxt<'tcx>, defs: &Generics, mk_kind: &mut F, )
where F: FnMut(&GenericParamDef, &[GenericArg<'tcx>]) -> GenericArg<'tcx>,

Source

pub fn fill_single<F>( args: &mut SmallVec<[GenericArg<'tcx>; 8]>, defs: &Generics, mk_kind: &mut F, )
where F: FnMut(&GenericParamDef, &[GenericArg<'tcx>]) -> GenericArg<'tcx>,

Source

pub fn extend_with_error( tcx: TyCtxt<'tcx>, def_id: DefId, original_args: &[GenericArg<'tcx>], ) -> GenericArgsRef<'tcx>

Source

pub fn types(&'tcx self) -> impl DoubleEndedIterator<Item = Ty<'tcx>> + 'tcx

Source

pub fn regions( &'tcx self, ) -> impl DoubleEndedIterator<Item = Region<'tcx>> + 'tcx

Source

pub fn consts(&'tcx self) -> impl DoubleEndedIterator<Item = Const<'tcx>> + 'tcx

Source

pub fn non_erasable_generics( &'tcx self, ) -> impl DoubleEndedIterator<Item = GenericArgKind<'tcx>> + 'tcx

Returns generic arguments that are not lifetimes or host effect params.

Source

pub fn type_at(&self, i: usize) -> Ty<'tcx>

Source

pub fn region_at(&self, i: usize) -> Region<'tcx>

Source

pub fn const_at(&self, i: usize) -> Const<'tcx>

Source

pub fn type_for_def(&self, def: &GenericParamDef) -> GenericArg<'tcx>

Source

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 of f 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 for f in the impl that are needed for it to match the trait.
Source

pub fn truncate_to( &self, tcx: TyCtxt<'tcx>, generics: &Generics, ) -> GenericArgsRef<'tcx>

Source

pub fn print_as_list(&self) -> String

Source§

impl<T> RawList<(), T>

Source

pub fn empty<'a>() -> &'a RawList<(), T>

Returns a reference to the (per header unique, static) empty list.

Source§

impl<H, T> RawList<H, T>

Source

pub fn len(&self) -> usize

Source

pub fn as_slice(&self) -> &[T]

Source

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()).

Source

pub fn iter(&self) -> <&RawList<H, T> as IntoIterator>::IntoIter
where T: Copy,

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>

Source§

impl<H, T> Aligned for RawList<H, T>

Source§

const ALIGN: Alignment = _

Alignment of Self.
Source§

impl<H, T> AsRef<[T]> for RawList<H, T>

Source§

fn as_ref(&self) -> &[T]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<H, T: Debug> Debug for RawList<H, T>

Source§

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

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

impl<H, T> Deref for RawList<H, T>

Source§

type Target = [T]

The resulting type after dereferencing.
Source§

fn deref(&self) -> &[T]

Dereferences the value.
Source§

impl<H, S: Encoder, T: Encodable<S>> Encodable<S> for RawList<H, T>

Source§

fn encode(&self, s: &mut S)

Source§

impl<Hdr, T> Hash for RawList<Hdr, T>

Source§

fn hash<H: Hasher>(&self, s: &mut H)

Feeds this value into the given Hasher. Read more
Source§

impl<H, T> Ord for RawList<H, T>
where T: Ord,

Source§

fn cmp(&self, other: &RawList<H, T>) -> Ordering

This method returns an Ordering between self and other. Read more
Source§

impl<H, T: PartialEq> PartialEq for RawList<H, T>

Source§

fn eq(&self, other: &RawList<H, T>) -> bool

Tests for self and other values to be equal, and is used by ==.
Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<H, T> PartialOrd for RawList<H, T>
where T: PartialOrd,

Source§

fn partial_cmp(&self, other: &RawList<H, T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<H: DynSync, T: DynSync> DynSync for RawList<H, T>

Source§

impl<H, T: Eq> Eq for RawList<H, T>

Source§

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.