Struct rustc_borrowck::type_check::TypeChecker [−][src]
struct TypeChecker<'a, 'tcx> {
infcx: &'a InferCtxt<'a, 'tcx>,
param_env: ParamEnv<'tcx>,
last_span: Span,
body: &'a Body<'tcx>,
user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>,
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
implicit_region_bound: Region<'tcx>,
reported_errors: FxHashSet<(Ty<'tcx>, Span)>,
borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>,
}
Expand description
The MIR type checker. Visits the MIR and enforces all the constraints needed for it to be valid and well-typed. Along the way, it accrues region constraints – these can later be used by NLL region checking.
Fields
infcx: &'a InferCtxt<'a, 'tcx>
param_env: ParamEnv<'tcx>
last_span: Span
body: &'a Body<'tcx>
user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>
User type annotations are shared between the main MIR and the MIR of all of the promoted items.
region_bound_pairs: &'a RegionBoundPairs<'tcx>
implicit_region_bound: Region<'tcx>
reported_errors: FxHashSet<(Ty<'tcx>, Span)>
borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>
Implementations
pub(super) fn fully_perform_op<R, Op>(
&mut self,
locations: Locations,
category: ConstraintCategory,
op: Op
) -> Fallible<R> where
Op: TypeOp<'tcx, Output = R>,
Canonical<'tcx, Op>: ToUniverseInfo<'tcx>,
pub(super) fn fully_perform_op<R, Op>(
&mut self,
locations: Locations,
category: ConstraintCategory,
op: Op
) -> Fallible<R> where
Op: TypeOp<'tcx, Output = R>,
Canonical<'tcx, Op>: ToUniverseInfo<'tcx>,
Given some operation op
that manipulates types, proves
predicates, or otherwise uses the inference context, executes
op
and then executes all the further obligations that op
returns. This will yield a set of outlives constraints amongst
regions which are extracted and stored as having occurred at
locations
.
Any rustc_infer::infer
operations that might generate region
constraints should occur within this method so that those
constraints can be properly localized!
pub(super) fn instantiate_canonical_with_fresh_inference_vars<T>(
&mut self,
span: Span,
canonical: &Canonical<'tcx, T>
) -> T where
T: TypeFoldable<'tcx>,
pub(super) fn prove_trait_ref(
&mut self,
trait_ref: TraitRef<'tcx>,
locations: Locations,
category: ConstraintCategory
)
pub(super) fn normalize_and_prove_instantiated_predicates(
&mut self,
_def_id: DefId,
instantiated_predicates: InstantiatedPredicates<'tcx>,
locations: Locations
)
pub(super) fn prove_predicates(
&mut self,
predicates: impl IntoIterator<Item = impl ToPredicate<'tcx>>,
locations: Locations,
category: ConstraintCategory
)
pub(super) fn prove_predicate(
&mut self,
predicate: Predicate<'tcx>,
locations: Locations,
category: ConstraintCategory
)
pub(super) fn normalize<T>(
&mut self,
value: T,
location: impl NormalizeLocation
) -> T where
T: Normalizable<'tcx> + Display + Copy + 'tcx,
pub(super) fn equate_inputs_and_outputs(
&mut self,
body: &Body<'tcx>,
universal_regions: &UniversalRegions<'tcx>,
normalized_inputs_and_output: &[Ty<'tcx>]
)
pub(super) fn relate_types(
&mut self,
a: Ty<'tcx>,
v: Variance,
b: Ty<'tcx>,
locations: Locations,
category: ConstraintCategory
) -> Fallible<()>
pub(super) fn relate_types(
&mut self,
a: Ty<'tcx>,
v: Variance,
b: Ty<'tcx>,
locations: Locations,
category: ConstraintCategory
) -> Fallible<()>
Adds sufficient constraints to ensure that a R b
where R
depends on v
:
- “Covariant”
a <: b
- “Invariant”
a == b
- “Contravariant”
a :> b
N.B., the type a
is permitted to have unresolved inference
variables, but not the type b
.
fn new(
infcx: &'a InferCtxt<'a, 'tcx>,
body: &'a Body<'tcx>,
param_env: ParamEnv<'tcx>,
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
implicit_region_bound: Region<'tcx>,
borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>
) -> Self
Equate the inferred type and the annotated type for user type annotations
fn push_region_constraints(
&mut self,
locations: Locations,
category: ConstraintCategory,
data: &QueryRegionConstraints<'tcx>
)
Try to relate sub <: sup
fn eq_types(
&mut self,
expected: Ty<'tcx>,
found: Ty<'tcx>,
locations: Locations,
category: ConstraintCategory
) -> Fallible<()>
fn relate_type_and_user_type(
&mut self,
a: Ty<'tcx>,
v: Variance,
user_ty: &UserTypeProjection,
locations: Locations,
category: ConstraintCategory
) -> Fallible<()>
fn eq_opaque_type_and_type(
&mut self,
revealed_ty: Ty<'tcx>,
anon_ty: Ty<'tcx>,
locations: Locations,
category: ConstraintCategory
) -> Fallible<()>
fn eq_opaque_type_and_type(
&mut self,
revealed_ty: Ty<'tcx>,
anon_ty: Ty<'tcx>,
locations: Locations,
category: ConstraintCategory
) -> Fallible<()>
Equates a type anon_ty
that may contain opaque types whose
values are to be inferred by the MIR.
The type revealed_ty
contains the same type as anon_ty
, but with the
hidden types for impl traits revealed.
Example
Consider a piece of code like
type Foo<U> = impl Debug;
fn foo<T: Debug>(t: T) -> Box<Foo<T>> {
Box::new((t, 22_u32))
}
Here, the function signature would be something like
fn(T) -> Box<impl Debug>
. The MIR return slot would have
the type with the opaque type revealed, so Box<(T, u32)>
.
In terms of our function parameters:
anon_ty
would beBox<Foo<T>>
whereFoo<T>
is an opaque type scoped to this function (note that it is parameterized by the generics offoo
). Note thatanon_ty
is not just the opaque type, but the entire return type (which may contain opaque types within it).revealed_ty
would beBox<(T, u32)>
fn check_terminator(
&mut self,
body: &Body<'tcx>,
term: &Terminator<'tcx>,
term_location: Location
)
fn check_call_dest(
&mut self,
body: &Body<'tcx>,
term: &Terminator<'tcx>,
sig: &FnSig<'tcx>,
destination: &Option<(Place<'tcx>, BasicBlock)>,
term_location: Location
)
fn check_call_inputs(
&mut self,
body: &Body<'tcx>,
term: &Terminator<'tcx>,
sig: &FnSig<'tcx>,
args: &[Operand<'tcx>],
term_location: Location,
from_hir_call: bool
)
fn assert_iscleanup(
&mut self,
body: &Body<'tcx>,
ctxt: &dyn Debug,
bb: BasicBlock,
iscleanuppad: bool
)
fn aggregate_field_ty(
&mut self,
ak: &AggregateKind<'tcx>,
field_index: usize,
location: Location
) -> Result<Ty<'tcx>, FieldAccessError>
If this rvalue supports a user-given type annotation, then extract and return it. This represents the final type of the rvalue and will be unified with the inferred type.
fn check_aggregate_rvalue(
&mut self,
body: &Body<'tcx>,
rvalue: &Rvalue<'tcx>,
aggregate_kind: &AggregateKind<'tcx>,
operands: &[Operand<'tcx>],
location: Location
)
Adds the constraints that arise from a borrow expression &'a P
at the location L
.
Parameters
location
: the locationL
where the borrow expression occursborrow_region
: the region'a
associated with the borrowborrowed_place
: the placeP
being borrowed
fn prove_aggregate_predicates(
&mut self,
aggregate_kind: &AggregateKind<'tcx>,
location: Location
)
fn prove_closure_bounds(
&mut self,
tcx: TyCtxt<'tcx>,
def_id: LocalDefId,
substs: SubstsRef<'tcx>,
location: Location
) -> InstantiatedPredicates<'tcx>
Auto Trait Implementations
impl<'a, 'tcx> !RefUnwindSafe for TypeChecker<'a, 'tcx>
impl<'a, 'tcx> !Send for TypeChecker<'a, 'tcx>
impl<'a, 'tcx> !Sync for TypeChecker<'a, 'tcx>
impl<'a, 'tcx> Unpin for TypeChecker<'a, 'tcx> where
'tcx: 'a,
impl<'a, 'tcx> !UnwindSafe for TypeChecker<'a, 'tcx>
Blanket Implementations
Layout
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.
Size: 96 bytes