librustc: De-@mut FnCtxt.
This commit is contained in:
parent
c9432327c4
commit
09589aae4f
7 changed files with 104 additions and 102 deletions
|
|
@ -25,7 +25,7 @@ use syntax::parse::token;
|
|||
use syntax::codemap::Span;
|
||||
use syntax::print::pprust;
|
||||
|
||||
pub fn check_match(fcx: @mut FnCtxt,
|
||||
pub fn check_match(fcx: @FnCtxt,
|
||||
expr: @ast::Expr,
|
||||
discrim: @ast::Expr,
|
||||
arms: &[ast::Arm]) {
|
||||
|
|
@ -102,7 +102,7 @@ pub fn check_match(fcx: @mut FnCtxt,
|
|||
}
|
||||
|
||||
pub struct pat_ctxt {
|
||||
fcx: @mut FnCtxt,
|
||||
fcx: @FnCtxt,
|
||||
map: PatIdMap,
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,17 +20,17 @@ use syntax::codemap::Span;
|
|||
|
||||
// Requires that the two types unify, and prints an error message if they
|
||||
// don't.
|
||||
pub fn suptype(fcx: @mut FnCtxt, sp: Span, expected: ty::t, actual: ty::t) {
|
||||
pub fn suptype(fcx: @FnCtxt, sp: Span, expected: ty::t, actual: ty::t) {
|
||||
suptype_with_fn(fcx, sp, false, expected, actual,
|
||||
|sp, e, a, s| { fcx.report_mismatched_types(sp, e, a, s) })
|
||||
}
|
||||
|
||||
pub fn subtype(fcx: @mut FnCtxt, sp: Span, expected: ty::t, actual: ty::t) {
|
||||
pub fn subtype(fcx: @FnCtxt, sp: Span, expected: ty::t, actual: ty::t) {
|
||||
suptype_with_fn(fcx, sp, true, actual, expected,
|
||||
|sp, a, e, s| { fcx.report_mismatched_types(sp, e, a, s) })
|
||||
}
|
||||
|
||||
pub fn suptype_with_fn(fcx: @mut FnCtxt,
|
||||
pub fn suptype_with_fn(fcx: @FnCtxt,
|
||||
sp: Span,
|
||||
b_is_expected: bool,
|
||||
ty_a: ty::t,
|
||||
|
|
@ -46,7 +46,7 @@ pub fn suptype_with_fn(fcx: @mut FnCtxt,
|
|||
}
|
||||
}
|
||||
|
||||
pub fn eqtype(fcx: @mut 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,10 +56,7 @@ pub fn eqtype(fcx: @mut FnCtxt, sp: Span, expected: ty::t, actual: ty::t) {
|
|||
}
|
||||
|
||||
// Checks that the type `actual` can be coerced to `expected`.
|
||||
pub fn coerce(fcx: @mut 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 */ }
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ pub enum AutoderefReceiverFlag {
|
|||
}
|
||||
|
||||
pub fn lookup(
|
||||
fcx: @mut FnCtxt,
|
||||
fcx: @FnCtxt,
|
||||
|
||||
// In a call `a.b::<X, Y, ...>(...)`:
|
||||
expr: @ast::Expr, // The expression `a.b(...)`.
|
||||
|
|
@ -168,7 +168,7 @@ pub fn lookup(
|
|||
}
|
||||
|
||||
pub struct LookupContext<'a> {
|
||||
fcx: @mut FnCtxt,
|
||||
fcx: @FnCtxt,
|
||||
expr: @ast::Expr,
|
||||
self_expr: @ast::Expr,
|
||||
callee_id: NodeId,
|
||||
|
|
@ -1245,7 +1245,7 @@ impl<'a> LookupContext<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
fn rcvr_matches_ty(fcx: @mut FnCtxt,
|
||||
fn rcvr_matches_ty(fcx: @FnCtxt,
|
||||
rcvr_ty: ty::t,
|
||||
candidate: &Candidate) -> bool {
|
||||
match candidate.rcvr_match_condition {
|
||||
|
|
|
|||
|
|
@ -110,6 +110,7 @@ use util::common::{block_query, indenter, loop_query};
|
|||
use util::ppaux::UserString;
|
||||
use util::ppaux;
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::hashmap::HashMap;
|
||||
use std::result;
|
||||
use std::util::replace;
|
||||
|
|
@ -226,7 +227,7 @@ pub struct FnCtxt {
|
|||
err_count_on_creation: uint,
|
||||
|
||||
ret_ty: ty::t,
|
||||
ps: PurityState,
|
||||
ps: RefCell<PurityState>,
|
||||
|
||||
// Sometimes we generate region pointers where the precise region
|
||||
// to use is not known. For example, an expression like `&x.f`
|
||||
|
|
@ -241,7 +242,7 @@ pub struct FnCtxt {
|
|||
// inference selects the ultimate value. Finally, borrowck is
|
||||
// charged with guaranteeing that the value whose address was taken
|
||||
// can actually be made to live as long as it needs to live.
|
||||
region_lb: ast::NodeId,
|
||||
region_lb: Cell<ast::NodeId>,
|
||||
|
||||
// Says whether we're inside a for loop, in a do block
|
||||
// or neither. Helps with error messages involving the
|
||||
|
|
@ -274,17 +275,17 @@ impl Inherited {
|
|||
pub fn blank_fn_ctxt(ccx: @mut CrateCtxt,
|
||||
rty: ty::t,
|
||||
region_bnd: ast::NodeId)
|
||||
-> @mut FnCtxt {
|
||||
-> @FnCtxt {
|
||||
// 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: ~[] };
|
||||
@mut FnCtxt {
|
||||
@FnCtxt {
|
||||
err_count_on_creation: ccx.tcx.sess.err_count(),
|
||||
ret_ty: rty,
|
||||
ps: PurityState::function(ast::impure_fn, 0),
|
||||
region_lb: region_bnd,
|
||||
ps: RefCell::new(PurityState::function(ast::impure_fn, 0)),
|
||||
region_lb: Cell::new(region_bnd),
|
||||
fn_kind: Vanilla,
|
||||
inh: @Inherited::new(ccx.tcx, param_env),
|
||||
ccx: ccx
|
||||
|
|
@ -339,7 +340,7 @@ pub fn check_bare_fn(ccx: @mut CrateCtxt,
|
|||
}
|
||||
|
||||
struct GatherLocalsVisitor {
|
||||
fcx: @mut FnCtxt,
|
||||
fcx: @FnCtxt,
|
||||
tcx: ty::ctxt,
|
||||
}
|
||||
|
||||
|
|
@ -414,7 +415,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
|
|||
id: ast::NodeId,
|
||||
body: ast::P<ast::Block>,
|
||||
fn_kind: FnKind,
|
||||
inherited: @Inherited) -> @mut FnCtxt
|
||||
inherited: @Inherited) -> @FnCtxt
|
||||
{
|
||||
/*!
|
||||
* Helper used by check_bare_fn and check_expr_fn. Does the
|
||||
|
|
@ -457,12 +458,12 @@ pub fn check_fn(ccx: @mut CrateCtxt,
|
|||
|
||||
// Create the function context. This is either derived from scratch or,
|
||||
// in the case of function expressions, based on the outer context.
|
||||
let fcx: @mut FnCtxt = {
|
||||
@mut FnCtxt {
|
||||
let fcx: @FnCtxt = {
|
||||
@FnCtxt {
|
||||
err_count_on_creation: err_count_on_creation,
|
||||
ret_ty: ret_ty,
|
||||
ps: PurityState::function(purity, id),
|
||||
region_lb: body.id,
|
||||
ps: RefCell::new(PurityState::function(purity, id)),
|
||||
region_lb: Cell::new(body.id),
|
||||
fn_kind: fn_kind,
|
||||
inh: inherited,
|
||||
ccx: ccx
|
||||
|
|
@ -496,7 +497,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
|
|||
|
||||
return fcx;
|
||||
|
||||
fn gather_locals(fcx: @mut FnCtxt,
|
||||
fn gather_locals(fcx: @FnCtxt,
|
||||
decl: &ast::fn_decl,
|
||||
body: ast::P<ast::Block>,
|
||||
arg_tys: &[ty::t],
|
||||
|
|
@ -1089,7 +1090,7 @@ impl FnCtxt {
|
|||
}
|
||||
|
||||
pub fn block_region(&self) -> ty::Region {
|
||||
ty::ReScope(self.region_lb)
|
||||
ty::ReScope(self.region_lb.get())
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -1143,7 +1144,7 @@ impl FnCtxt {
|
|||
pub fn write_bot(&self, node_id: ast::NodeId) {
|
||||
self.write_ty(node_id, ty::mk_bot());
|
||||
}
|
||||
pub fn write_error(@mut self, node_id: ast::NodeId) {
|
||||
pub fn write_error(&self, node_id: ast::NodeId) {
|
||||
self.write_ty(node_id, ty::mk_err());
|
||||
}
|
||||
|
||||
|
|
@ -1257,11 +1258,11 @@ impl FnCtxt {
|
|||
infer::mk_subr(self.infcx(), a_is_expected, origin, sub, sup)
|
||||
}
|
||||
|
||||
pub fn with_region_lb<R>(@mut self, lb: ast::NodeId, f: || -> R) -> R {
|
||||
let old_region_lb = self.region_lb;
|
||||
self.region_lb = lb;
|
||||
pub fn with_region_lb<R>(&self, lb: ast::NodeId, f: || -> R) -> R {
|
||||
let old_region_lb = self.region_lb.get();
|
||||
self.region_lb.set(lb);
|
||||
let v = f();
|
||||
self.region_lb = old_region_lb;
|
||||
self.region_lb.set(old_region_lb);
|
||||
v
|
||||
}
|
||||
|
||||
|
|
@ -1294,7 +1295,7 @@ impl FnCtxt {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn do_autoderef(fcx: @mut FnCtxt, sp: Span, t: ty::t) -> (ty::t, uint) {
|
||||
pub fn do_autoderef(fcx: @FnCtxt, sp: Span, t: ty::t) -> (ty::t, uint) {
|
||||
/*!
|
||||
*
|
||||
* Autoderefs the type `t` as many times as possible, returning
|
||||
|
|
@ -1351,7 +1352,7 @@ pub fn do_autoderef(fcx: @mut FnCtxt, sp: Span, t: ty::t) -> (ty::t, uint) {
|
|||
}
|
||||
|
||||
// AST fragment checking
|
||||
pub fn check_lit(fcx: @mut 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 {
|
||||
|
|
@ -1390,7 +1391,7 @@ pub fn valid_range_bounds(ccx: @mut CrateCtxt,
|
|||
}
|
||||
|
||||
pub fn check_expr_has_type(
|
||||
fcx: @mut FnCtxt, expr: @ast::Expr,
|
||||
fcx: @FnCtxt, expr: @ast::Expr,
|
||||
expected: ty::t) {
|
||||
check_expr_with_unifier(fcx, expr, Some(expected), || {
|
||||
demand::suptype(fcx, expr.span, expected, fcx.expr_ty(expr));
|
||||
|
|
@ -1398,7 +1399,7 @@ pub fn check_expr_has_type(
|
|||
}
|
||||
|
||||
pub fn check_expr_coercable_to_type(
|
||||
fcx: @mut FnCtxt, expr: @ast::Expr,
|
||||
fcx: @FnCtxt, expr: @ast::Expr,
|
||||
expected: ty::t) {
|
||||
check_expr_with_unifier(fcx, expr, Some(expected), || {
|
||||
demand::coerce(fcx, expr.span, expected, expr)
|
||||
|
|
@ -1406,18 +1407,18 @@ pub fn check_expr_coercable_to_type(
|
|||
}
|
||||
|
||||
pub fn check_expr_with_hint(
|
||||
fcx: @mut FnCtxt, expr: @ast::Expr,
|
||||
fcx: @FnCtxt, expr: @ast::Expr,
|
||||
expected: ty::t) {
|
||||
check_expr_with_unifier(fcx, expr, Some(expected), || ())
|
||||
}
|
||||
|
||||
pub fn check_expr_with_opt_hint(
|
||||
fcx: @mut FnCtxt, expr: @ast::Expr,
|
||||
fcx: @FnCtxt, expr: @ast::Expr,
|
||||
expected: Option<ty::t>) {
|
||||
check_expr_with_unifier(fcx, expr, expected, || ())
|
||||
}
|
||||
|
||||
pub fn check_expr(fcx: @mut FnCtxt, expr: @ast::Expr) {
|
||||
pub fn check_expr(fcx: @FnCtxt, expr: @ast::Expr) {
|
||||
check_expr_with_unifier(fcx, expr, None, || ())
|
||||
}
|
||||
|
||||
|
|
@ -1489,7 +1490,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: @mut 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
|
||||
|
|
@ -1623,14 +1624,14 @@ fn check_type_parameter_positions_in_path(function_context: @mut 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.
|
||||
pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
||||
pub fn check_expr_with_unifier(fcx: @FnCtxt,
|
||||
expr: @ast::Expr,
|
||||
expected: Option<ty::t>,
|
||||
unifier: ||) {
|
||||
debug!(">> typechecking");
|
||||
|
||||
fn check_method_argument_types(
|
||||
fcx: @mut FnCtxt,
|
||||
fcx: @FnCtxt,
|
||||
sp: Span,
|
||||
method_fn_ty: ty::t,
|
||||
callee_expr: @ast::Expr,
|
||||
|
|
@ -1659,7 +1660,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
}
|
||||
}
|
||||
|
||||
fn check_argument_types(fcx: @mut FnCtxt,
|
||||
fn check_argument_types(fcx: @FnCtxt,
|
||||
sp: Span,
|
||||
fn_inputs: &[ty::t],
|
||||
callee_expr: @ast::Expr,
|
||||
|
|
@ -1809,7 +1810,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
}
|
||||
|
||||
// A generic function for checking assignment expressions
|
||||
fn check_assignment(fcx: @mut FnCtxt,
|
||||
fn check_assignment(fcx: @FnCtxt,
|
||||
lhs: @ast::Expr,
|
||||
rhs: @ast::Expr,
|
||||
id: ast::NodeId) {
|
||||
|
|
@ -1820,7 +1821,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
// The callee checks for bot / err, we don't need to
|
||||
}
|
||||
|
||||
fn write_call(fcx: @mut FnCtxt,
|
||||
fn write_call(fcx: @FnCtxt,
|
||||
call_expr: @ast::Expr,
|
||||
output: ty::t,
|
||||
sugar: ast::CallSugar) {
|
||||
|
|
@ -1841,7 +1842,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
}
|
||||
|
||||
// A generic function for doing all of the checking for call expressions
|
||||
fn check_call(fcx: @mut FnCtxt,
|
||||
fn check_call(fcx: @FnCtxt,
|
||||
callee_id: ast::NodeId,
|
||||
call_expr: @ast::Expr,
|
||||
f: @ast::Expr,
|
||||
|
|
@ -1903,7 +1904,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
}
|
||||
|
||||
// Checks a method call.
|
||||
fn check_method_call(fcx: @mut FnCtxt,
|
||||
fn check_method_call(fcx: @FnCtxt,
|
||||
callee_id: ast::NodeId,
|
||||
expr: @ast::Expr,
|
||||
rcvr: @ast::Expr,
|
||||
|
|
@ -1963,7 +1964,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
|
||||
// A generic function for checking the then and else in an if
|
||||
// or if-check
|
||||
fn check_then_else(fcx: @mut FnCtxt,
|
||||
fn check_then_else(fcx: @FnCtxt,
|
||||
cond_expr: @ast::Expr,
|
||||
then_blk: &ast::Block,
|
||||
opt_else_expr: Option<@ast::Expr>,
|
||||
|
|
@ -2002,7 +2003,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
fcx.write_ty(id, if_ty);
|
||||
}
|
||||
|
||||
fn lookup_op_method(fcx: @mut FnCtxt,
|
||||
fn lookup_op_method(fcx: @FnCtxt,
|
||||
callee_id: ast::NodeId,
|
||||
op_ex: @ast::Expr,
|
||||
self_ex: @ast::Expr,
|
||||
|
|
@ -2040,7 +2041,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
}
|
||||
|
||||
// could be either a expr_binop or an expr_assign_binop
|
||||
fn check_binop(fcx: @mut FnCtxt,
|
||||
fn check_binop(fcx: @FnCtxt,
|
||||
callee_id: ast::NodeId,
|
||||
expr: @ast::Expr,
|
||||
op: ast::BinOp,
|
||||
|
|
@ -2128,7 +2129,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
}
|
||||
}
|
||||
|
||||
fn check_user_binop(fcx: @mut FnCtxt,
|
||||
fn check_user_binop(fcx: @FnCtxt,
|
||||
callee_id: ast::NodeId,
|
||||
ex: @ast::Expr,
|
||||
lhs_expr: @ast::Expr,
|
||||
|
|
@ -2170,7 +2171,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
ty::mk_err()
|
||||
}
|
||||
|
||||
fn check_user_unop(fcx: @mut FnCtxt,
|
||||
fn check_user_unop(fcx: @FnCtxt,
|
||||
callee_id: ast::NodeId,
|
||||
op_str: &str,
|
||||
mname: &str,
|
||||
|
|
@ -2196,7 +2197,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
// resolution is not possible (e.g., no constraints yet present), just
|
||||
// returns `none`.
|
||||
fn unpack_expected<O>(
|
||||
fcx: @mut FnCtxt,
|
||||
fcx: @FnCtxt,
|
||||
expected: Option<ty::t>,
|
||||
unpack: |&ty::sty| -> Option<O>)
|
||||
-> Option<O> {
|
||||
|
|
@ -2211,7 +2212,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
}
|
||||
}
|
||||
|
||||
fn check_expr_fn(fcx: @mut FnCtxt,
|
||||
fn check_expr_fn(fcx: @FnCtxt,
|
||||
expr: @ast::Expr,
|
||||
ast_sigil_opt: Option<ast::Sigil>,
|
||||
decl: &ast::fn_decl,
|
||||
|
|
@ -2306,7 +2307,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
fcx.write_ty(expr.id, fty);
|
||||
|
||||
let (inherited_purity, id) =
|
||||
ty::determine_inherited_purity((fcx.ps.purity, fcx.ps.def),
|
||||
ty::determine_inherited_purity((fcx.ps.get().purity,
|
||||
fcx.ps.get().def),
|
||||
(purity, expr.id),
|
||||
sigil);
|
||||
|
||||
|
|
@ -2316,7 +2318,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
|
||||
|
||||
// Check field access expressions
|
||||
fn check_field(fcx: @mut FnCtxt,
|
||||
fn check_field(fcx: @FnCtxt,
|
||||
expr: @ast::Expr,
|
||||
base: @ast::Expr,
|
||||
field: ast::Name,
|
||||
|
|
@ -2387,7 +2389,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
fcx.write_error(expr.id);
|
||||
}
|
||||
|
||||
fn check_struct_or_variant_fields(fcx: @mut FnCtxt,
|
||||
fn check_struct_or_variant_fields(fcx: @FnCtxt,
|
||||
struct_ty: ty::t,
|
||||
span: Span,
|
||||
class_id: ast::DefId,
|
||||
|
|
@ -2480,7 +2482,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
}
|
||||
}
|
||||
|
||||
fn check_struct_constructor(fcx: @mut FnCtxt,
|
||||
fn check_struct_constructor(fcx: @FnCtxt,
|
||||
id: ast::NodeId,
|
||||
span: codemap::Span,
|
||||
class_id: ast::DefId,
|
||||
|
|
@ -2538,7 +2540,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
fcx.write_ty(id, struct_type);
|
||||
}
|
||||
|
||||
fn check_struct_enum_variant(fcx: @mut FnCtxt,
|
||||
fn check_struct_enum_variant(fcx: @FnCtxt,
|
||||
id: ast::NodeId,
|
||||
span: codemap::Span,
|
||||
enum_id: ast::DefId,
|
||||
|
|
@ -3069,7 +3071,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
_ => false
|
||||
}
|
||||
}
|
||||
fn types_compatible(fcx: @mut FnCtxt, sp: Span,
|
||||
fn types_compatible(fcx: @FnCtxt, sp: Span,
|
||||
t1: ty::t, t2: ty::t) -> bool {
|
||||
if !is_vec(t1) {
|
||||
false
|
||||
|
|
@ -3257,7 +3259,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
|
|||
unifier();
|
||||
}
|
||||
|
||||
pub fn require_integral(fcx: @mut 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 `{}`",
|
||||
|
|
@ -3266,7 +3268,7 @@ pub fn require_integral(fcx: @mut FnCtxt, sp: Span, t: ty::t) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn check_decl_initializer(fcx: @mut FnCtxt,
|
||||
pub fn check_decl_initializer(fcx: @FnCtxt,
|
||||
nid: ast::NodeId,
|
||||
init: @ast::Expr)
|
||||
{
|
||||
|
|
@ -3274,7 +3276,7 @@ pub fn check_decl_initializer(fcx: @mut FnCtxt,
|
|||
check_expr_coercable_to_type(fcx, init, local_ty)
|
||||
}
|
||||
|
||||
pub fn check_decl_local(fcx: @mut 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);
|
||||
|
|
@ -3302,7 +3304,7 @@ pub fn check_decl_local(fcx: @mut FnCtxt, local: @ast::Local) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn check_stmt(fcx: @mut 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;
|
||||
|
|
@ -3347,7 +3349,7 @@ pub fn check_stmt(fcx: @mut FnCtxt, stmt: @ast::Stmt) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn check_block_no_value(fcx: @mut 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) {
|
||||
|
|
@ -3362,15 +3364,18 @@ pub fn check_block_no_value(fcx: @mut FnCtxt, blk: &ast::Block) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn check_block(fcx0: @mut 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: @mut FnCtxt,
|
||||
pub fn check_block_with_expected(fcx: @FnCtxt,
|
||||
blk: &ast::Block,
|
||||
expected: Option<ty::t>) {
|
||||
let purity_state = fcx.ps.recurse(blk);
|
||||
let prev = replace(&mut fcx.ps, purity_state);
|
||||
let prev = {
|
||||
let mut fcx_ps = fcx.ps.borrow_mut();
|
||||
let purity_state = fcx_ps.get().recurse(blk);
|
||||
replace(fcx_ps.get(), purity_state)
|
||||
};
|
||||
|
||||
fcx.with_region_lb(blk.id, || {
|
||||
let mut warned = false;
|
||||
|
|
@ -3427,7 +3432,7 @@ pub fn check_block_with_expected(fcx: @mut FnCtxt,
|
|||
};
|
||||
});
|
||||
|
||||
fcx.ps = prev;
|
||||
fcx.ps.set(prev);
|
||||
}
|
||||
|
||||
pub fn check_const(ccx: @mut CrateCtxt,
|
||||
|
|
@ -3440,7 +3445,7 @@ pub fn check_const(ccx: @mut CrateCtxt,
|
|||
check_const_with_ty(fcx, sp, e, declty);
|
||||
}
|
||||
|
||||
pub fn check_const_with_ty(fcx: @mut FnCtxt,
|
||||
pub fn check_const_with_ty(fcx: @FnCtxt,
|
||||
_: Span,
|
||||
e: @ast::Expr,
|
||||
declty: ty::t) {
|
||||
|
|
@ -3642,12 +3647,12 @@ pub fn check_enum_variants(ccx: @mut CrateCtxt,
|
|||
check_instantiable(ccx.tcx, sp, id);
|
||||
}
|
||||
|
||||
pub fn lookup_def(fcx: @mut 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: @mut FnCtxt,
|
||||
pub fn ty_param_bounds_and_ty_for_def(fcx: @FnCtxt,
|
||||
sp: Span,
|
||||
defn: ast::Def)
|
||||
-> ty_param_bounds_and_ty {
|
||||
|
|
@ -3697,7 +3702,7 @@ pub fn ty_param_bounds_and_ty_for_def(fcx: @mut 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: @mut FnCtxt,
|
||||
pub fn instantiate_path(fcx: @FnCtxt,
|
||||
pth: &ast::Path,
|
||||
tpt: ty_param_bounds_and_ty,
|
||||
def: ast::Def,
|
||||
|
|
@ -3812,7 +3817,7 @@ pub fn instantiate_path(fcx: @mut FnCtxt,
|
|||
|
||||
// Resolves `typ` by a single level if `typ` is a type variable. If no
|
||||
// resolution is possible, then an error is reported.
|
||||
pub fn structurally_resolved_type(fcx: @mut FnCtxt, sp: Span, tp: ty::t)
|
||||
pub fn structurally_resolved_type(fcx: @FnCtxt, sp: Span, tp: ty::t)
|
||||
-> ty::t {
|
||||
match infer::resolve_type(fcx.infcx(), tp, force_tvar) {
|
||||
Ok(t_s) if !ty::type_is_ty_var(t_s) => t_s,
|
||||
|
|
@ -3827,47 +3832,47 @@ pub fn structurally_resolved_type(fcx: @mut FnCtxt, sp: Span, tp: ty::t)
|
|||
}
|
||||
|
||||
// Returns the one-level-deep structure of the given type.
|
||||
pub fn structure_of<'a>(fcx: @mut 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: @mut 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: @mut 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: @mut 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: @mut 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: @mut 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: @mut 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: @mut 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: @mut FnCtxt,
|
||||
pub fn ast_expr_vstore_to_vstore(fcx: @FnCtxt,
|
||||
e: @ast::Expr,
|
||||
v: ast::ExprVstore)
|
||||
-> ty::vstore {
|
||||
|
|
|
|||
|
|
@ -47,14 +47,14 @@ use syntax::visit;
|
|||
use syntax::visit::Visitor;
|
||||
|
||||
pub struct Rcx {
|
||||
fcx: @mut FnCtxt,
|
||||
fcx: @FnCtxt,
|
||||
errors_reported: uint,
|
||||
|
||||
// id of innermost fn or loop
|
||||
repeating_scope: ast::NodeId,
|
||||
}
|
||||
|
||||
fn encl_region_of_def(fcx: @mut FnCtxt, def: ast::Def) -> ty::Region {
|
||||
fn encl_region_of_def(fcx: @FnCtxt, def: ast::Def) -> ty::Region {
|
||||
let tcx = fcx.tcx();
|
||||
match def {
|
||||
DefLocal(node_id, _) | DefArg(node_id, _) |
|
||||
|
|
@ -141,7 +141,7 @@ impl Rcx {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn regionck_expr(fcx: @mut 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;
|
||||
|
|
@ -152,7 +152,7 @@ pub fn regionck_expr(fcx: @mut FnCtxt, e: @ast::Expr) {
|
|||
fcx.infcx().resolve_regions();
|
||||
}
|
||||
|
||||
pub fn regionck_fn(fcx: @mut FnCtxt, blk: ast::P<ast::Block>) {
|
||||
pub fn regionck_fn(fcx: @FnCtxt, blk: ast::P<ast::Block>) {
|
||||
let mut rcx = Rcx { fcx: fcx, errors_reported: 0,
|
||||
repeating_scope: blk.id };
|
||||
let rcx = &mut rcx;
|
||||
|
|
|
|||
|
|
@ -528,7 +528,7 @@ fn connect_trait_tps(vcx: &VtableContext,
|
|||
relate_trait_refs(vcx, location_info, impl_trait_ref, trait_ref);
|
||||
}
|
||||
|
||||
fn insert_vtables(fcx: @mut FnCtxt,
|
||||
fn insert_vtables(fcx: @FnCtxt,
|
||||
callee_id: ast::NodeId,
|
||||
vtables: vtable_res) {
|
||||
debug!("insert_vtables(callee_id={}, vtables={:?})",
|
||||
|
|
@ -550,7 +550,7 @@ pub fn location_info_for_item(item: @ast::item) -> LocationInfo {
|
|||
}
|
||||
|
||||
pub fn early_resolve_expr(ex: @ast::Expr,
|
||||
fcx: @mut FnCtxt,
|
||||
fcx: @FnCtxt,
|
||||
is_early: bool) {
|
||||
debug!("vtable: early_resolve_expr() ex with id {:?} (early: {}): {}",
|
||||
ex.id, is_early, expr_to_str(ex, fcx.tcx().sess.intr()));
|
||||
|
|
@ -715,7 +715,7 @@ pub fn early_resolve_expr(ex: @ast::Expr,
|
|||
}
|
||||
}
|
||||
|
||||
fn resolve_expr(fcx: @mut FnCtxt,
|
||||
fn resolve_expr(fcx: @FnCtxt,
|
||||
ex: @ast::Expr) {
|
||||
let mut fcx = fcx;
|
||||
early_resolve_expr(ex, fcx, false);
|
||||
|
|
@ -776,7 +776,7 @@ pub fn resolve_impl(ccx: @mut CrateCtxt,
|
|||
ccx.tcx.impl_vtables.insert(impl_def_id, res);
|
||||
}
|
||||
|
||||
impl visit::Visitor<()> for @mut FnCtxt {
|
||||
impl visit::Visitor<()> for @FnCtxt {
|
||||
fn visit_expr(&mut self, ex:@ast::Expr, _:()) {
|
||||
resolve_expr(*self, ex);
|
||||
}
|
||||
|
|
@ -787,7 +787,7 @@ impl visit::Visitor<()> for @mut FnCtxt {
|
|||
|
||||
// Detect points where a trait-bounded type parameter is
|
||||
// instantiated, resolve the impls for the parameters.
|
||||
pub fn resolve_in_block(fcx: @mut FnCtxt, bl: ast::P<ast::Block>) {
|
||||
pub fn resolve_in_block(fcx: @FnCtxt, bl: ast::P<ast::Block>) {
|
||||
let mut fcx = fcx;
|
||||
visit::walk_block(&mut fcx, bl, ());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ use syntax::print::pprust::pat_to_str;
|
|||
use syntax::visit;
|
||||
use syntax::visit::Visitor;
|
||||
|
||||
fn resolve_type_vars_in_type(fcx: @mut 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) {
|
||||
|
|
@ -50,7 +50,7 @@ fn resolve_type_vars_in_type(fcx: @mut FnCtxt, sp: Span, typ: ty::t)
|
|||
}
|
||||
}
|
||||
|
||||
fn resolve_type_vars_in_types(fcx: @mut FnCtxt, sp: Span, tys: &[ty::t])
|
||||
fn resolve_type_vars_in_types(fcx: @FnCtxt, sp: Span, tys: &[ty::t])
|
||||
-> ~[ty::t] {
|
||||
tys.map(|t| {
|
||||
match resolve_type_vars_in_type(fcx, sp, *t) {
|
||||
|
|
@ -60,7 +60,7 @@ fn resolve_type_vars_in_types(fcx: @mut FnCtxt, sp: Span, tys: &[ty::t])
|
|||
})
|
||||
}
|
||||
|
||||
fn resolve_method_map_entry(fcx: @mut FnCtxt, sp: Span, id: ast::NodeId) {
|
||||
fn resolve_method_map_entry(fcx: @FnCtxt, sp: Span, id: ast::NodeId) {
|
||||
// Resolve any method map entry
|
||||
match fcx.inh.method_map.find(&id) {
|
||||
None => {}
|
||||
|
|
@ -80,7 +80,7 @@ fn resolve_method_map_entry(fcx: @mut FnCtxt, sp: Span, id: ast::NodeId) {
|
|||
}
|
||||
}
|
||||
|
||||
fn resolve_vtable_map_entry(fcx: @mut FnCtxt, sp: Span, id: ast::NodeId) {
|
||||
fn resolve_vtable_map_entry(fcx: @FnCtxt, sp: Span, id: ast::NodeId) {
|
||||
// Resolve any method map entry
|
||||
match fcx.inh.vtable_map.find(&id) {
|
||||
None => {}
|
||||
|
|
@ -93,12 +93,12 @@ fn resolve_vtable_map_entry(fcx: @mut FnCtxt, sp: Span, id: ast::NodeId) {
|
|||
}
|
||||
}
|
||||
|
||||
fn resolve_origins(fcx: @mut 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: @mut FnCtxt,
|
||||
fn resolve_origin(fcx: @FnCtxt,
|
||||
sp: Span,
|
||||
origin: &vtable_origin) -> vtable_origin {
|
||||
match origin {
|
||||
|
|
@ -208,7 +208,7 @@ fn maybe_resolve_type_vars_for_node(wbcx: &mut WbCtxt,
|
|||
}
|
||||
|
||||
struct WbCtxt {
|
||||
fcx: @mut FnCtxt,
|
||||
fcx: @FnCtxt,
|
||||
|
||||
// As soon as we hit an error we have to stop resolving
|
||||
// the entire function.
|
||||
|
|
@ -329,14 +329,14 @@ impl Visitor<()> for WbCtxt {
|
|||
fn visit_ty(&mut self, _t: &ast::Ty, _:()) {}
|
||||
}
|
||||
|
||||
pub fn resolve_type_vars_in_expr(fcx: @mut 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, ());
|
||||
return wbcx.success;
|
||||
}
|
||||
|
||||
pub fn resolve_type_vars_in_fn(fcx: @mut FnCtxt,
|
||||
pub fn resolve_type_vars_in_fn(fcx: @FnCtxt,
|
||||
decl: &ast::fn_decl,
|
||||
blk: ast::P<ast::Block>,
|
||||
self_info: Option<SelfInfo>) -> bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue