Skip to content

Dedupe typeorigin #23691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 15 additions & 29 deletions src/librustc/middle/infer/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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"
}
};

Expand Down Expand Up @@ -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(
Expand Down
25 changes: 25 additions & 0 deletions src/librustc/middle/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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> {
Expand Down