Auto merge of #23691 - richo:dedup-typeorigin-mergable, r=eddyb

I've started on refactoring the error handling code to avoid the need to reparse generated errors in `span_*`, but would rather land this incrementally as one monolithic PR (and have un-fond memories of merge conflicts from various other monoliths)

r? @eddyb
This commit is contained in:
bors 2015-03-26 05:44:26 +00:00
commit b0fd67b3e7
2 changed files with 40 additions and 29 deletions

View file

@ -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));
@ -1495,38 +1481,38 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
infer::Subtype(ref trace) => {
let desc = match trace.origin {
infer::Misc(_) => {
format!("types are compatible")
"types are compatible"
}
infer::MethodCompatCheck(_) => {
format!("method type is compatible with trait")
"method type is compatible with trait"
}
infer::ExprAssignable(_) => {
format!("expression is assignable")
"expression is assignable"
}
infer::RelateTraitRefs(_) => {
format!("traits are compatible")
"traits are compatible"
}
infer::RelateSelfType(_) => {
format!("self type matches impl self type")
"self type matches impl self type"
}
infer::RelateOutputImplTypes(_) => {
format!("trait type parameters matches those \
specified on the impl")
"trait type parameters matches those \
specified on the impl"
}
infer::MatchExpressionArm(_, _) => {
format!("match arms have compatible types")
"match arms have compatible types"
}
infer::IfExpression(_) => {
format!("if and else have compatible types")
"if and else have compatible types"
}
infer::IfExpressionWithNoElse(_) => {
format!("if may be missing an else clause")
"if may be missing an else clause"
}
infer::RangeExpression(_) => {
format!("start and end of range have compatible types")
"start and end of range have compatible types"
}
infer::EquatePredicate(_) => {
format!("equality where clause is satisfied")
"equality where clause is satisfied"
}
};
@ -1666,8 +1652,8 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
infer::RelateRegionParamBound(span) => {
self.tcx.sess.span_note(
span,
&format!("...so that the declared lifetime parameter bounds \
are satisfied"));
"...so that the declared lifetime parameter bounds \
are satisfied");
}
infer::SafeDestructor(span) => {
self.tcx.sess.span_note(

View file

@ -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,30 @@ pub enum TypeOrigin {
EquatePredicate(Span),
}
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::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",
}
}
}
impl fmt::Display for TypeOrigin {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(),fmt::Error> {
fmt::Display::fmt(self.as_str(), f)
}
}
/// See `error_reporting.rs` for more details
#[derive(Clone, Debug)]
pub enum ValuePairs<'tcx> {