Skip to content

Commit e15bebf

Browse files
committed
infer: Refactor Display impl
1 parent 385b5a3 commit e15bebf

File tree

1 file changed

+14
-9
lines changed
  • src/librustc/middle/infer

1 file changed

+14
-9
lines changed

src/librustc/middle/infer/mod.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,22 +129,27 @@ pub enum TypeOrigin {
129129
EquatePredicate(Span),
130130
}
131131

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",
132+
impl TypeOrigin {
133+
fn as_str(&self) -> &'static str {
134+
match self {
135+
&TypeOrigin::Misc(_) |
136+
&TypeOrigin::RelateSelfType(_) |
137+
&TypeOrigin::RelateOutputImplTypes(_) |
137138
&TypeOrigin::ExprAssignable(_) => "mismatched types",
138139
&TypeOrigin::RelateTraitRefs(_) => "mismatched traits",
139-
&TypeOrigin::RelateSelfType(_) => "mismatched types",
140-
&TypeOrigin::RelateOutputImplTypes(_) => "mismatched types",
140+
&TypeOrigin::MethodCompatCheck(_) => "method not compatible with trait",
141141
&TypeOrigin::MatchExpressionArm(_, _) => "match arms have incompatible types",
142142
&TypeOrigin::IfExpression(_) => "if and else have incompatible types",
143143
&TypeOrigin::IfExpressionWithNoElse(_) => "if may be missing an else clause",
144144
&TypeOrigin::RangeExpression(_) => "start and end of range have incompatible types",
145145
&TypeOrigin::EquatePredicate(_) => "equality predicate not satisfied",
146-
};
147-
fmt::Display::fmt(msg, f)
146+
}
147+
}
148+
}
149+
150+
impl fmt::Display for TypeOrigin {
151+
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(),fmt::Error> {
152+
fmt::Display::fmt(self.as_str(), f)
148153
}
149154
}
150155

0 commit comments

Comments
 (0)