Skip to content

Commit bdf968c

Browse files
committed
rustc: Add a version of demand that takes in a set of region variable bindings
1 parent 30c272c commit bdf968c

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

src/rustc/middle/ty.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,8 +1542,8 @@ mod unify {
15421542
export resolve_type_structure;
15431543
export resolve_type_var;
15441544
export unify;
1545-
export var_bindings;
1546-
export precise, in_bindings;
1545+
export var_bindings, region_bindings;
1546+
export precise, in_bindings, in_region_bindings;
15471547

15481548
type ures<T> = result<T,type_err>;
15491549

@@ -1669,7 +1669,11 @@ mod unify {
16691669
typ: t, variance: variance,
16701670
nxt: fn(t) -> ures<T>) -> ures<T> {
16711671

1672-
let vb = alt check cx.st { in_bindings(vb) { vb } };
1672+
let vb = alt cx.st {
1673+
in_bindings(vb) | in_region_bindings(vb, _) { vb }
1674+
precise { fail; }
1675+
};
1676+
16731677
ufind::grow(vb.sets, (key as uint) + 1u);
16741678
let root = ufind::find(vb.sets, key as uint);
16751679
let result_type = typ;

src/rustc/middle/typeck.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,15 @@ mod collect {
10891089

10901090
// Type unification
10911091
mod unify {
1092+
fn unify_with_region_bindings(fcx: @fn_ctxt,
1093+
rb: @ty::unify::region_bindings,
1094+
expected: ty::t,
1095+
actual: ty::t)
1096+
-> result<ty::t, ty::type_err> {
1097+
let irb = ty::unify::in_region_bindings(fcx.var_bindings, rb);
1098+
ret ty::unify::unify(expected, actual, irb, fcx.ccx.tcx);
1099+
}
1100+
10921101
fn unify(fcx: @fn_ctxt, expected: ty::t, actual: ty::t) ->
10931102
result<ty::t, ty::type_err> {
10941103
ret ty::unify::unify(expected, actual,
@@ -1146,17 +1155,32 @@ type ty_param_substs_and_ty = {substs: [ty::t], ty: ty::t};
11461155
mod demand {
11471156
fn simple(fcx: @fn_ctxt, sp: span, expected: ty::t, actual: ty::t) ->
11481157
ty::t {
1149-
full(fcx, sp, expected, actual, []).ty
1158+
full(fcx, sp, unify::unify, expected, actual, []).ty
1159+
}
1160+
1161+
fn with_region_bindings(fcx: @fn_ctxt,
1162+
sp: span,
1163+
rb: @ty::unify::region_bindings,
1164+
expected: ty::t,
1165+
actual: ty::t)
1166+
-> ty::t {
1167+
full(fcx, sp, bind unify::unify_with_region_bindings(_, rb, _, _),
1168+
expected, actual, []).ty
11501169
}
11511170

11521171
fn with_substs(fcx: @fn_ctxt, sp: span, expected: ty::t, actual: ty::t,
11531172
ty_param_substs_0: [ty::t]) -> ty_param_substs_and_ty {
1154-
full(fcx, sp, expected, actual, ty_param_substs_0)
1173+
full(fcx, sp, unify::unify, expected, actual, ty_param_substs_0)
11551174
}
11561175

11571176
// Requires that the two types unify, and prints an error message if they
11581177
// don't. Returns the unified type and the type parameter substitutions.
1159-
fn full(fcx: @fn_ctxt, sp: span, expected: ty::t, actual: ty::t,
1178+
fn full(fcx: @fn_ctxt,
1179+
sp: span,
1180+
unifier: fn@(@fn_ctxt, ty::t, ty::t)
1181+
-> result<ty::t, ty::type_err>,
1182+
expected: ty::t,
1183+
actual: ty::t,
11601184
ty_param_substs_0: [ty::t]) ->
11611185
ty_param_substs_and_ty {
11621186

@@ -1183,7 +1207,7 @@ mod demand {
11831207
}
11841208

11851209

1186-
alt unify::unify(fcx, expected, actual) {
1210+
alt unifier(fcx, expected, actual) {
11871211
result::ok(t) { ret mk_result(fcx, t, ty_param_subst_var_ids); }
11881212
result::err(err) {
11891213
let e_err = resolve_type_vars_if_possible(fcx, expected);

0 commit comments

Comments
 (0)