[−][src]Module rustc_typeck::check

typeck: check phase

Within the check phase of type check, we check each item one at a time (bodies of function expressions are checked as part of the containing function). Inference is used to supply types wherever they are unknown.

By far the most complex case is checking the body of a function. This can be broken down into several distinct phases:

Intermediate types

While type checking a function, the intermediate types for the expressions, blocks, and so forth contained within the function are stored in fcx.node_types and fcx.node_substs. These types may contain unresolved type variables. After type checking is complete, the functions in the writeback module are used to take the types from this table, resolve them, and then write them into their permanent home in the type context tcx.

This means that during inferencing you should use fcx.write_ty() and fcx.expr_ty() / fcx.node_ty() to write/obtain the types of nodes within the function.

The types of top-level items, which never contain unbound type variables, are stored directly into the tcx typeck_results.

N.B., a type variable is not the same thing as a type parameter. A type variable is rather an "instance" of a type parameter: that is, given a generic function fn foo<T>(t: T): while checking the function foo, the type ty_param(0) refers to the type T, which is treated in abstract. When foo() is called, however, T will be substituted for a fresh type variable N. This variable will eventually be resolved to some concrete type (which might itself be type parameter).

Re-exports

pub use self::Expectation::*;

Modules

_match
autoderef

Some helper functions for AutoDeref

callee
cast

Code for type-checking cast expressions.

check
closure

Code for type-checking closure expressions.

coercion

Type Coercion

compare_method
demand
diverges
dropck
expectation
expr

Type checking expressions.

fn_ctxt
gather_locals
generator_interior

This calculates the types which has storage which lives across a suspension point in a generator from the perspective of typeck. The actual types used at runtime is calculated in rustc_mir::transform::generator and may be a subset of the types computed here.

inherited
intrinsic

Type-checking for the rust-intrinsic and platform-intrinsic intrinsics that the compiler exposes.

method

Method lookup: the secret sauce of Rust. See the rustc dev guide for more information.

op

Code related to processing overloaded binary and unary operators.

pat
place_op
regionck

The region check is a final pass that runs over the AST after we have inferred the type constraints but before we have actually finalized the types. Its purpose is to embed a variety of region constraints. Inserting these constraints as a separate pass is good because (1) it localizes the code that has to do with region inference and (2) often we cannot know what constraints are needed until the basic types have been inferred.

upvar

Inferring borrow kinds for upvars

wfcheck
writeback

Structs

BreakableCtxt
CheckItemTypesVisitor
EnclosingBreakables
FnCtxt
GeneratorTypes

When check_fn is invoked on a generator (i.e., a body that includes yield), it returns back some information about the yield points.

Inherited

Closures defined within the function. For example:

InheritedBuilder

Helper type of a temporary returned by Inherited::build(...). Necessary because we can't write the following bound: F: for<'b, 'tcx> where 'tcx FnOnce(Inherited<'b, 'tcx>).

LocalTy

The type of a local binding, including the revealed type for anon types.

MaybeInProgressTables

A wrapper for InferCtxt's in_progress_typeck_results field.

UnsafetyState

Enums

Diverges

Tracks whether executing a node may exit normally (versus return/break/panic, which "diverge", leaving dead code in their wake). Tracked semi-automatically (through type variables marked as diverging), with some manual adjustments for control-flow primitives (approximating a CFG).

Expectation

When type-checking an expression, we propagate downward whatever type hint we are able in the form of an Expectation.

FallbackMode

Controls how we perform fallback for unconstrained type variables.

Needs
PlaceOp
TupleArgumentsFlag

Controls whether the arguments are tupled. This is used for the call operator.

Functions

adt_destructor
bad_non_zero_sized_fields

Emit an error when encountering more or less than one non-zero-sized field in a transparent enum.

bad_variant_count

Emit an error when encountering more or less than one variant in a transparent enum.

binding_opaque_type_cycle_error

Emit an error for recursive opaque types in a let binding.

bounds_from_generic_predicates

Resugar ty::GenericPredicates in a way suitable to be used in structured suggestions.

check_item_type
check_wf_new
diagnostic_only_typeck

Used only to get TypeckResults for type inference during error recovery. Currently only used for type inference of statics and consts to avoid type cycle errors.

fatally_break_rust
fixup_opaque_types

Inspects the substs of opaque types, replacing any inference variables with proper generic parameter from the identity substs.

fn_maybe_err
fn_sig_suggestion

Return placeholder code for the given function.

get_owner_return_paths

Given a DefId for an opaque type in return position, find its parent item's return expressions.

has_typeck_results
maybe_check_static_with_link_section
missing_items_err
potentially_plural_count
primary_body_of

If this DefId is a "primary tables entry", returns Some((body_id, header, decl)) with information about it's body-id, fn-header and fn-decl (if any). Otherwise, returns None.

provide
report_forbidden_specialization
report_unexpected_variant_res
suggestion_signature

Return placeholder code for the given associated item. Similar to ty::AssocItem::suggestion, but appropriate for use as the code snippet of a structured suggestion.

typeck
typeck_const_arg
typeck_item_bodies
typeck_with_fallback
used_trait_imports