Skip to content

Commit 26bd186

Browse files
committed
Don't create a new inference context for checking pattern ranges.
Ugly fix -- it would be better to refactor and consolidate the various "make sure these types are the same" fns scattered around typeck.
1 parent 3e28143 commit 26bd186

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/rustc/middle/typeck.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,23 @@ fn require_same_types(
203203
}
204204
}
205205

206+
fn require_same_types_in_infcx(
207+
infcx: infer::infer_ctxt,
208+
span: span,
209+
t1: ty::t,
210+
t2: ty::t,
211+
msg: fn() -> str) -> bool {
212+
213+
alt infer::compare_tys_in_infcx(infcx, t1, t2) {
214+
result::ok(()) { true }
215+
result::err(terr) {
216+
infcx.tcx.sess.span_err(span, msg() + ": " +
217+
ty::type_err_to_str(infcx.tcx, terr));
218+
false
219+
}
220+
}
221+
}
222+
206223
fn arg_is_argv_ty(_tcx: ty::ctxt, a: ty::arg) -> bool {
207224
alt ty::get(a.ty).struct {
208225
ty::ty_vec(mt) {

src/rustc/middle/typeck/check/alt.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,12 @@ fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) {
137137
check_expr_with(fcx, end, expected);
138138
let b_ty =
139139
fcx.infcx.resolve_type_vars_if_possible(fcx.expr_ty(begin));
140-
if !require_same_types(
141-
tcx, pat.span, b_ty,
142-
fcx.infcx.resolve_type_vars_if_possible(fcx.expr_ty(end)),
140+
let e_ty =
141+
fcx.infcx.resolve_type_vars_if_possible(fcx.expr_ty(end));
142+
#debug["pat_range beginning type: %?", b_ty];
143+
#debug["pat_range ending type: %?", e_ty];
144+
if !require_same_types_in_infcx(
145+
fcx.infcx, pat.span, b_ty, e_ty,
143146
{|| "mismatched types in range" }) {
144147
// no-op
145148
} else if !ty::type_is_numeric(b_ty) {

src/rustc/middle/typeck/infer.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ export resolve_deep_var;
172172
export methods; // for infer_ctxt
173173
export unify_methods; // for infer_ctxt
174174
export compare_tys;
175+
export compare_tys_in_infcx;
175176
export fixup_err, fixup_err_to_str;
176177
export assignment;
177178
export root, to_str;
@@ -381,6 +382,10 @@ fn compare_tys(tcx: ty::ctxt, a: ty::t, b: ty::t) -> ures {
381382
mk_eqty(infcx, a, b)
382383
}
383384

385+
fn compare_tys_in_infcx(infcx: infer_ctxt, a: ty::t, b: ty::t) -> ures {
386+
mk_eqty(infcx, a, b)
387+
}
388+
384389
// See comment on the type `resolve_state` below
385390
fn resolve_shallow(cx: infer_ctxt, a: ty::t,
386391
force_vars: force_level) -> fres<ty::t> {

0 commit comments

Comments
 (0)