Skip to content

Commit 385b5a3

Browse files
committed
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.
1 parent ed81038 commit 385b5a3

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/librustc/middle/infer/error_reporting.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -357,23 +357,9 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
357357
}
358358
};
359359

360-
let message_root_str = match trace.origin {
361-
infer::Misc(_) => "mismatched types",
362-
infer::MethodCompatCheck(_) => "method not compatible with trait",
363-
infer::ExprAssignable(_) => "mismatched types",
364-
infer::RelateTraitRefs(_) => "mismatched traits",
365-
infer::RelateSelfType(_) => "mismatched types",
366-
infer::RelateOutputImplTypes(_) => "mismatched types",
367-
infer::MatchExpressionArm(_, _) => "match arms have incompatible types",
368-
infer::IfExpression(_) => "if and else have incompatible types",
369-
infer::IfExpressionWithNoElse(_) => "if may be missing an else clause",
370-
infer::RangeExpression(_) => "start and end of range have incompatible types",
371-
infer::EquatePredicate(_) => "equality predicate not satisfied",
372-
};
373-
374360
span_err!(self.tcx.sess, trace.origin.span(), E0308,
375361
"{}: {} ({})",
376-
message_root_str,
362+
trace.origin,
377363
expected_found_str,
378364
ty::type_err_to_str(self.tcx, terr));
379365

src/librustc/middle/infer/mod.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use middle::ty::replace_late_bound_regions;
2929
use middle::ty::{self, Ty};
3030
use middle::ty_fold::{TypeFolder, TypeFoldable};
3131
use std::cell::{RefCell};
32+
use std::fmt;
3233
use std::rc::Rc;
3334
use syntax::ast;
3435
use syntax::codemap;
@@ -128,6 +129,25 @@ pub enum TypeOrigin {
128129
EquatePredicate(Span),
129130
}
130131

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+
131151
/// See `error_reporting.rs` for more details
132152
#[derive(Clone, Debug)]
133153
pub enum ValuePairs<'tcx> {

0 commit comments

Comments
 (0)