infer: Take the origin in report_mismatched_types.
This commit is contained in:
parent
871a1e1cf8
commit
dc37664c94
@ -1351,18 +1351,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
}
|
||||
|
||||
pub fn report_mismatched_types(&self,
|
||||
span: Span,
|
||||
origin: TypeOrigin,
|
||||
expected: Ty<'tcx>,
|
||||
actual: Ty<'tcx>,
|
||||
err: &TypeError<'tcx>) {
|
||||
err: TypeError<'tcx>) {
|
||||
let trace = TypeTrace {
|
||||
origin: TypeOrigin::Misc(span),
|
||||
origin: origin,
|
||||
values: Types(ExpectedFound {
|
||||
expected: expected,
|
||||
found: actual
|
||||
})
|
||||
};
|
||||
self.report_and_explain_type_error(trace, err);
|
||||
self.report_and_explain_type_error(trace, &err);
|
||||
}
|
||||
|
||||
pub fn report_conflicting_default_types(&self,
|
||||
|
@ -10,45 +10,27 @@
|
||||
|
||||
|
||||
use check::{coercion, FnCtxt};
|
||||
use middle::ty::{self, Ty};
|
||||
use middle::infer::{self, TypeOrigin};
|
||||
use middle::ty::Ty;
|
||||
use middle::infer::TypeOrigin;
|
||||
|
||||
use std::result::Result::{Err, Ok};
|
||||
use syntax::codemap::Span;
|
||||
use rustc_front::hir;
|
||||
|
||||
// Requires that the two types unify, and prints an error message if
|
||||
// they don't.
|
||||
pub fn suptype<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span,
|
||||
ty_expected: Ty<'tcx>, ty_actual: Ty<'tcx>) {
|
||||
suptype_with_fn(fcx, sp, false, ty_expected, ty_actual,
|
||||
|sp, e, a, s| { fcx.report_mismatched_types(sp, e, a, s) })
|
||||
}
|
||||
|
||||
/// As `suptype`, but call `handle_err` if unification for subtyping fails.
|
||||
pub fn suptype_with_fn<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
sp: Span,
|
||||
b_is_expected: bool,
|
||||
ty_a: Ty<'tcx>,
|
||||
ty_b: Ty<'tcx>,
|
||||
handle_err: F) where
|
||||
F: FnOnce(Span, Ty<'tcx>, Ty<'tcx>, &ty::error::TypeError<'tcx>),
|
||||
{
|
||||
// n.b.: order of actual, expected is reversed
|
||||
match infer::mk_subty(fcx.infcx(), b_is_expected, TypeOrigin::Misc(sp),
|
||||
ty_b, ty_a) {
|
||||
Ok(()) => { /* ok */ }
|
||||
Err(ref err) => {
|
||||
handle_err(sp, ty_a, ty_b, err);
|
||||
}
|
||||
expected: Ty<'tcx>, actual: Ty<'tcx>) {
|
||||
let origin = TypeOrigin::Misc(sp);
|
||||
if let Err(e) = fcx.infcx().sub_types(false, origin, actual, expected) {
|
||||
fcx.infcx().report_mismatched_types(origin, expected, actual, e);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn eqtype<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, sp: Span,
|
||||
expected: Ty<'tcx>, actual: Ty<'tcx>) {
|
||||
match infer::mk_eqty(fcx.infcx(), false, TypeOrigin::Misc(sp), actual, expected) {
|
||||
Ok(()) => { /* ok */ }
|
||||
Err(ref err) => { fcx.report_mismatched_types(sp, expected, actual, err); }
|
||||
let origin = TypeOrigin::Misc(sp);
|
||||
if let Err(e) = fcx.infcx().eq_types(false, origin, actual, expected) {
|
||||
fcx.infcx().report_mismatched_types(origin, expected, actual, e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -63,10 +45,8 @@ pub fn coerce<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
expr_ty);
|
||||
let expr_ty = fcx.resolve_type_vars_if_possible(expr_ty);
|
||||
let expected = fcx.resolve_type_vars_if_possible(expected);
|
||||
match coercion::mk_assignty(fcx, expr, expr_ty, expected) {
|
||||
Ok(()) => { /* ok */ }
|
||||
Err(ref err) => {
|
||||
fcx.report_mismatched_types(sp, expected, expr_ty, err);
|
||||
}
|
||||
let origin = TypeOrigin::Misc(sp);
|
||||
if let Err(e) = coercion::try(fcx, expr, expr_ty, expected) {
|
||||
fcx.infcx().report_mismatched_types(origin, expected, expr_ty, e);
|
||||
}
|
||||
}
|
||||
|
@ -1622,14 +1622,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
self.infcx().type_error_struct(sp, mk_msg, actual_ty, err)
|
||||
}
|
||||
|
||||
pub fn report_mismatched_types(&self,
|
||||
sp: Span,
|
||||
e: Ty<'tcx>,
|
||||
a: Ty<'tcx>,
|
||||
err: &TypeError<'tcx>) {
|
||||
self.infcx().report_mismatched_types(sp, e, a, err)
|
||||
}
|
||||
|
||||
/// Registers an obligation for checking later, during regionck, that the type `ty` must
|
||||
/// outlive the region `r`.
|
||||
pub fn register_region_obligation(&self,
|
||||
|
@ -385,11 +385,12 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
|
||||
|
||||
let infcx = new_infer_ctxt(tcx, &tcx.tables, Some(param_env));
|
||||
|
||||
let origin = TypeOrigin::Misc(span);
|
||||
let check_mutbl = |mt_a: ty::TypeAndMut<'tcx>, mt_b: ty::TypeAndMut<'tcx>,
|
||||
mk_ptr: &Fn(Ty<'tcx>) -> Ty<'tcx>| {
|
||||
if (mt_a.mutbl, mt_b.mutbl) == (hir::MutImmutable, hir::MutMutable) {
|
||||
infcx.report_mismatched_types(span, mk_ptr(mt_b.ty),
|
||||
target, &ty::error::TypeError::Mutability);
|
||||
infcx.report_mismatched_types(origin, mk_ptr(mt_b.ty),
|
||||
target, ty::error::TypeError::Mutability);
|
||||
}
|
||||
(mt_a.ty, mt_b.ty, unsize_trait, None)
|
||||
};
|
||||
@ -418,7 +419,6 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
|
||||
return;
|
||||
}
|
||||
|
||||
let origin = TypeOrigin::Misc(span);
|
||||
let fields = &def_a.struct_variant().fields;
|
||||
let diff_fields = fields.iter().enumerate().filter_map(|(i, f)| {
|
||||
let (a, b) = (f.ty(tcx, substs_a), f.ty(tcx, substs_b));
|
||||
|
Loading…
x
Reference in New Issue
Block a user