Module rustc_middle::ty [−][src]
Expand description
Defines how the compiler represents types internally.
Two important entities in this module are:
rustc_middle::ty::Ty
, used to represent the semantics of a type.rustc_middle::ty::TyCtxt
, the central data structure in the compiler.
For more information, see “The ty
module: representing types” in the ructc-dev-guide.
Re-exports
pub use self::fold::TypeFoldable;
pub use self::fold::TypeFolder;
pub use self::fold::TypeVisitor;
pub use self::AssocItemContainer::*;
pub use self::BorrowKind::*;
pub use self::IntVarValue::*;
pub use self::Variance::*;
pub use self::AssocItemContainer::*;
pub use vtable::*;
pub use rustc_type_ir::InferTy::*;
pub use self::binding::BindingMode;
pub use self::binding::BindingMode::*;
pub use self::sty::BoundRegionKind::*;
pub use self::sty::RegionKind::*;
pub use self::sty::TyKind::*;
pub use self::trait_def::TraitDef;
Modules
This module contains some shared code for encoding and decoding various
things from the ty
module, and in particular implements support for
“shorthands” which allow to have pointers back into the already encoded
stream instead of re-encoding the same thing twice.
Type context book-keeping.
Diagnostics related methods for TyS
.
Generalized type folding mechanism. The setup is a bit convoluted
but allows for convenient usage. Let T be an instance of some
“foldable type” (one which implements TypeFoldable
) and F be an
instance of a “folder” (a type which implements TypeFolder
). Then
the setup is intended to be:
This module contains HashStable
implementations for various data types
from rustc_middle::ty
in no particular order.
Methods for normalizing when you don’t care about regions (and
aren’t doing type inference). If either of those things don’t
apply to you, use infcx.normalize(...)
.
Generalized type relating mechanism.
This module contains implements of the Lift
and TypeFoldable
traits for various types in the Rust compiler. Most are written by
hand, though we’ve recently added some macros and proc-macros to help with the tedium.
This module contains TyKind
and its major components.
Miscellaneous type-system utilities that are too small to deserve their own modules.
An iterator over the type substructure. WARNING: this does not keep track of the region depth.
Structs
The definition of a user-defined type, e.g., a struct
, enum
, or union
.
A list of ty::AssocItem
s in definition order that allows for efficient lookup by name.
Binder is a binder for higher-ranked lifetimes or types. It is part of the
compiler’s representation for things like for<'a> Fn(&'a isize)
(which would be represented by the type PolyTraitRef == Binder<'tcx, TraitRef>
). Note that when we instantiate,
erase, or otherwise “discharge” these bound vars, we change the
type from Binder<'tcx, T>
to just T
(see
e.g., liberate_late_bound_regions
).
Part of MinCaptureInformationMap
; describes the capture kind (&, &mut, move)
for a particular capture as well as identifying the part of the source code
that triggered this capture to occur.
A composite describing a Place
that is captured by a closure.
A closure can be modeled as a struct that looks like:
Struct returned by split()
.
Encodes that we have to coerce from the a
type to the b
type.
Typed constant value.
A type for representing any integer. Only used for printing.
A const
variable ID.
A map for the local crate mapping each type to a vector of its
inherent impls. This is not meant to be used outside of coherence;
rather, you should request the vector for a specific type via
tcx.inherent_impls(def_id)
so as to minimize your dependencies
(constructing this map requires touching the entire crate).
The crate outlives map is computed during typeck and contains the
outlives of every item in the local crate. You should not use it
directly, because to do so will make your pass dependent on the
HIR of every item in the local crate. Instead, use
tcx.inferred_outlives_of()
to get the outlives for a particular
item.
The crate variances map is computed during typeck and contains the
variance of every item in the local crate. You should not use it
directly, because to do so will make your pass dependent on the
HIR of every item in the local crate. Instead, use
tcx.variances_of()
to get the variance for a particular
item.
A De Bruijn index is a standard means of representing regions (and perhaps later types) in a higher-ranked setting. In particular, imagine a type like this:
A type that is not publicly constructable. This prevents people from making TyKind::Error
s
except through the error-reporting functions on a tcx
.
A ProjectionPredicate
for an ExistentialTraitRef
.
An existential reference to a trait, where Self
is erased.
For example, the trait object Trait<'a, 'b, X, Y>
is:
An floating-point (f32
or f64
) type variable ID.
Signature of a function type, which we have arbitrarily decided to use to refer to the input/output types.
A “free” region fr
can be interpreted as “some region
at least as big as the scope fr.scope
”.
Whenever a value may be live across a generator yield, the type of that value winds up in the
GeneratorInteriorTypeCause
struct. This struct adds additional information about such
captured types that can be useful for diagnostics. In particular, it stores the span that
caused a given type to be recorded, along with the scope that enclosed the value (which can
be used to find the await that the value is live across).
Similar to ClosureSubsts
; see the above documentation for more.
Bounds on generics.
Information about the formal type/lifetime parameters associated
with an item or method. Analogous to hir::Generics
.
The “header” of an impl is everything outside the body: a Self type, a trait ref (in the case of a trait impl), and a set of predicates (from the bounds / where-clauses).
A monomorphized InstanceDef
.
Represents the bounds declared on a particular set of type
parameters. Should eventually be generalized into a flag list of
where-clauses. You can obtain an InstantiatedPredicates
list from a
GenericPredicates
by using the instantiate
method. Note that this method
reflects an important semantic invariant of InstantiatedPredicates
: while
the GenericPredicates
are expressed in terms of the bound type
parameters of the impl/trait/whatever, an InstantiatedPredicates
instance
represented a set of bounds for some particular instantiation,
meaning that the generic parameters have been substituted with
their values.
An integral (u32
, i32
, usize
, etc.) type variable ID.
A wrapper for slices with the additional invariant that the slice is interned and no other slice with the same contents can exist in the same context. This means we can use pointer for both equality comparisons and hashing.
When type checking, we use the ParamEnv
to track
details about the set of where-clauses that are in scope at this
particular point.
The “placeholder index” fully defines a placeholder region, type, or const. Placeholders are identified by both a universe, as well as a name residing within that universe. Distinct bound regions/types/consts within the same universe simply have an unknown relationship to one another.
This kind of predicate has no direct correspondent in the syntax, but it roughly corresponds to the syntactic forms:
Represents the projection of an associated type. In explicit UFCS
form this would be written <T as Trait<..>>::N
.
A region (lifetime) variable ID.
Represents the repr options provided by the user,
The raw bytes of a simple value.
Encodes that a
must be a subtype of b
. The a_is_expected
flag indicates
whether the a
type is the type that we should label as “expected” when
presenting user diagnostics.
Collect al types that have an implicit 'static
obligation that we could suggest '_
for.
A complete reference to a trait. These take numerous guises in syntax, but perhaps the most recognizable form is in a where-clause:
The central data structure of the compiler. It stores references to the various arenas and also houses the results of the various compiler queries that have been performed. See the rustc dev guide for more details.
A type variable ID.
Flags that we track on types. These flags are propagated upwards through the type during type construction, so that we can quickly check whether the type has various kinds of types in it without recursing over the type itself.
An unevaluated, potentially generic, constant.
“Universes” are used during type- and trait-checking in the
presence of for<..>
binders to control what sets of names are
visible. Universes are arranged into a tree: the root universe
contains names that are always visible. Each child then adds a new
set of names that are visible, in addition to those of its parent.
We say that the child universe “extends” the parent universe with
new names.
Upvars do not get their own NodeId
. Instead, we use the pair of
the original var ID (that is, the root variable that is referenced
by the upvar) and the ID of the closure expression.
Definition of a variant – a struct’s fields or an enum variant.
A DefId
which, in case it is a const argument, is potentially bundled with
the DefId
of the generic parameter it instantiates.
Enums
Represents the various closure traits in the language. This
will determine the type of the environment (self
, in the
desugaring) argument that the closure expects.
Represents a constant in Rust.
An inference variable for a const, for use in const generics.
A placeholder for a type that hasn’t been inferred yet.
Representation of regions. Note that the NLL checker uses a distinct
representation of regions. For this reason, it internally replaces all the
regions with inference variables – the index of the variable is then used
to index into internal NLL data structures. See rustc_const_eval::borrow_check
module for more information.
Defines the kinds of types.
Information describing the capture of an upvar. This is computed
during typeck
, specifically by regionck
.
A user-given type annotation attached to a constant. These arise
from constants that are named via paths, like Foo::<A>::new
and
so forth.
This datastructure is used to represent the value of constants used in the type system.
Extra information about why we ended up with a particular variance.
This is only used to add more information to error messages, and
has no effect on soundness. While choosing the ‘wrong’ VarianceDiagInfo
may lead to confusing notes in error messages, it will never cause
a miscompilation or unsoundness.
Constants
Traits
A trait implemented for all X<'a>
types that can be safely and
efficiently converted to X<'tcx>
as long as they are part of the
provided TyCtxt<'tcx>
.
This can be done, for example, for Ty<'tcx>
or SubstsRef<'tcx>
by looking them up in their respective interners.
Functions
Return true if the proj_possible_ancestor
represents an ancestor path
to proj_capture
or proj_possible_ancestor
is same as proj_capture
,
assuming they both start off of the same root variable.
Yields the parent function’s DefId
if def_id
is an impl Trait
definition.
Suggest restricting a type param with a new bound.
Type Definitions
Canonicalized user type annotation.
Mapping of type annotation indices to canonical user type annotations.
Given the closure DefId this map provides a map of root variables to minimum
set of CapturedPlace
s that need to be tracked to support all captures of that closure.
Part of MinCaptureInformationMap
; List of CapturePlace
s.
Part of MinCaptureInformationMap
; Maps a root variable to the list of CapturedPlace
.
Used to track the minimum set of Place
s that need to be captured to support all
Places captured by the closure starting at a given root variable.