about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRicho Healey <richo@psych0tik.net>2015-03-19 14:49:28 -0700
committerRicho Healey <richo@psych0tik.net>2015-03-25 21:44:21 -0700
commit385b5a3a7d2d96701ebabd7a48a6332a212d9c99 (patch)
tree050c2536288e46efc65480571d26538ce0552569 /src
parented810385045ab0db90303574ba3ea47dfa2a36d5 (diff)
infer: Move TypeOrigin formatting onto it's enum
This doesn't actually solve the issue that prompted this, at:

https://github.com/rust-lang/rust/blob/master/src/librustc/session/mod.rs#L262-271

But skimming the cfg it appears that all type information has been
discarded long before that point.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/infer/error_reporting.rs16
-rw-r--r--src/librustc/middle/infer/mod.rs20
2 files changed, 21 insertions, 15 deletions
diff --git a/src/librustc/middle/infer/error_reporting.rs b/src/librustc/middle/infer/error_reporting.rs
index 1ca56596a01..590099b5966 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 835964828d4..5ad37b0df62 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> {