Address review comments

This commit is contained in:
Jakub Bukaj 2014-10-29 18:59:04 +01:00
parent 66fbe4c22c
commit 1b79303f49
3 changed files with 27 additions and 18 deletions

View File

@ -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 `{}`",

View File

@ -112,7 +112,7 @@ pub trait ErrorReporting {
fn values_str(&self, values: &ValuePairs) -> Option<String>;
fn expected_found_str<T: UserString + Resolvable>(
fn expected_found_str<T: UserString + Resolvable + HasRemainingTypeVariables>(
&self,
exp_found: &ty::expected_found<T>)
-> Option<String>;
@ -402,7 +402,7 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> {
}
}
fn expected_found_str<T: UserString + Resolvable>(
fn expected_found_str<T: UserString + Resolvable + HasRemainingTypeVariables>(
&self,
exp_found: &ty::expected_found<T>)
-> Option<String>
@ -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<ty::InferTy>;
}
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<T: TypeFoldable> HasRemainingTypeVariables for T {
fn remaining_type_variables(&self, tcx: &ty::ctxt) -> HashSet<ty::InferTy> {
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<ty::TraitRef> {
fn resolve(&self, infcx: &InferCtxt) -> Rc<ty::TraitRef> {
Rc::new(infcx.resolve_type_vars_in_trait_ref_if_possible(&**self))
@ -1691,9 +1697,6 @@ impl Resolvable for Rc<ty::TraitRef> {
fn contains_error(&self) -> bool {
ty::trait_ref_contains_error(&**self)
}
fn remaining_type_variables(&self, _: &ty::ctxt) -> HashSet<ty::InferTy> {
HashSet::new()
}
}
fn lifetimes_in_scope(tcx: &ty::ctxt,

View File

@ -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(),