提交 abfa8164 编写于 作者: L Lindsey Kuper

Change the level of forcing in structurally_resolved_type().

A cleaner way to handle suffix inference for unary minus exprs.
上级 31786467
......@@ -74,7 +74,7 @@
import rscope::{in_binding_rscope, region_scope, type_rscope};
import syntax::ast::ty_i;
import typeck::infer::{unify_methods}; // infcx.set()
import typeck::infer::{force_level, force_none, force_non_region_vars_only,
import typeck::infer::{force_level, force_none, force_ty_vars_only,
force_all};
type fn_ctxt =
......@@ -1174,14 +1174,7 @@ fn check_expr_fn(fcx: @fn_ctxt,
}
}
ast::neg {
// If the operand's type is an integral type variable, we
// don't want to resolve it yet, because the rest of the
// typing context might not have had the opportunity to
// constrain it yet.
if !(ty::type_is_var_integral(oprnd_t)) {
oprnd_t = structurally_resolved_type(fcx, oprnd.span,
oprnd_t);
}
oprnd_t = structurally_resolved_type(fcx, oprnd.span, oprnd_t);
if !(ty::type_is_integral(oprnd_t) ||
ty::type_is_fp(oprnd_t)) {
oprnd_t = check_user_unop(fcx, "-", "unary-", expr,
......@@ -2116,7 +2109,7 @@ fn instantiate_path(fcx: @fn_ctxt,
// resolution is possible, then an error is reported.
fn structurally_resolved_type(fcx: @fn_ctxt, sp: span, tp: ty::t) -> ty::t {
alt infer::resolve_shallow(fcx.infcx, tp,
force_non_region_vars_only) {
force_ty_vars_only) {
result::ok(t_s) if !ty::type_is_var(t_s) { ret t_s; }
_ {
fcx.ccx.tcx.sess.span_fatal
......
......@@ -197,7 +197,7 @@ fn bar() {
export assignment;
export root, to_str;
export int_ty_set_all;
export force_level, force_none, force_non_region_vars_only, force_all;
export force_level, force_none, force_ty_vars_only, force_all;
// Bitvector to represent sets of integral types
enum int_ty_set = uint;
......@@ -1093,9 +1093,9 @@ enum force_level {
// Any unconstrained variables are OK.
force_none,
// Unconstrained region vars are OK; unconstrained ty vars and
// integral ty vars result in an error.
force_non_region_vars_only,
// Unconstrained region vars and integral ty vars are OK;
// unconstrained general-purpose ty vars result in an error.
force_ty_vars_only,
// Any unconstrained variables result in an error.
force_all,
......@@ -1237,7 +1237,7 @@ fn resolve_ty_var(vid: tv_vid) -> ty::t {
{ ub:_, lb:some(t) } { self.resolve1(t) }
{ ub:none, lb:none } {
alt self.force_vars {
force_non_region_vars_only | force_all {
force_ty_vars_only | force_all {
self.err = some(unresolved_ty(vid));
}
force_none { /* ok */ }
......@@ -1260,7 +1260,7 @@ fn resolve_ty_var_integral(vid: tvi_vid) -> ty::t {
some(t) { t }
none {
alt self.force_vars {
force_non_region_vars_only | force_all {
force_all {
// As a last resort, default to int.
let ty = ty::mk_int(self.infcx.tcx);
self.infcx.set(
......@@ -1270,7 +1270,7 @@ fn resolve_ty_var_integral(vid: tvi_vid) -> ty::t {
nde.rank));
ty
}
force_none {
force_none | force_ty_vars_only {
ty::mk_var_integral(self.infcx.tcx, vid)
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册