diff --git a/src/librustc/middle/infer/error_reporting.rs b/src/librustc/middle/infer/error_reporting.rs index 1ca56596a014..590099b59661 100644 --- a/src/librustc/middle/infer/error_reporting.rs +++ b/src/librustc/middle/infer/error_reporting.rs @@ -357,23 +357,9 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> { } }; - let message_root_str = match trace.origin { - infer::Misc(_) => "mismatched types", - infer::MethodCompatCheck(_) => "method not compatible with trait", - infer::ExprAssignable(_) => "mismatched types", - infer::RelateTraitRefs(_) => "mismatched traits", - infer::RelateSelfType(_) => "mismatched types", - infer::RelateOutputImplTypes(_) => "mismatched types", - infer::MatchExpressionArm(_, _) => "match arms have incompatible types", - infer::IfExpression(_) => "if and else have incompatible types", - infer::IfExpressionWithNoElse(_) => "if may be missing an else clause", - infer::RangeExpression(_) => "start and end of range have incompatible types", - infer::EquatePredicate(_) => "equality predicate not satisfied", - }; - span_err!(self.tcx.sess, trace.origin.span(), E0308, "{}: {} ({})", - message_root_str, + trace.origin, expected_found_str, ty::type_err_to_str(self.tcx, terr)); diff --git a/src/librustc/middle/infer/mod.rs b/src/librustc/middle/infer/mod.rs index 835964828d41..5ad37b0df627 100644 --- a/src/librustc/middle/infer/mod.rs +++ b/src/librustc/middle/infer/mod.rs @@ -29,6 +29,7 @@ use middle::ty::replace_late_bound_regions; use middle::ty::{self, Ty}; use middle::ty_fold::{TypeFolder, TypeFoldable}; use std::cell::{RefCell}; +use std::fmt; use std::rc::Rc; use syntax::ast; use syntax::codemap; @@ -128,6 +129,25 @@ pub enum TypeOrigin { EquatePredicate(Span), } +impl fmt::Display for TypeOrigin { + fn fmt(&self, f: &mut fmt::Formatter) -> Result<(),fmt::Error> { + let msg = match self { + &TypeOrigin::Misc(_) => "mismatched types", + &TypeOrigin::MethodCompatCheck(_) => "method not compatible with trait", + &TypeOrigin::ExprAssignable(_) => "mismatched types", + &TypeOrigin::RelateTraitRefs(_) => "mismatched traits", + &TypeOrigin::RelateSelfType(_) => "mismatched types", + &TypeOrigin::RelateOutputImplTypes(_) => "mismatched types", + &TypeOrigin::MatchExpressionArm(_, _) => "match arms have incompatible types", + &TypeOrigin::IfExpression(_) => "if and else have incompatible types", + &TypeOrigin::IfExpressionWithNoElse(_) => "if may be missing an else clause", + &TypeOrigin::RangeExpression(_) => "start and end of range have incompatible types", + &TypeOrigin::EquatePredicate(_) => "equality predicate not satisfied", + }; + fmt::Display::fmt(msg, f) + } +} + /// See `error_reporting.rs` for more details #[derive(Clone, Debug)] pub enum ValuePairs<'tcx> {