Crate rustc_typeck[−][src]
🔬 This is a nightly-only experimental API. (rustc_private
)
this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml
instead?
typeck.rs, an introduction
The type checker is responsible for:
- Determining the type of each expression
- Resolving methods and traits
- Guaranteeing that most type rules are met ("most?", you say, "why most?" Well, dear reader, read on)
The main entry point is check_crate()
. Type checking operates in
several major phases:
-
The collect phase first passes over all items and determines their type, without examining their "innards".
-
Variance inference then runs to compute the variance of each parameter
-
Coherence checks for overlapping or orphaned impls
-
Finally, the check phase then checks function bodies and so forth. Within the check phase, we check each function body 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. The actual checking of a function itself has several phases (check, regionck, writeback), as discussed in the documentation for the
check
module.
The type checker is defined into various submodules which are documented independently:
-
astconv: converts the AST representation of types into the
ty
representation -
collect: computes the types of each top-level item and enters them into the
tcx.types
table for later use -
coherence: enforces coherence rules, builds some tables
-
variance: variance inference
-
outlives: outlives inference
-
check: walks over function bodies and type checks them, inferring types for local variables, type parameters, etc as necessary.
-
infer: finds the types to use for each type variable such that all subtyping and assignment constraints are met. In essence, the check module specifies the constraints, and the infer module solves them.
Note
This API is completely unstable and subject to change.
Re-exports
extern crate std; |
extern crate log; |
extern crate syntax; |
extern crate syntax_pos; |
extern crate arena; |
extern crate rustc; |
extern crate rustc_platform_intrinsics as intrinsics; |
extern crate rustc_data_structures; |
extern crate rustc_errors as errors; |
extern crate rustc_target; |
use std::prelude::v1::*; |
use rustc::hir; |
use rustc::lint; |
use rustc::middle; |
use rustc::session; |
use rustc::util; |
use hir::map as hir_map; |
use rustc::infer::InferOk; |
use rustc::ty::subst::Substs; |
use rustc::ty; |
use rustc::ty::Ty; |
use rustc::ty::TyCtxt; |
use rustc::ty::maps::Providers; |
use rustc::traits::ObligationCause; |
use rustc::traits::ObligationCauseCode; |
use rustc::traits::TraitEngine; |
use session::CompileIncomplete; |
use session::config; |
use util::common::time; |
use syntax::ast; |
use rustc_target::spec::abi::Abi; |
use syntax_pos::Span; |
use std::iter; |
Modules
astconv |
[ Experimental ] Conversion from AST representation of types to the ty.rs
representation. The main routine here is |
check |
[ Experimental ]
|
check_unused |
[ Experimental ]
|
coherence |
[ Experimental ]
|
collect |
[ Experimental ] "Collection" is the process of determining the type and other external details of each item in Rust. Collection is specifically concerned with interprocedural things -- for example, for a function definition, collection will figure out the type and signature of the function, but it will not visit the body of the function in any way, nor examine type annotations on local variables (that's the job of type checking). |
constrained_type_params |
[ Experimental ]
|
diagnostics |
[ Experimental ]
|
impl_wf_check |
[ Experimental ] This pass enforces various "well-formedness constraints" on impls. Logically, it is part of wfcheck -- but we do it early so that we can stop compilation afterwards, since part of the trait matching infrastructure gets very grumpy if these conditions don't hold. In particular, if there are type parameters that are not part of the impl, then coherence will report strange inference ambiguity errors; if impls have duplicate items, we get misleading specialization errors. These things can (and probably should) be fixed, but for the moment it's easier to do these checks early. |
namespace |
[ Experimental ]
|
outlives |
[ Experimental ]
|
structured_errors |
[ Experimental ]
|
variance |
[ Experimental ] Module for inferring the variance of type and lifetime parameters. See the rustc guide chapter for more info. |
Structs
TypeAndSubsts |
[ Experimental ]
|
Constants
DIAGNOSTICS |
[ Experimental ]
|
Functions
check_crate |
[ Experimental ]
|
check_for_entry_fn |
[ Experimental ]
|
check_main_fn_ty |
[ Experimental ]
|
check_start_fn_ty |
[ Experimental ]
|
hir_trait_to_predicates |
[ Experimental ]
|
hir_ty_to_ty |
[ Experimental ] A quasi-deprecated helper used in rustdoc and save-analysis to get the type from a HIR node. |
provide |
[ Experimental ]
|
require_c_abi_if_variadic |
[ Experimental ]
|
require_same_types |
[ Experimental ]
|