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.
This commit is contained in:
parent
ed81038504
commit
385b5a3a7d
2 changed files with 21 additions and 15 deletions
|
|
@ -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));
|
||||
|
||||
|
|
|
|||
|
|
@ -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> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue