diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 3ec1106ff20..ff949a93e01 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -3912,9 +3912,15 @@ pub fn type_err_to_str(cx: &ctxt, err: &type_err) -> String { trait_store_to_string(cx, (*values).found)) } terr_sorts(values) => { - format!("expected {}, found {}", - ty_sort_string(cx, values.expected), - ty_sort_string(cx, values.found)) + // A naive approach to making sure that we're not reporting silly errors such as: + // (expected closure, found closure). + let expected_str = ty_sort_string(cx, values.expected); + let found_str = ty_sort_string(cx, values.found); + if expected_str == found_str { + format!("expected {}, found a different {}", expected_str, found_str) + } else { + format!("expected {}, found {}", expected_str, found_str) + } } terr_traits(values) => { format!("expected trait `{}`, found trait `{}`", diff --git a/src/librustc/middle/typeck/infer/error_reporting.rs b/src/librustc/middle/typeck/infer/error_reporting.rs index 0f000e93fc0..e6c158ef9af 100644 --- a/src/librustc/middle/typeck/infer/error_reporting.rs +++ b/src/librustc/middle/typeck/infer/error_reporting.rs @@ -112,7 +112,7 @@ pub trait ErrorReporting { fn values_str(&self, values: &ValuePairs) -> Option; - fn expected_found_str( + fn expected_found_str( &self, exp_found: &ty::expected_found) -> Option; @@ -402,7 +402,7 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> { } } - fn expected_found_str( + fn expected_found_str( &self, exp_found: &ty::expected_found) -> Option @@ -1656,16 +1656,13 @@ impl<'a, 'tcx> ErrorReportingHelpers for InferCtxt<'a, 'tcx> { pub trait Resolvable { fn resolve(&self, infcx: &InferCtxt) -> Self; fn contains_error(&self) -> bool; +} + +pub trait HasRemainingTypeVariables { fn remaining_type_variables(&self, tcx: &ty::ctxt) -> HashSet; } -impl Resolvable for ty::t { - fn resolve(&self, infcx: &InferCtxt) -> ty::t { - infcx.resolve_type_vars_if_possible(*self) - } - fn contains_error(&self) -> bool { - ty::type_is_error(*self) - } +impl HasRemainingTypeVariables for T { fn remaining_type_variables(&self, tcx: &ty::ctxt) -> HashSet { let mut vars = HashSet::new(); { @@ -1684,6 +1681,15 @@ impl Resolvable for ty::t { } } +impl Resolvable for ty::t { + fn resolve(&self, infcx: &InferCtxt) -> ty::t { + infcx.resolve_type_vars_if_possible(*self) + } + fn contains_error(&self) -> bool { + ty::type_is_error(*self) + } +} + impl Resolvable for Rc { fn resolve(&self, infcx: &InferCtxt) -> Rc { Rc::new(infcx.resolve_type_vars_in_trait_ref_if_possible(&**self)) @@ -1691,9 +1697,6 @@ impl Resolvable for Rc { fn contains_error(&self) -> bool { ty::trait_ref_contains_error(&**self) } - fn remaining_type_variables(&self, _: &ty::ctxt) -> HashSet { - HashSet::new() - } } fn lifetimes_in_scope(tcx: &ty::ctxt, diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 572f2c9abf2..eb37f68154d 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -383,9 +383,9 @@ pub fn ty_to_string_with_var_ids(cx: &ctxt, typ: t, mut print_var_ids: bool) -> fn infer_ty_to_string(ty: ty::InferTy, print_var_ids: bool) -> String { match ty { - ty::TyVar(ty::TyVid { index: vid }) - | ty::IntVar(ty::IntVid { index: vid }) - | ty::FloatVar(ty::FloatVid { index: vid }) => { + ty::TyVar(ty::TyVid { index: vid }) | + ty::IntVar(ty::IntVid { index: vid }) | + ty::FloatVar(ty::FloatVid { index: vid }) => { match ty { ty::TyVar(_) if print_var_ids => format!("_#{}", vid), ty::TyVar(_) => "_".to_string(),