@@ -29,6 +29,7 @@ use middle::ty::replace_late_bound_regions;
29
29
use middle:: ty:: { self , Ty } ;
30
30
use middle:: ty_fold:: { TypeFolder , TypeFoldable } ;
31
31
use std:: cell:: { RefCell } ;
32
+ use std:: fmt;
32
33
use std:: rc:: Rc ;
33
34
use syntax:: ast;
34
35
use syntax:: codemap;
@@ -128,6 +129,25 @@ pub enum TypeOrigin {
128
129
EquatePredicate ( Span ) ,
129
130
}
130
131
132
+ impl fmt:: Display for TypeOrigin {
133
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> Result < ( ) , fmt:: Error > {
134
+ let msg = match self {
135
+ & TypeOrigin :: Misc ( _) => "mismatched types" ,
136
+ & TypeOrigin :: MethodCompatCheck ( _) => "method not compatible with trait" ,
137
+ & TypeOrigin :: ExprAssignable ( _) => "mismatched types" ,
138
+ & TypeOrigin :: RelateTraitRefs ( _) => "mismatched traits" ,
139
+ & TypeOrigin :: RelateSelfType ( _) => "mismatched types" ,
140
+ & TypeOrigin :: RelateOutputImplTypes ( _) => "mismatched types" ,
141
+ & TypeOrigin :: MatchExpressionArm ( _, _) => "match arms have incompatible types" ,
142
+ & TypeOrigin :: IfExpression ( _) => "if and else have incompatible types" ,
143
+ & TypeOrigin :: IfExpressionWithNoElse ( _) => "if may be missing an else clause" ,
144
+ & TypeOrigin :: RangeExpression ( _) => "start and end of range have incompatible types" ,
145
+ & TypeOrigin :: EquatePredicate ( _) => "equality predicate not satisfied" ,
146
+ } ;
147
+ fmt:: Display :: fmt ( msg, f)
148
+ }
149
+ }
150
+
131
151
/// See `error_reporting.rs` for more details
132
152
#[ derive( Clone , Debug ) ]
133
153
pub enum ValuePairs < ' tcx > {
0 commit comments