De-@ type checking contexts.

This commit is contained in:
Eduard Burtescu 2014-03-06 17:08:00 +02:00
parent 6879916a06
commit 869c96dbf0
10 changed files with 136 additions and 133 deletions

View File

@ -20,7 +20,7 @@
* `AstConv` instance; in this phase, the `get_item_ty()` function
* triggers a recursive call to `ty_of_item()` (note that
* `ast_ty_to_ty()` will detect recursive types and report an error).
* In the check phase, when the @FnCtxt is used as the `AstConv`,
* In the check phase, when the FnCtxt is used as the `AstConv`,
* `get_item_ty()` just looks up the item type in `tcx.tcache`.
*
* The `RegionScope` trait controls what happens when the user does

View File

@ -27,7 +27,7 @@ use syntax::parse::token;
use syntax::codemap::Span;
use syntax::print::pprust;
pub fn check_match(fcx: @FnCtxt,
pub fn check_match(fcx: &FnCtxt,
expr: &ast::Expr,
discrim: &ast::Expr,
arms: &[ast::Arm]) {
@ -104,7 +104,7 @@ pub fn check_match(fcx: @FnCtxt,
}
pub struct pat_ctxt<'a> {
fcx: @FnCtxt<'a>,
fcx: &'a FnCtxt<'a>,
map: PatIdMap,
}

View File

@ -46,7 +46,7 @@ pub fn suptype_with_fn(fcx: &FnCtxt,
}
}
pub fn eqtype(fcx: @FnCtxt, sp: Span, expected: ty::t, actual: ty::t) {
pub fn eqtype(fcx: &FnCtxt, sp: Span, expected: ty::t, actual: ty::t) {
match infer::mk_eqty(fcx.infcx(), false, infer::Misc(sp), actual, expected) {
Ok(()) => { /* ok */ }
Err(ref err) => {
@ -56,7 +56,7 @@ pub fn eqtype(fcx: @FnCtxt, sp: Span, expected: ty::t, actual: ty::t) {
}
// Checks that the type `actual` can be coerced to `expected`.
pub fn coerce(fcx: @FnCtxt, sp: Span, expected: ty::t, expr: &ast::Expr) {
pub fn coerce(fcx: &FnCtxt, sp: Span, expected: ty::t, expr: &ast::Expr) {
let expr_ty = fcx.expr_ty(expr);
match fcx.mk_assignty(expr, expr_ty, expected) {
result::Ok(()) => { /* ok */ }

View File

@ -120,7 +120,7 @@ pub enum AutoderefReceiverFlag {
}
pub fn lookup<'a>(
fcx: @FnCtxt,
fcx: &'a FnCtxt<'a>,
// In a call `a.b::<X, Y, ...>(...)`:
expr: &ast::Expr, // The expression `a.b(...)`.
@ -165,7 +165,7 @@ pub fn lookup<'a>(
}
pub fn lookup_in_trait<'a>(
fcx: @FnCtxt,
fcx: &'a FnCtxt<'a>,
// In a call `a.b::<X, Y, ...>(...)`:
span: Span, // The expression `a.b(...)`'s span.
@ -199,7 +199,7 @@ pub fn lookup_in_trait<'a>(
}
struct LookupContext<'a> {
fcx: @FnCtxt<'a>,
fcx: &'a FnCtxt<'a>,
span: Span,
// The receiver to the method call. Only `None` in the case of
@ -1351,7 +1351,7 @@ impl<'a> LookupContext<'a> {
}
}
fn rcvr_matches_ty(fcx: @FnCtxt,
fn rcvr_matches_ty(fcx: &FnCtxt,
rcvr_ty: ty::t,
candidate: &Candidate) -> bool {
match candidate.rcvr_match_condition {

View File

@ -251,9 +251,9 @@ pub struct FnCtxt<'a> {
// function return type.
fn_kind: FnKind,
inh: @Inherited<'a>,
inh: &'a Inherited<'a>,
ccx: @CrateCtxt<'a>,
ccx: &'a CrateCtxt<'a>,
}
impl<'a> Inherited<'a> {
@ -275,26 +275,31 @@ impl<'a> Inherited<'a> {
}
// Used by check_const and check_enum_variants
pub fn blank_fn_ctxt<'a>(ccx: @CrateCtxt<'a>,
rty: ty::t,
region_bnd: ast::NodeId)
-> @FnCtxt<'a> {
// It's kind of a kludge to manufacture a fake function context
// and statement context, but we might as well do write the code only once
let param_env = ty::ParameterEnvironment { free_substs: substs::empty(),
self_param_bound: None,
type_param_bounds: Vec::new() };
@FnCtxt {
fn blank_fn_ctxt<'a>(ccx: &'a CrateCtxt<'a>,
inh: &'a Inherited<'a>,
rty: ty::t,
region_bnd: ast::NodeId)
-> FnCtxt<'a> {
FnCtxt {
err_count_on_creation: ccx.tcx.sess.err_count(),
ret_ty: rty,
ps: RefCell::new(PurityState::function(ast::ImpureFn, 0)),
region_lb: Cell::new(region_bnd),
fn_kind: Vanilla,
inh: @Inherited::new(ccx.tcx, param_env),
inh: inh,
ccx: ccx
}
}
fn blank_inherited_fields<'a>(ccx: &'a CrateCtxt<'a>) -> Inherited<'a> {
// It's kind of a kludge to manufacture a fake function context
// and statement context, but we might as well do write the code only once
let param_env = ty::ParameterEnvironment { free_substs: substs::empty(),
self_param_bound: None,
type_param_bounds: Vec::new() };
Inherited::new(ccx.tcx, param_env)
}
impl<'a> ExprTyProvider for FnCtxt<'a> {
fn expr_ty(&self, ex: &ast::Expr) -> ty::t {
self.expr_ty(ex)
@ -305,7 +310,7 @@ impl<'a> ExprTyProvider for FnCtxt<'a> {
}
}
struct CheckItemTypesVisitor<'a> { ccx: @CrateCtxt<'a> }
struct CheckItemTypesVisitor<'a> { ccx: &'a CrateCtxt<'a> }
impl<'a> Visitor<()> for CheckItemTypesVisitor<'a> {
fn visit_item(&mut self, i: &ast::Item, _: ()) {
@ -314,12 +319,12 @@ impl<'a> Visitor<()> for CheckItemTypesVisitor<'a> {
}
}
pub fn check_item_types(ccx: @CrateCtxt, krate: &ast::Crate) {
pub fn check_item_types(ccx: &CrateCtxt, krate: &ast::Crate) {
let mut visit = CheckItemTypesVisitor { ccx: ccx };
visit::walk_crate(&mut visit, krate, ());
}
fn check_bare_fn(ccx: @CrateCtxt,
fn check_bare_fn(ccx: &CrateCtxt,
decl: &ast::FnDecl,
body: &ast::Block,
id: ast::NodeId,
@ -327,13 +332,13 @@ fn check_bare_fn(ccx: @CrateCtxt,
param_env: ty::ParameterEnvironment) {
match ty::get(fty).sty {
ty::ty_bare_fn(ref fn_ty) => {
let fcx =
check_fn(ccx, fn_ty.purity, &fn_ty.sig, decl, id, body,
Vanilla, @Inherited::new(ccx.tcx, param_env));
let inh = Inherited::new(ccx.tcx, param_env);
let fcx = check_fn(ccx, fn_ty.purity, &fn_ty.sig,
decl, id, body, Vanilla, &inh);
vtable::resolve_in_block(fcx, body);
regionck::regionck_fn(fcx, body);
writeback::resolve_type_vars_in_fn(fcx, decl, body);
vtable::resolve_in_block(&fcx, body);
regionck::regionck_fn(&fcx, body);
writeback::resolve_type_vars_in_fn(&fcx, decl, body);
}
_ => ccx.tcx.sess.impossible_case(body.span,
"check_bare_fn: function type expected")
@ -341,7 +346,7 @@ fn check_bare_fn(ccx: @CrateCtxt,
}
struct GatherLocalsVisitor<'a> {
fcx: @FnCtxt<'a>
fcx: &'a FnCtxt<'a>
}
impl<'a> GatherLocalsVisitor<'a> {
@ -415,14 +420,14 @@ impl<'a> Visitor<()> for GatherLocalsVisitor<'a> {
}
fn check_fn<'a>(ccx: @CrateCtxt<'a>,
fn check_fn<'a>(ccx: &'a CrateCtxt<'a>,
purity: ast::Purity,
fn_sig: &ty::FnSig,
decl: &ast::FnDecl,
id: ast::NodeId,
body: &ast::Block,
fn_kind: FnKind,
inherited: @Inherited<'a>) -> @FnCtxt<'a>
inherited: &'a Inherited<'a>) -> FnCtxt<'a>
{
/*!
* Helper used by check_bare_fn and check_expr_fn. Does the
@ -454,7 +459,7 @@ fn check_fn<'a>(ccx: @CrateCtxt<'a>,
// Create the function context. This is either derived from scratch or,
// in the case of function expressions, based on the outer context.
let fcx = @FnCtxt {
let fcx = FnCtxt {
err_count_on_creation: err_count_on_creation,
ret_ty: ret_ty,
ps: RefCell::new(PurityState::function(purity, id)),
@ -466,7 +471,7 @@ fn check_fn<'a>(ccx: @CrateCtxt<'a>,
{
let mut visit = GatherLocalsVisitor { fcx: fcx, };
let mut visit = GatherLocalsVisitor { fcx: &fcx, };
// Add formal parameters.
for (arg_ty, input) in arg_tys.iter().zip(decl.inputs.iter()) {
// Create type variables for each argument.
@ -478,7 +483,7 @@ fn check_fn<'a>(ccx: @CrateCtxt<'a>,
// Check the pattern.
let pcx = pat_ctxt {
fcx: fcx,
fcx: &fcx,
map: pat_id_map(tcx.def_map, input.pat),
};
_match::check_pat(&pcx, input.pat, *arg_ty);
@ -487,7 +492,7 @@ fn check_fn<'a>(ccx: @CrateCtxt<'a>,
visit.visit_block(body, ());
}
check_block_with_expected(fcx, body, Some(ret_ty));
check_block_with_expected(&fcx, body, Some(ret_ty));
// We unify the tail expr's type with the
// function result type, if there is a tail expr.
@ -495,7 +500,7 @@ fn check_fn<'a>(ccx: @CrateCtxt<'a>,
Some(tail_expr) => {
// Special case: we print a special error if there appears
// to be do-block/for-loop confusion
demand::suptype_with_fn(fcx, tail_expr.span, false,
demand::suptype_with_fn(&fcx, tail_expr.span, false,
fcx.ret_ty, fcx.expr_ty(tail_expr),
|sp, e, a, s| {
fcx.report_mismatched_return_types(sp, e, a, s);
@ -532,7 +537,7 @@ pub fn check_no_duplicate_fields(tcx: &ty::ctxt,
}
}
pub fn check_struct(ccx: @CrateCtxt, id: ast::NodeId, span: Span) {
pub fn check_struct(ccx: &CrateCtxt, id: ast::NodeId, span: Span) {
let tcx = ccx.tcx;
// Check that the struct is representable
@ -546,7 +551,7 @@ pub fn check_struct(ccx: @CrateCtxt, id: ast::NodeId, span: Span) {
}
}
pub fn check_item(ccx: @CrateCtxt, it: &ast::Item) {
pub fn check_item(ccx: &CrateCtxt, it: &ast::Item) {
debug!("check_item(it.id={}, it.ident={})",
it.id,
ty::item_path_str(ccx.tcx, local_def(it.id)));
@ -648,7 +653,7 @@ pub fn check_item(ccx: @CrateCtxt, it: &ast::Item) {
}
}
fn check_method_body(ccx: @CrateCtxt,
fn check_method_body(ccx: &CrateCtxt,
item_generics: &ty::Generics,
self_bound: Option<@ty::TraitRef>,
method: &ast::Method) {
@ -689,7 +694,7 @@ fn check_method_body(ccx: @CrateCtxt,
check_bare_fn(ccx, method.decl, method.body, method.id, fty, param_env);
}
fn check_impl_methods_against_trait(ccx: @CrateCtxt,
fn check_impl_methods_against_trait(ccx: &CrateCtxt,
impl_span: Span,
impl_generics: &ty::Generics,
ast_trait_ref: &ast::TraitRef,
@ -1240,7 +1245,7 @@ pub enum LvaluePreference {
NoPreference
}
pub fn autoderef<T>(fcx: @FnCtxt, sp: Span, base_ty: ty::t,
pub fn autoderef<T>(fcx: &FnCtxt, sp: Span, base_ty: ty::t,
expr_id: Option<ast::NodeId>,
mut lvalue_pref: LvaluePreference,
should_stop: |ty::t, uint| -> Option<T>)
@ -1291,7 +1296,7 @@ pub fn autoderef<T>(fcx: @FnCtxt, sp: Span, base_ty: ty::t,
(ty::mk_err(), 0, None)
}
fn try_overloaded_deref(fcx: @FnCtxt,
fn try_overloaded_deref(fcx: &FnCtxt,
span: Span,
method_call: Option<MethodCall>,
base_expr: Option<&ast::Expr>,
@ -1334,7 +1339,7 @@ fn try_overloaded_deref(fcx: @FnCtxt,
}
// AST fragment checking
pub fn check_lit(fcx: @FnCtxt, lit: &ast::Lit) -> ty::t {
pub fn check_lit(fcx: &FnCtxt, lit: &ast::Lit) -> ty::t {
let tcx = fcx.ccx.tcx;
match lit.node {
@ -1362,7 +1367,7 @@ pub fn check_lit(fcx: @FnCtxt, lit: &ast::Lit) -> ty::t {
}
}
pub fn valid_range_bounds(ccx: @CrateCtxt,
pub fn valid_range_bounds(ccx: &CrateCtxt,
from: &ast::Expr,
to: &ast::Expr)
-> Option<bool> {
@ -1373,40 +1378,40 @@ pub fn valid_range_bounds(ccx: @CrateCtxt,
}
pub fn check_expr_has_type(
fcx: @FnCtxt, expr: &ast::Expr,
fcx: &FnCtxt, expr: &ast::Expr,
expected: ty::t) {
check_expr_with_unifier(fcx, expr, Some(expected), NoPreference, || {
demand::suptype(fcx, expr.span, expected, fcx.expr_ty(expr));
});
}
fn check_expr_coercable_to_type(fcx: @FnCtxt, expr: &ast::Expr, expected: ty::t) {
fn check_expr_coercable_to_type(fcx: &FnCtxt, expr: &ast::Expr, expected: ty::t) {
check_expr_with_unifier(fcx, expr, Some(expected), NoPreference, || {
demand::coerce(fcx, expr.span, expected, expr)
});
}
fn check_expr_with_hint(fcx: @FnCtxt, expr: &ast::Expr, expected: ty::t) {
fn check_expr_with_hint(fcx: &FnCtxt, expr: &ast::Expr, expected: ty::t) {
check_expr_with_unifier(fcx, expr, Some(expected), NoPreference, || ())
}
fn check_expr_with_opt_hint(fcx: @FnCtxt, expr: &ast::Expr,
fn check_expr_with_opt_hint(fcx: &FnCtxt, expr: &ast::Expr,
expected: Option<ty::t>) {
check_expr_with_unifier(fcx, expr, expected, NoPreference, || ())
}
fn check_expr_with_opt_hint_and_lvalue_pref(fcx: @FnCtxt,
fn check_expr_with_opt_hint_and_lvalue_pref(fcx: &FnCtxt,
expr: &ast::Expr,
expected: Option<ty::t>,
lvalue_pref: LvaluePreference) {
check_expr_with_unifier(fcx, expr, expected, lvalue_pref, || ())
}
fn check_expr(fcx: @FnCtxt, expr: &ast::Expr) {
fn check_expr(fcx: &FnCtxt, expr: &ast::Expr) {
check_expr_with_unifier(fcx, expr, None, NoPreference, || ())
}
fn check_expr_with_lvalue_pref(fcx: @FnCtxt, expr: &ast::Expr,
fn check_expr_with_lvalue_pref(fcx: &FnCtxt, expr: &ast::Expr,
lvalue_pref: LvaluePreference) {
check_expr_with_unifier(fcx, expr, None, lvalue_pref, || ())
}
@ -1477,7 +1482,7 @@ fn generics_of_static_method_container(type_context: &ty::ctxt,
// Verifies that type parameters supplied in paths are in the right
// locations.
fn check_type_parameter_positions_in_path(function_context: @FnCtxt,
fn check_type_parameter_positions_in_path(function_context: &FnCtxt,
path: &ast::Path,
def: ast::Def) {
// We only care about checking the case in which the path has two or
@ -1634,7 +1639,7 @@ fn check_type_parameter_positions_in_path(function_context: @FnCtxt,
/// Note that inspecting a type's structure *directly* may expose the fact
/// that there are actually multiple representations for both `ty_err` and
/// `ty_bot`, so avoid that when err and bot need to be handled differently.
fn check_expr_with_unifier(fcx: @FnCtxt,
fn check_expr_with_unifier(fcx: &FnCtxt,
expr: &ast::Expr,
expected: Option<ty::t>,
lvalue_pref: LvaluePreference,
@ -1642,7 +1647,7 @@ fn check_expr_with_unifier(fcx: @FnCtxt,
debug!(">> typechecking");
fn check_method_argument_types(
fcx: @FnCtxt,
fcx: &FnCtxt,
sp: Span,
method_fn_ty: ty::t,
callee_expr: &ast::Expr,
@ -1673,7 +1678,7 @@ fn check_expr_with_unifier(fcx: @FnCtxt,
}
}
fn check_argument_types(fcx: @FnCtxt,
fn check_argument_types(fcx: &FnCtxt,
sp: Span,
fn_inputs: &[ty::t],
callee_expr: &ast::Expr,
@ -1824,12 +1829,12 @@ fn check_expr_with_unifier(fcx: @FnCtxt,
Vec::from_fn(len, |_| ty::mk_err())
}
fn write_call(fcx: @FnCtxt, call_expr: &ast::Expr, output: ty::t) {
fn write_call(fcx: &FnCtxt, call_expr: &ast::Expr, output: ty::t) {
fcx.write_ty(call_expr.id, output);
}
// A generic function for doing all of the checking for call expressions
fn check_call(fcx: @FnCtxt,
fn check_call(fcx: &FnCtxt,
call_expr: &ast::Expr,
f: &ast::Expr,
args: &[@ast::Expr]) {
@ -1878,7 +1883,7 @@ fn check_expr_with_unifier(fcx: @FnCtxt,
}
// Checks a method call.
fn check_method_call(fcx: @FnCtxt,
fn check_method_call(fcx: &FnCtxt,
expr: &ast::Expr,
method_name: ast::Ident,
args: &[@ast::Expr],
@ -1935,7 +1940,7 @@ fn check_expr_with_unifier(fcx: @FnCtxt,
// A generic function for checking the then and else in an if
// or if-check
fn check_then_else(fcx: @FnCtxt,
fn check_then_else(fcx: &FnCtxt,
cond_expr: &ast::Expr,
then_blk: &ast::Block,
opt_else_expr: Option<@ast::Expr>,
@ -1974,7 +1979,7 @@ fn check_expr_with_unifier(fcx: @FnCtxt,
fcx.write_ty(id, if_ty);
}
fn lookup_op_method(fcx: @FnCtxt,
fn lookup_op_method(fcx: &FnCtxt,
op_ex: &ast::Expr,
self_t: ty::t,
opname: ast::Name,
@ -2013,7 +2018,7 @@ fn check_expr_with_unifier(fcx: @FnCtxt,
}
// could be either an expr_binop or an expr_assign_binop
fn check_binop(fcx: @FnCtxt,
fn check_binop(fcx: &FnCtxt,
expr: &ast::Expr,
op: ast::BinOp,
lhs: @ast::Expr,
@ -2091,7 +2096,7 @@ fn check_expr_with_unifier(fcx: @FnCtxt,
}
}
fn check_user_binop(fcx: @FnCtxt,
fn check_user_binop(fcx: &FnCtxt,
ex: &ast::Expr,
lhs_expr: @ast::Expr,
lhs_resolved_t: ty::t,
@ -2130,7 +2135,7 @@ fn check_expr_with_unifier(fcx: @FnCtxt,
})
}
fn check_user_unop(fcx: @FnCtxt,
fn check_user_unop(fcx: &FnCtxt,
op_str: &str,
mname: &str,
trait_did: Option<ast::DefId>,
@ -2150,7 +2155,7 @@ fn check_expr_with_unifier(fcx: @FnCtxt,
// resolution is not possible (e.g., no constraints yet present), just
// returns `none`.
fn unpack_expected<O>(
fcx: @FnCtxt,
fcx: &FnCtxt,
expected: Option<ty::t>,
unpack: |&ty::sty| -> Option<O>)
-> Option<O> {
@ -2165,7 +2170,7 @@ fn check_expr_with_unifier(fcx: @FnCtxt,
}
}
fn check_expr_fn(fcx: @FnCtxt,
fn check_expr_fn(fcx: &FnCtxt,
expr: &ast::Expr,
ast_sigil_opt: Option<ast::Sigil>,
decl: &ast::FnDecl,
@ -2271,7 +2276,7 @@ fn check_expr_with_unifier(fcx: @FnCtxt,
// Check field access expressions
fn check_field(fcx: @FnCtxt,
fn check_field(fcx: &FnCtxt,
expr: &ast::Expr,
lvalue_pref: LvaluePreference,
base: &ast::Expr,
@ -2340,7 +2345,7 @@ fn check_expr_with_unifier(fcx: @FnCtxt,
fcx.write_error(expr.id);
}
fn check_struct_or_variant_fields(fcx: @FnCtxt,
fn check_struct_or_variant_fields(fcx: &FnCtxt,
struct_ty: ty::t,
span: Span,
class_id: ast::DefId,
@ -2428,7 +2433,7 @@ fn check_expr_with_unifier(fcx: @FnCtxt,
}
}
fn check_struct_constructor(fcx: @FnCtxt,
fn check_struct_constructor(fcx: &FnCtxt,
id: ast::NodeId,
span: codemap::Span,
class_id: ast::DefId,
@ -2484,7 +2489,7 @@ fn check_expr_with_unifier(fcx: @FnCtxt,
fcx.write_ty(id, struct_type);
}
fn check_struct_enum_variant(fcx: @FnCtxt,
fn check_struct_enum_variant(fcx: &FnCtxt,
id: ast::NodeId,
span: codemap::Span,
enum_id: ast::DefId,
@ -3020,7 +3025,7 @@ fn check_expr_with_unifier(fcx: @FnCtxt,
_ => false
}
}
fn types_compatible(fcx: @FnCtxt, sp: Span,
fn types_compatible(fcx: &FnCtxt, sp: Span,
t1: ty::t, t2: ty::t) -> bool {
if !is_vec(t1) {
false
@ -3205,7 +3210,7 @@ fn check_expr_with_unifier(fcx: @FnCtxt,
unifier();
}
pub fn require_integral(fcx: @FnCtxt, sp: Span, t: ty::t) {
pub fn require_integral(fcx: &FnCtxt, sp: Span, t: ty::t) {
if !type_is_integral(fcx, sp, t) {
fcx.type_error_message(sp, |actual| {
format!("mismatched types: expected integral type but found `{}`",
@ -3214,7 +3219,7 @@ pub fn require_integral(fcx: @FnCtxt, sp: Span, t: ty::t) {
}
}
pub fn check_decl_initializer(fcx: @FnCtxt,
pub fn check_decl_initializer(fcx: &FnCtxt,
nid: ast::NodeId,
init: &ast::Expr)
{
@ -3222,7 +3227,7 @@ pub fn check_decl_initializer(fcx: @FnCtxt,
check_expr_coercable_to_type(fcx, init, local_ty)
}
pub fn check_decl_local(fcx: @FnCtxt, local: &ast::Local) {
pub fn check_decl_local(fcx: &FnCtxt, local: &ast::Local) {
let tcx = fcx.ccx.tcx;
let t = fcx.local_ty(local.span, local.id);
@ -3250,7 +3255,7 @@ pub fn check_decl_local(fcx: @FnCtxt, local: &ast::Local) {
}
}
pub fn check_stmt(fcx: @FnCtxt, stmt: &ast::Stmt) {
pub fn check_stmt(fcx: &FnCtxt, stmt: &ast::Stmt) {
let node_id;
let mut saw_bot = false;
let mut saw_err = false;
@ -3295,7 +3300,7 @@ pub fn check_stmt(fcx: @FnCtxt, stmt: &ast::Stmt) {
}
}
pub fn check_block_no_value(fcx: @FnCtxt, blk: &ast::Block) {
pub fn check_block_no_value(fcx: &FnCtxt, blk: &ast::Block) {
check_block_with_expected(fcx, blk, Some(ty::mk_nil()));
let blkty = fcx.node_ty(blk.id);
if ty::type_is_error(blkty) {
@ -3310,11 +3315,11 @@ pub fn check_block_no_value(fcx: @FnCtxt, blk: &ast::Block) {
}
}
pub fn check_block(fcx0: @FnCtxt, blk: &ast::Block) {
pub fn check_block(fcx0: &FnCtxt, blk: &ast::Block) {
check_block_with_expected(fcx0, blk, None)
}
pub fn check_block_with_expected(fcx: @FnCtxt,
pub fn check_block_with_expected(fcx: &FnCtxt,
blk: &ast::Block,
expected: Option<ty::t>) {
let prev = {
@ -3383,20 +3388,21 @@ pub fn check_block_with_expected(fcx: @FnCtxt,
fcx.ps.set(prev);
}
pub fn check_const(ccx: @CrateCtxt,
pub fn check_const(ccx: &CrateCtxt,
sp: Span,
e: &ast::Expr,
id: ast::NodeId) {
let inh = blank_inherited_fields(ccx);
let rty = ty::node_id_to_type(ccx.tcx, id);
let fcx = blank_fn_ctxt(ccx, rty, e.id);
let fcx = blank_fn_ctxt(ccx, &inh, rty, e.id);
let declty = {
let tcache = fcx.ccx.tcx.tcache.borrow();
tcache.get().get(&local_def(id)).ty
};
check_const_with_ty(fcx, sp, e, declty);
check_const_with_ty(&fcx, sp, e, declty);
}
pub fn check_const_with_ty(fcx: @FnCtxt,
pub fn check_const_with_ty(fcx: &FnCtxt,
_: Span,
e: &ast::Expr,
declty: ty::t) {
@ -3486,15 +3492,15 @@ pub fn check_simd(tcx: &ty::ctxt, sp: Span, id: ast::NodeId) {
}
}
pub fn check_enum_variants(ccx: @CrateCtxt,
pub fn check_enum_variants(ccx: &CrateCtxt,
sp: Span,
vs: &[ast::P<ast::Variant>],
id: ast::NodeId) {
fn disr_in_range(ccx: @CrateCtxt,
fn disr_in_range(ccx: &CrateCtxt,
ty: attr::IntType,
disr: ty::Disr) -> bool {
fn uint_in_range(ccx: @CrateCtxt, ty: ast::UintTy, disr: ty::Disr) -> bool {
fn uint_in_range(ccx: &CrateCtxt, ty: ast::UintTy, disr: ty::Disr) -> bool {
match ty {
ast::TyU8 => disr as u8 as Disr == disr,
ast::TyU16 => disr as u16 as Disr == disr,
@ -3503,7 +3509,7 @@ pub fn check_enum_variants(ccx: @CrateCtxt,
ast::TyU => uint_in_range(ccx, ccx.tcx.sess.targ_cfg.uint_type, disr)
}
}
fn int_in_range(ccx: @CrateCtxt, ty: ast::IntTy, disr: ty::Disr) -> bool {
fn int_in_range(ccx: &CrateCtxt, ty: ast::IntTy, disr: ty::Disr) -> bool {
match ty {
ast::TyI8 => disr as i8 as Disr == disr,
ast::TyI16 => disr as i16 as Disr == disr,
@ -3518,7 +3524,7 @@ pub fn check_enum_variants(ccx: @CrateCtxt,
}
}
fn do_check(ccx: @CrateCtxt,
fn do_check(ccx: &CrateCtxt,
vs: &[ast::P<ast::Variant>],
id: ast::NodeId,
hint: attr::ReprAttr)
@ -3542,9 +3548,10 @@ pub fn check_enum_variants(ccx: @CrateCtxt,
Some(e) => {
debug!("disr expr, checking {}", pprust::expr_to_str(e));
let fcx = blank_fn_ctxt(ccx, rty, e.id);
let inh = blank_inherited_fields(ccx);
let fcx = blank_fn_ctxt(ccx, &inh, rty, e.id);
let declty = ty::mk_int_var(ccx.tcx, fcx.infcx().next_int_var_id());
check_const_with_ty(fcx, e.span, e, declty);
check_const_with_ty(&fcx, e.span, e, declty);
// check_expr (from check_const pass) doesn't guarantee
// that the expression is in an form that eval_const_expr can
// handle, so we may still get an internal compiler error
@ -3617,12 +3624,12 @@ pub fn check_enum_variants(ccx: @CrateCtxt,
check_instantiable(ccx.tcx, sp, id);
}
pub fn lookup_def(fcx: @FnCtxt, sp: Span, id: ast::NodeId) -> ast::Def {
pub fn lookup_def(fcx: &FnCtxt, sp: Span, id: ast::NodeId) -> ast::Def {
lookup_def_ccx(fcx.ccx, sp, id)
}
// Returns the type parameter count and the type for the given definition.
pub fn ty_param_bounds_and_ty_for_def(fcx: @FnCtxt,
pub fn ty_param_bounds_and_ty_for_def(fcx: &FnCtxt,
sp: Span,
defn: ast::Def)
-> ty_param_bounds_and_ty {
@ -3672,7 +3679,7 @@ pub fn ty_param_bounds_and_ty_for_def(fcx: @FnCtxt,
// Instantiates the given path, which must refer to an item with the given
// number of type parameters and type.
pub fn instantiate_path(fcx: @FnCtxt,
pub fn instantiate_path(fcx: &FnCtxt,
pth: &ast::Path,
tpt: ty_param_bounds_and_ty,
def: ast::Def,
@ -3858,47 +3865,47 @@ pub fn structurally_resolved_type(fcx: &FnCtxt, sp: Span, tp: ty::t) -> ty::t {
}
// Returns the one-level-deep structure of the given type.
pub fn structure_of<'a>(fcx: @FnCtxt, sp: Span, typ: ty::t)
pub fn structure_of<'a>(fcx: &FnCtxt, sp: Span, typ: ty::t)
-> &'a ty::sty {
&ty::get(structurally_resolved_type(fcx, sp, typ)).sty
}
pub fn type_is_integral(fcx: @FnCtxt, sp: Span, typ: ty::t) -> bool {
pub fn type_is_integral(fcx: &FnCtxt, sp: Span, typ: ty::t) -> bool {
let typ_s = structurally_resolved_type(fcx, sp, typ);
return ty::type_is_integral(typ_s);
}
pub fn type_is_scalar(fcx: @FnCtxt, sp: Span, typ: ty::t) -> bool {
pub fn type_is_scalar(fcx: &FnCtxt, sp: Span, typ: ty::t) -> bool {
let typ_s = structurally_resolved_type(fcx, sp, typ);
return ty::type_is_scalar(typ_s);
}
pub fn type_is_char(fcx: @FnCtxt, sp: Span, typ: ty::t) -> bool {
pub fn type_is_char(fcx: &FnCtxt, sp: Span, typ: ty::t) -> bool {
let typ_s = structurally_resolved_type(fcx, sp, typ);
return ty::type_is_char(typ_s);
}
pub fn type_is_bare_fn(fcx: @FnCtxt, sp: Span, typ: ty::t) -> bool {
pub fn type_is_bare_fn(fcx: &FnCtxt, sp: Span, typ: ty::t) -> bool {
let typ_s = structurally_resolved_type(fcx, sp, typ);
return ty::type_is_bare_fn(typ_s);
}
pub fn type_is_unsafe_ptr(fcx: @FnCtxt, sp: Span, typ: ty::t) -> bool {
pub fn type_is_unsafe_ptr(fcx: &FnCtxt, sp: Span, typ: ty::t) -> bool {
let typ_s = structurally_resolved_type(fcx, sp, typ);
return ty::type_is_unsafe_ptr(typ_s);
}
pub fn type_is_region_ptr(fcx: @FnCtxt, sp: Span, typ: ty::t) -> bool {
pub fn type_is_region_ptr(fcx: &FnCtxt, sp: Span, typ: ty::t) -> bool {
let typ_s = structurally_resolved_type(fcx, sp, typ);
return ty::type_is_region_ptr(typ_s);
}
pub fn type_is_c_like_enum(fcx: @FnCtxt, sp: Span, typ: ty::t) -> bool {
pub fn type_is_c_like_enum(fcx: &FnCtxt, sp: Span, typ: ty::t) -> bool {
let typ_s = structurally_resolved_type(fcx, sp, typ);
return ty::type_is_c_like_enum(fcx.ccx.tcx, typ_s);
}
pub fn ast_expr_vstore_to_vstore(fcx: @FnCtxt,
pub fn ast_expr_vstore_to_vstore(fcx: &FnCtxt,
e: &ast::Expr,
v: ast::ExprVstore)
-> ty::vstore {
@ -3962,7 +3969,7 @@ pub fn may_break(cx: &ty::ctxt, id: ast::NodeId, b: ast::P<ast::Block>) -> bool
}}))
}
pub fn check_bounds_are_used(ccx: @CrateCtxt,
pub fn check_bounds_are_used(ccx: &CrateCtxt,
span: Span,
tps: &OptVec<ast::TyParam>,
ty: ty::t) {
@ -3992,8 +3999,8 @@ pub fn check_bounds_are_used(ccx: @CrateCtxt,
}
}
pub fn check_intrinsic_type(ccx: @CrateCtxt, it: &ast::ForeignItem) {
fn param(ccx: @CrateCtxt, n: uint) -> ty::t {
pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
fn param(ccx: &CrateCtxt, n: uint) -> ty::t {
ty::mk_param(ccx.tcx, n, local_def(0))
}

View File

@ -293,7 +293,7 @@ impl<'a, 'b> mc::Typer for &'a mut Rcx<'b> {
}
}
pub fn regionck_expr(fcx: @FnCtxt, e: &ast::Expr) {
pub fn regionck_expr(fcx: &FnCtxt, e: &ast::Expr) {
let mut rcx = Rcx { fcx: fcx, errors_reported: 0,
repeating_scope: e.id };
let rcx = &mut rcx;
@ -304,7 +304,7 @@ pub fn regionck_expr(fcx: @FnCtxt, e: &ast::Expr) {
fcx.infcx().resolve_regions();
}
pub fn regionck_fn(fcx: @FnCtxt, blk: &ast::Block) {
pub fn regionck_fn(fcx: &FnCtxt, blk: &ast::Block) {
let mut rcx = Rcx { fcx: fcx, errors_reported: 0,
repeating_scope: blk.id };
let rcx = &mut rcx;

View File

@ -35,7 +35,7 @@ use syntax::print::pprust::pat_to_str;
use syntax::visit;
use syntax::visit::Visitor;
fn resolve_type_vars_in_type(fcx: @FnCtxt, sp: Span, typ: ty::t)
fn resolve_type_vars_in_type(fcx: &FnCtxt, sp: Span, typ: ty::t)
-> Option<ty::t> {
if !ty::type_needs_infer(typ) { return Some(typ); }
match resolve_type(fcx.infcx(), typ, resolve_all | force_all) {
@ -53,7 +53,7 @@ fn resolve_type_vars_in_type(fcx: @FnCtxt, sp: Span, typ: ty::t)
}
}
fn resolve_type_vars_in_types(fcx: @FnCtxt, sp: Span, tys: &[ty::t])
fn resolve_type_vars_in_types(fcx: &FnCtxt, sp: Span, tys: &[ty::t])
-> Vec<ty::t> {
tys.iter().map(|t| {
match resolve_type_vars_in_type(fcx, sp, *t) {
@ -101,7 +101,7 @@ fn resolve_method_map_entry(wbcx: &mut WbCtxt, sp: Span, method_call: MethodCall
}
}
fn resolve_vtable_map_entry(fcx: @FnCtxt, sp: Span, id: ast::NodeId) {
fn resolve_vtable_map_entry(fcx: &FnCtxt, sp: Span, id: ast::NodeId) {
// Resolve any vtable map entry
match fcx.inh.vtable_map.borrow().get().find_copy(&id) {
Some(origins) => {
@ -113,12 +113,12 @@ fn resolve_vtable_map_entry(fcx: @FnCtxt, sp: Span, id: ast::NodeId) {
None => {}
}
fn resolve_origins(fcx: @FnCtxt, sp: Span,
fn resolve_origins(fcx: &FnCtxt, sp: Span,
vtbls: vtable_res) -> vtable_res {
@vtbls.map(|os| @os.map(|o| resolve_origin(fcx, sp, o)))
}
fn resolve_origin(fcx: @FnCtxt,
fn resolve_origin(fcx: &FnCtxt,
sp: Span,
origin: &vtable_origin) -> vtable_origin {
match origin {
@ -255,7 +255,7 @@ fn resolve_type_vars_for_node(wbcx: &mut WbCtxt, sp: Span, id: ast::NodeId)
}
struct WbCtxt<'a> {
fcx: @FnCtxt<'a>,
fcx: &'a FnCtxt<'a>,
// As soon as we hit an error we have to stop resolving
// the entire function.
@ -383,7 +383,7 @@ fn resolve_upvar_borrow_map(wbcx: &mut WbCtxt) {
}
}
pub fn resolve_type_vars_in_expr(fcx: @FnCtxt, e: &ast::Expr) -> bool {
pub fn resolve_type_vars_in_expr(fcx: &FnCtxt, e: &ast::Expr) -> bool {
let mut wbcx = WbCtxt { fcx: fcx, success: true };
let wbcx = &mut wbcx;
wbcx.visit_expr(e, ());
@ -391,7 +391,7 @@ pub fn resolve_type_vars_in_expr(fcx: @FnCtxt, e: &ast::Expr) -> bool {
return wbcx.success;
}
pub fn resolve_type_vars_in_fn(fcx: @FnCtxt, decl: &ast::FnDecl,
pub fn resolve_type_vars_in_fn(fcx: &FnCtxt, decl: &ast::FnDecl,
blk: &ast::Block) -> bool {
let mut wbcx = WbCtxt { fcx: fcx, success: true };
let wbcx = &mut wbcx;

View File

@ -145,7 +145,7 @@ fn get_base_type_def_id(inference_context: &InferCtxt,
}
struct CoherenceChecker<'a> {
crate_context: @CrateCtxt<'a>,
crate_context: &'a CrateCtxt<'a>,
inference_context: InferCtxt<'a>,
}
@ -227,13 +227,6 @@ impl<'a> visit::Visitor<()> for PrivilegedScopeVisitor<'a> {
}
impl<'a> CoherenceChecker<'a> {
fn new(crate_context: @CrateCtxt<'a>) -> CoherenceChecker<'a> {
CoherenceChecker {
crate_context: crate_context,
inference_context: new_infer_ctxt(crate_context.tcx),
}
}
fn check(&self, krate: &Crate) {
// Check implementations and traits. This populates the tables
// containing the inherent methods and extension methods. It also
@ -838,6 +831,9 @@ fn subst_receiver_types_in_method_ty(tcx: &ty::ctxt,
)
}
pub fn check_coherence(crate_context: @CrateCtxt, krate: &Crate) {
CoherenceChecker::new(crate_context).check(krate);
pub fn check_coherence(crate_context: &CrateCtxt, krate: &Crate) {
CoherenceChecker {
crate_context: crate_context,
inference_context: new_infer_ctxt(crate_context.tcx),
}.check(krate);
}

View File

@ -62,7 +62,7 @@ use syntax::visit;
use syntax::opt_vec::OptVec;
struct CollectItemTypesVisitor<'a> {
ccx: @CrateCtxt<'a>
ccx: &'a CrateCtxt<'a>
}
impl<'a> visit::Visitor<()> for CollectItemTypesVisitor<'a> {
@ -76,7 +76,7 @@ impl<'a> visit::Visitor<()> for CollectItemTypesVisitor<'a> {
}
}
pub fn collect_item_types(ccx: @CrateCtxt, krate: &ast::Crate) {
pub fn collect_item_types(ccx: &CrateCtxt, krate: &ast::Crate) {
fn collect_intrinsic_type(ccx: &CrateCtxt,
lang_item: ast::DefId) {
let ty::ty_param_bounds_and_ty { ty: ty, .. } =

View File

@ -462,7 +462,7 @@ pub fn check_crate(tcx: &ty::ctxt,
krate: &ast::Crate)
-> (MethodMap, vtable_map) {
let time_passes = tcx.sess.time_passes();
let ccx = @CrateCtxt {
let ccx = CrateCtxt {
trait_map: trait_map,
method_map: @RefCell::new(FnvHashMap::new()),
vtable_map: @RefCell::new(NodeMap::new()),
@ -470,7 +470,7 @@ pub fn check_crate(tcx: &ty::ctxt,
};
time(time_passes, "type collecting", (), |_|
collect::collect_item_types(ccx, krate));
collect::collect_item_types(&ccx, krate));
// this ensures that later parts of type checking can assume that items
// have valid types and not error
@ -480,12 +480,12 @@ pub fn check_crate(tcx: &ty::ctxt,
variance::infer_variance(tcx, krate));
time(time_passes, "coherence checking", (), |_|
coherence::check_coherence(ccx, krate));
coherence::check_coherence(&ccx, krate));
time(time_passes, "type checking", (), |_|
check::check_item_types(ccx, krate));
check::check_item_types(&ccx, krate));
check_for_entry_fn(ccx);
check_for_entry_fn(&ccx);
tcx.sess.abort_if_errors();
(ccx.method_map, ccx.vtable_map)
}