Skip to content

Commit 1b79303

Browse files
author
Jakub Bukaj
committed
Address review comments
1 parent 66fbe4c commit 1b79303

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

src/librustc/middle/ty.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3912,9 +3912,15 @@ pub fn type_err_to_str(cx: &ctxt, err: &type_err) -> String {
39123912
trait_store_to_string(cx, (*values).found))
39133913
}
39143914
terr_sorts(values) => {
3915-
format!("expected {}, found {}",
3916-
ty_sort_string(cx, values.expected),
3917-
ty_sort_string(cx, values.found))
3915+
// A naive approach to making sure that we're not reporting silly errors such as:
3916+
// (expected closure, found closure).
3917+
let expected_str = ty_sort_string(cx, values.expected);
3918+
let found_str = ty_sort_string(cx, values.found);
3919+
if expected_str == found_str {
3920+
format!("expected {}, found a different {}", expected_str, found_str)
3921+
} else {
3922+
format!("expected {}, found {}", expected_str, found_str)
3923+
}
39183924
}
39193925
terr_traits(values) => {
39203926
format!("expected trait `{}`, found trait `{}`",

src/librustc/middle/typeck/infer/error_reporting.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub trait ErrorReporting {
112112

113113
fn values_str(&self, values: &ValuePairs) -> Option<String>;
114114

115-
fn expected_found_str<T: UserString + Resolvable>(
115+
fn expected_found_str<T: UserString + Resolvable + HasRemainingTypeVariables>(
116116
&self,
117117
exp_found: &ty::expected_found<T>)
118118
-> Option<String>;
@@ -402,7 +402,7 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> {
402402
}
403403
}
404404

405-
fn expected_found_str<T: UserString + Resolvable>(
405+
fn expected_found_str<T: UserString + Resolvable + HasRemainingTypeVariables>(
406406
&self,
407407
exp_found: &ty::expected_found<T>)
408408
-> Option<String>
@@ -1656,16 +1656,13 @@ impl<'a, 'tcx> ErrorReportingHelpers for InferCtxt<'a, 'tcx> {
16561656
pub trait Resolvable {
16571657
fn resolve(&self, infcx: &InferCtxt) -> Self;
16581658
fn contains_error(&self) -> bool;
1659+
}
1660+
1661+
pub trait HasRemainingTypeVariables {
16591662
fn remaining_type_variables(&self, tcx: &ty::ctxt) -> HashSet<ty::InferTy>;
16601663
}
16611664

1662-
impl Resolvable for ty::t {
1663-
fn resolve(&self, infcx: &InferCtxt) -> ty::t {
1664-
infcx.resolve_type_vars_if_possible(*self)
1665-
}
1666-
fn contains_error(&self) -> bool {
1667-
ty::type_is_error(*self)
1668-
}
1665+
impl<T: TypeFoldable> HasRemainingTypeVariables for T {
16691666
fn remaining_type_variables(&self, tcx: &ty::ctxt) -> HashSet<ty::InferTy> {
16701667
let mut vars = HashSet::new();
16711668
{
@@ -1684,16 +1681,22 @@ impl Resolvable for ty::t {
16841681
}
16851682
}
16861683

1684+
impl Resolvable for ty::t {
1685+
fn resolve(&self, infcx: &InferCtxt) -> ty::t {
1686+
infcx.resolve_type_vars_if_possible(*self)
1687+
}
1688+
fn contains_error(&self) -> bool {
1689+
ty::type_is_error(*self)
1690+
}
1691+
}
1692+
16871693
impl Resolvable for Rc<ty::TraitRef> {
16881694
fn resolve(&self, infcx: &InferCtxt) -> Rc<ty::TraitRef> {
16891695
Rc::new(infcx.resolve_type_vars_in_trait_ref_if_possible(&**self))
16901696
}
16911697
fn contains_error(&self) -> bool {
16921698
ty::trait_ref_contains_error(&**self)
16931699
}
1694-
fn remaining_type_variables(&self, _: &ty::ctxt) -> HashSet<ty::InferTy> {
1695-
HashSet::new()
1696-
}
16971700
}
16981701

16991702
fn lifetimes_in_scope(tcx: &ty::ctxt,

src/librustc/util/ppaux.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,9 @@ pub fn ty_to_string_with_var_ids(cx: &ctxt, typ: t, mut print_var_ids: bool) ->
383383

384384
fn infer_ty_to_string(ty: ty::InferTy, print_var_ids: bool) -> String {
385385
match ty {
386-
ty::TyVar(ty::TyVid { index: vid })
387-
| ty::IntVar(ty::IntVid { index: vid })
388-
| ty::FloatVar(ty::FloatVid { index: vid }) => {
386+
ty::TyVar(ty::TyVid { index: vid }) |
387+
ty::IntVar(ty::IntVid { index: vid }) |
388+
ty::FloatVar(ty::FloatVid { index: vid }) => {
389389
match ty {
390390
ty::TyVar(_) if print_var_ids => format!("_#{}", vid),
391391
ty::TyVar(_) => "_".to_string(),

0 commit comments

Comments
 (0)