Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Bukaj committed Oct 29, 2014
1 parent 66fbe4c commit 1b79303
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
12 changes: 9 additions & 3 deletions src/librustc/middle/ty.rs
Expand Up @@ -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 `{}`",
Expand Down
27 changes: 15 additions & 12 deletions src/librustc/middle/typeck/infer/error_reporting.rs
Expand Up @@ -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>;
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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();
{
Expand All @@ -1684,16 +1681,22 @@ 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))
}
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,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/util/ppaux.rs
Expand Up @@ -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(),
Expand Down

0 comments on commit 1b79303

Please sign in to comment.