Skip to content

Commit dc37664

Browse files
committed
infer: Take the origin in report_mismatched_types.
1 parent 871a1e1 commit dc37664

File tree

4 files changed

+19
-47
lines changed

4 files changed

+19
-47
lines changed

src/librustc/middle/infer/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,18 +1351,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13511351
}
13521352

13531353
pub fn report_mismatched_types(&self,
1354-
span: Span,
1354+
origin: TypeOrigin,
13551355
expected: Ty<'tcx>,
13561356
actual: Ty<'tcx>,
1357-
err: &TypeError<'tcx>) {
1357+
err: TypeError<'tcx>) {
13581358
let trace = TypeTrace {
1359-
origin: TypeOrigin::Misc(span),
1359+
origin: origin,
13601360
values: Types(ExpectedFound {
13611361
expected: expected,
13621362
found: actual
13631363
})
13641364
};
1365-
self.report_and_explain_type_error(trace, err);
1365+
self.report_and_explain_type_error(trace, &err);
13661366
}
13671367

13681368
pub fn report_conflicting_default_types(&self,

src/librustc_typeck/check/demand.rs

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,27 @@
1010

1111

1212
use check::{coercion, FnCtxt};
13-
use middle::ty::{self, Ty};
14-
use middle::infer::{self, TypeOrigin};
13+
use middle::ty::Ty;
14+
use middle::infer::TypeOrigin;
1515

16-
use std::result::Result::{Err, Ok};
1716
use syntax::codemap::Span;
1817
use rustc_front::hir;
1918

2019
// Requires that the two types unify, and prints an error message if
2120
// they don't.
2221
pub fn suptype<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span,
23-
ty_expected: Ty<'tcx>, ty_actual: Ty<'tcx>) {
24-
suptype_with_fn(fcx, sp, false, ty_expected, ty_actual,
25-
|sp, e, a, s| { fcx.report_mismatched_types(sp, e, a, s) })
26-
}
27-
28-
/// As `suptype`, but call `handle_err` if unification for subtyping fails.
29-
pub fn suptype_with_fn<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
30-
sp: Span,
31-
b_is_expected: bool,
32-
ty_a: Ty<'tcx>,
33-
ty_b: Ty<'tcx>,
34-
handle_err: F) where
35-
F: FnOnce(Span, Ty<'tcx>, Ty<'tcx>, &ty::error::TypeError<'tcx>),
36-
{
37-
// n.b.: order of actual, expected is reversed
38-
match infer::mk_subty(fcx.infcx(), b_is_expected, TypeOrigin::Misc(sp),
39-
ty_b, ty_a) {
40-
Ok(()) => { /* ok */ }
41-
Err(ref err) => {
42-
handle_err(sp, ty_a, ty_b, err);
43-
}
22+
expected: Ty<'tcx>, actual: Ty<'tcx>) {
23+
let origin = TypeOrigin::Misc(sp);
24+
if let Err(e) = fcx.infcx().sub_types(false, origin, actual, expected) {
25+
fcx.infcx().report_mismatched_types(origin, expected, actual, e);
4426
}
4527
}
4628

4729
pub fn eqtype<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span,
4830
expected: Ty<'tcx>, actual: Ty<'tcx>) {
49-
match infer::mk_eqty(fcx.infcx(), false, TypeOrigin::Misc(sp), actual, expected) {
50-
Ok(()) => { /* ok */ }
51-
Err(ref err) => { fcx.report_mismatched_types(sp, expected, actual, err); }
31+
let origin = TypeOrigin::Misc(sp);
32+
if let Err(e) = fcx.infcx().eq_types(false, origin, actual, expected) {
33+
fcx.infcx().report_mismatched_types(origin, expected, actual, e);
5234
}
5335
}
5436

@@ -63,10 +45,8 @@ pub fn coerce<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
6345
expr_ty);
6446
let expr_ty = fcx.resolve_type_vars_if_possible(expr_ty);
6547
let expected = fcx.resolve_type_vars_if_possible(expected);
66-
match coercion::mk_assignty(fcx, expr, expr_ty, expected) {
67-
Ok(()) => { /* ok */ }
68-
Err(ref err) => {
69-
fcx.report_mismatched_types(sp, expected, expr_ty, err);
70-
}
48+
let origin = TypeOrigin::Misc(sp);
49+
if let Err(e) = coercion::try(fcx, expr, expr_ty, expected) {
50+
fcx.infcx().report_mismatched_types(origin, expected, expr_ty, e);
7151
}
7252
}

src/librustc_typeck/check/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,14 +1622,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16221622
self.infcx().type_error_struct(sp, mk_msg, actual_ty, err)
16231623
}
16241624

1625-
pub fn report_mismatched_types(&self,
1626-
sp: Span,
1627-
e: Ty<'tcx>,
1628-
a: Ty<'tcx>,
1629-
err: &TypeError<'tcx>) {
1630-
self.infcx().report_mismatched_types(sp, e, a, err)
1631-
}
1632-
16331625
/// Registers an obligation for checking later, during regionck, that the type `ty` must
16341626
/// outlive the region `r`.
16351627
pub fn register_region_obligation(&self,

src/librustc_typeck/coherence/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,12 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
385385

386386
let infcx = new_infer_ctxt(tcx, &tcx.tables, Some(param_env));
387387

388+
let origin = TypeOrigin::Misc(span);
388389
let check_mutbl = |mt_a: ty::TypeAndMut<'tcx>, mt_b: ty::TypeAndMut<'tcx>,
389390
mk_ptr: &Fn(Ty<'tcx>) -> Ty<'tcx>| {
390391
if (mt_a.mutbl, mt_b.mutbl) == (hir::MutImmutable, hir::MutMutable) {
391-
infcx.report_mismatched_types(span, mk_ptr(mt_b.ty),
392-
target, &ty::error::TypeError::Mutability);
392+
infcx.report_mismatched_types(origin, mk_ptr(mt_b.ty),
393+
target, ty::error::TypeError::Mutability);
393394
}
394395
(mt_a.ty, mt_b.ty, unsize_trait, None)
395396
};
@@ -418,7 +419,6 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
418419
return;
419420
}
420421

421-
let origin = TypeOrigin::Misc(span);
422422
let fields = &def_a.struct_variant().fields;
423423
let diff_fields = fields.iter().enumerate().filter_map(|(i, f)| {
424424
let (a, b) = (f.ty(tcx, substs_a), f.ty(tcx, substs_b));

0 commit comments

Comments
 (0)