Skip to content

Commit

Permalink
infer: Refactor Display impl
Browse files Browse the repository at this point in the history
  • Loading branch information
richo committed Mar 26, 2015
1 parent 385b5a3 commit e15bebf
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/librustc/middle/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,27 @@ 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",
impl TypeOrigin {
fn as_str(&self) -> &'static str {
match self {
&TypeOrigin::Misc(_) |
&TypeOrigin::RelateSelfType(_) |
&TypeOrigin::RelateOutputImplTypes(_) |
&TypeOrigin::ExprAssignable(_) => "mismatched types",
&TypeOrigin::RelateTraitRefs(_) => "mismatched traits",
&TypeOrigin::RelateSelfType(_) => "mismatched types",
&TypeOrigin::RelateOutputImplTypes(_) => "mismatched types",
&TypeOrigin::MethodCompatCheck(_) => "method not compatible with trait",
&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)
}
}
}

impl fmt::Display for TypeOrigin {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(),fmt::Error> {
fmt::Display::fmt(self.as_str(), f)
}
}

Expand Down

0 comments on commit e15bebf

Please sign in to comment.