Skip to content

Commit 3db13f4

Browse files
author
Jakub Bukaj
committed
Always drop var IDs from type variables modulo -Z verbose, per PR discussion
1 parent 1b79303 commit 3db13f4

File tree

11 files changed

+71
-101
lines changed

11 files changed

+71
-101
lines changed

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

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ time of error detection.
6262
use std::collections::HashSet;
6363
use middle::def;
6464
use middle::subst;
65-
use middle::ty_fold::{mod, TypeFoldable};
6665
use middle::ty;
6766
use middle::ty::{Region, ReFree};
6867
use middle::typeck::infer;
@@ -112,7 +111,7 @@ pub trait ErrorReporting {
112111

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

115-
fn expected_found_str<T: UserString + Resolvable + HasRemainingTypeVariables>(
114+
fn expected_found_str<T: UserString + Resolvable>(
116115
&self,
117116
exp_found: &ty::expected_found<T>)
118117
-> Option<String>;
@@ -402,7 +401,7 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> {
402401
}
403402
}
404403

405-
fn expected_found_str<T: UserString + Resolvable + HasRemainingTypeVariables>(
404+
fn expected_found_str<T: UserString + Resolvable>(
406405
&self,
407406
exp_found: &ty::expected_found<T>)
408407
-> Option<String>
@@ -417,14 +416,9 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> {
417416
return None;
418417
}
419418

420-
// Only include variable IDs in the diagnostics if there are at least two
421-
// present across both types/traits.
422-
let should_print_var_ids = expected.remaining_type_variables(self.tcx)
423-
.union(&found.remaining_type_variables(self.tcx)).count() > 1;
424-
425419
Some(format!("expected `{}`, found `{}`",
426-
expected.user_string_with_var_ids(self.tcx, should_print_var_ids),
427-
found.user_string_with_var_ids(self.tcx, should_print_var_ids)))
420+
expected.user_string(self.tcx),
421+
found.user_string(self.tcx)))
428422
}
429423

430424
fn report_param_bound_failure(&self,
@@ -1658,29 +1652,6 @@ pub trait Resolvable {
16581652
fn contains_error(&self) -> bool;
16591653
}
16601654

1661-
pub trait HasRemainingTypeVariables {
1662-
fn remaining_type_variables(&self, tcx: &ty::ctxt) -> HashSet<ty::InferTy>;
1663-
}
1664-
1665-
impl<T: TypeFoldable> HasRemainingTypeVariables for T {
1666-
fn remaining_type_variables(&self, tcx: &ty::ctxt) -> HashSet<ty::InferTy> {
1667-
let mut vars = HashSet::new();
1668-
{
1669-
let mut folder = ty_fold::BottomUpFolder {
1670-
tcx: tcx,
1671-
fldop: |t| {
1672-
if let ty::ty_infer(var) = ty::get(t).sty {
1673-
vars.insert(var);
1674-
}
1675-
t
1676-
}
1677-
};
1678-
self.fold_with(&mut folder);
1679-
}
1680-
vars
1681-
}
1682-
}
1683-
16841655
impl Resolvable for ty::t {
16851656
fn resolve(&self, infcx: &InferCtxt) -> ty::t {
16861657
infcx.resolve_type_vars_if_possible(*self)

src/librustc/util/ppaux.rs

Lines changed: 37 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ pub trait Repr {
4343
/// Produces a string suitable for showing to the user.
4444
pub trait UserString {
4545
fn user_string(&self, tcx: &ctxt) -> String;
46-
fn user_string_with_var_ids(&self, tcx: &ctxt, _: bool) -> String {
47-
self.user_string(tcx)
48-
}
4946
}
5047

5148
pub fn note_and_explain_region(cx: &ctxt,
@@ -231,14 +228,10 @@ pub fn mutability_to_string(m: ast::Mutability) -> String {
231228
}
232229
}
233230

234-
pub fn mt_to_string_with_var_ids(cx: &ctxt, m: &mt, print_var_ids: bool) -> String {
231+
pub fn mt_to_string(cx: &ctxt, m: &mt) -> String {
235232
format!("{}{}",
236233
mutability_to_string(m.mutbl),
237-
ty_to_string_with_var_ids(cx, m.ty, print_var_ids))
238-
}
239-
240-
pub fn mt_to_string(cx: &ctxt, m: &mt) -> String {
241-
mt_to_string_with_var_ids(cx, m, false)
234+
ty_to_string(cx, m.ty))
242235
}
243236

244237
pub fn trait_store_to_string(cx: &ctxt, s: ty::TraitStore) -> String {
@@ -265,17 +258,11 @@ pub fn trait_ref_to_string(cx: &ctxt, trait_ref: &ty::TraitRef) -> String {
265258
}
266259

267260
pub fn ty_to_string(cx: &ctxt, typ: t) -> String {
268-
ty_to_string_with_var_ids(cx, typ, true)
269-
}
270-
271-
pub fn ty_to_string_with_var_ids(cx: &ctxt, typ: t, mut print_var_ids: bool) -> String {
272-
print_var_ids = print_var_ids || cx.sess.verbose();
273261
fn bare_fn_to_string(cx: &ctxt,
274262
fn_style: ast::FnStyle,
275263
abi: abi::Abi,
276264
ident: Option<ast::Ident>,
277-
sig: &ty::FnSig,
278-
print_var_ids: bool)
265+
sig: &ty::FnSig)
279266
-> String {
280267
let mut s = String::new();
281268
match fn_style {
@@ -300,12 +287,12 @@ pub fn ty_to_string_with_var_ids(cx: &ctxt, typ: t, mut print_var_ids: bool) ->
300287
_ => { }
301288
}
302289

303-
push_sig_to_string(cx, &mut s, '(', ')', sig, "", print_var_ids);
290+
push_sig_to_string(cx, &mut s, '(', ')', sig, "");
304291

305292
s
306293
}
307294

308-
fn closure_to_string(cx: &ctxt, cty: &ty::ClosureTy, print_var_ids: bool) -> String {
295+
fn closure_to_string(cx: &ctxt, cty: &ty::ClosureTy) -> String {
309296
let mut s = String::new();
310297

311298
match cty.store {
@@ -330,15 +317,15 @@ pub fn ty_to_string_with_var_ids(cx: &ctxt, typ: t, mut print_var_ids: bool) ->
330317
assert_eq!(cty.onceness, ast::Once);
331318
s.push_str("proc");
332319
push_sig_to_string(cx, &mut s, '(', ')', &cty.sig,
333-
bounds_str.as_slice(), print_var_ids);
320+
bounds_str.as_slice());
334321
}
335322
ty::RegionTraitStore(..) => {
336323
match cty.onceness {
337324
ast::Many => {}
338325
ast::Once => s.push_str("once ")
339326
}
340327
push_sig_to_string(cx, &mut s, '|', '|', &cty.sig,
341-
bounds_str.as_slice(), print_var_ids);
328+
bounds_str.as_slice());
342329
}
343330
}
344331

@@ -350,12 +337,11 @@ pub fn ty_to_string_with_var_ids(cx: &ctxt, typ: t, mut print_var_ids: bool) ->
350337
bra: char,
351338
ket: char,
352339
sig: &ty::FnSig,
353-
bounds: &str,
354-
print_var_ids: bool) {
340+
bounds: &str) {
355341
s.push(bra);
356342
let strs = sig.inputs
357343
.iter()
358-
.map(|a| ty_to_string_with_var_ids(cx, *a, print_var_ids))
344+
.map(|a| ty_to_string(cx, *a))
359345
.collect::<Vec<_>>();
360346
s.push_str(strs.connect(", ").as_slice());
361347
if sig.variadic {
@@ -372,7 +358,7 @@ pub fn ty_to_string_with_var_ids(cx: &ctxt, typ: t, mut print_var_ids: bool) ->
372358
ty::FnConverging(t) => {
373359
if !ty::type_is_nil(t) {
374360
s.push_str(" -> ");
375-
s.push_str(ty_to_string_with_var_ids(cx, t, print_var_ids).as_slice());
361+
s.push_str(ty_to_string(cx, t).as_slice());
376362
}
377363
}
378364
ty::FnDiverging => {
@@ -381,21 +367,20 @@ pub fn ty_to_string_with_var_ids(cx: &ctxt, typ: t, mut print_var_ids: bool) ->
381367
}
382368
}
383369

384-
fn infer_ty_to_string(ty: ty::InferTy, print_var_ids: bool) -> String {
370+
fn infer_ty_to_string(cx: &ctxt, ty: ty::InferTy) -> String {
371+
let print_var_ids = cx.sess.verbose();
385372
match ty {
386-
ty::TyVar(ty::TyVid { index: vid }) |
387-
ty::IntVar(ty::IntVid { index: vid }) |
388-
ty::FloatVar(ty::FloatVid { index: vid }) => {
389-
match ty {
390-
ty::TyVar(_) if print_var_ids => format!("_#{}", vid),
391-
ty::TyVar(_) => "_".to_string(),
392-
ty::IntVar(_) => format!("_#{}i", vid),
393-
ty::FloatVar(_) => format!("_#{}f", vid),
394-
_ => unreachable!()
395-
}
396-
}
373+
ty::TyVar(ty::TyVid { index: vid }) if print_var_ids =>
374+
format!("_#{}", vid),
375+
ty::IntVar(ty::IntVid { index: vid }) if print_var_ids =>
376+
format!("_#{}i", vid),
377+
ty::FloatVar(ty::FloatVid { index: vid }) if print_var_ids =>
378+
format!("_#{}f", vid),
379+
ty::TyVar(_) => "_".to_string(),
380+
ty::IntVar(_) => "_#i".to_string(),
381+
ty::FloatVar(_) => "_#f".to_string(),
397382
ty::SkolemizedTy(v) => format!("SkolemizedTy({})", v),
398-
ty::SkolemizedIntTy(v) => format!("SkolemizedIntTy({})", v),
383+
ty::SkolemizedIntTy(v) => format!("SkolemizedIntTy({})", v)
399384
}
400385
}
401386

@@ -407,7 +392,7 @@ pub fn ty_to_string_with_var_ids(cx: &ctxt, typ: t, mut print_var_ids: bool) ->
407392
ty_int(t) => ast_util::int_ty_to_string(t, None).to_string(),
408393
ty_uint(t) => ast_util::uint_ty_to_string(t, None).to_string(),
409394
ty_float(t) => ast_util::float_ty_to_string(t).to_string(),
410-
ty_uniq(typ) => format!("Box<{}>", ty_to_string_with_var_ids(cx, typ, print_var_ids)),
395+
ty_uniq(typ) => format!("Box<{}>", ty_to_string(cx, typ)),
411396
ty_ptr(ref tm) => {
412397
format!("*{} {}", match tm.mutbl {
413398
ast::MutMutable => "mut",
@@ -416,42 +401,42 @@ pub fn ty_to_string_with_var_ids(cx: &ctxt, typ: t, mut print_var_ids: bool) ->
416401
}
417402
ty_rptr(r, ref tm) => {
418403
let mut buf = region_ptr_to_string(cx, r);
419-
buf.push_str(mt_to_string_with_var_ids(cx, tm, print_var_ids).as_slice());
404+
buf.push_str(mt_to_string(cx, tm).as_slice());
420405
buf
421406
}
422407
ty_open(typ) =>
423-
format!("opened<{}>", ty_to_string_with_var_ids(cx, typ, print_var_ids)),
408+
format!("opened<{}>", ty_to_string(cx, typ)),
424409
ty_tup(ref elems) => {
425410
let strs = elems
426411
.iter()
427-
.map(|elem| ty_to_string_with_var_ids(cx, *elem, print_var_ids))
412+
.map(|elem| ty_to_string(cx, *elem))
428413
.collect::<Vec<_>>();
429414
match strs.as_slice() {
430415
[ref string] => format!("({},)", string),
431416
strs => format!("({})", strs.connect(", "))
432417
}
433418
}
434419
ty_closure(ref f) => {
435-
closure_to_string(cx, &**f, print_var_ids)
420+
closure_to_string(cx, &**f)
436421
}
437422
ty_bare_fn(ref f) => {
438-
bare_fn_to_string(cx, f.fn_style, f.abi, None, &f.sig, print_var_ids)
423+
bare_fn_to_string(cx, f.fn_style, f.abi, None, &f.sig)
439424
}
440-
ty_infer(infer_ty) => infer_ty_to_string(infer_ty, print_var_ids),
425+
ty_infer(infer_ty) => infer_ty_to_string(cx, infer_ty),
441426
ty_err => "[type error]".to_string(),
442427
ty_param(ref param_ty) => param_ty.repr(cx),
443428
ty_enum(did, ref substs) | ty_struct(did, ref substs) => {
444429
let base = ty::item_path_str(cx, did);
445430
let generics = ty::lookup_item_type(cx, did).generics;
446-
parameterized(cx, base.as_slice(), substs, &generics, print_var_ids)
431+
parameterized(cx, base.as_slice(), substs, &generics)
447432
}
448433
ty_trait(box ty::TyTrait {
449434
def_id: did, ref substs, ref bounds
450435
}) => {
451436
let base = ty::item_path_str(cx, did);
452437
let trait_def = ty::lookup_trait_def(cx, did);
453438
let ty = parameterized(cx, base.as_slice(),
454-
substs, &trait_def.generics, print_var_ids);
439+
substs, &trait_def.generics);
455440
let bound_str = bounds.user_string(cx);
456441
let bound_sep = if bound_str.is_empty() { "" } else { "+" };
457442
format!("{}{}{}",
@@ -463,11 +448,11 @@ pub fn ty_to_string_with_var_ids(cx: &ctxt, typ: t, mut print_var_ids: bool) ->
463448
ty_unboxed_closure(ref did, _, ref substs) => {
464449
let unboxed_closures = cx.unboxed_closures.borrow();
465450
unboxed_closures.find(did).map(|cl| {
466-
closure_to_string(cx, &cl.closure_type.subst(cx, substs), print_var_ids)
451+
closure_to_string(cx, &cl.closure_type.subst(cx, substs))
467452
}).unwrap_or_else(|| "closure".to_string())
468453
}
469454
ty_vec(t, sz) => {
470-
let inner_str = ty_to_string_with_var_ids(cx, t, print_var_ids);
455+
let inner_str = ty_to_string(cx, t);
471456
match sz {
472457
Some(n) => format!("[{}, ..{}]", inner_str, n),
473458
None => format!("[{}]", inner_str),
@@ -492,8 +477,7 @@ pub fn explicit_self_category_to_str(category: &ty::ExplicitSelfCategory)
492477
pub fn parameterized(cx: &ctxt,
493478
base: &str,
494479
substs: &subst::Substs,
495-
generics: &ty::Generics,
496-
print_var_ids: bool)
480+
generics: &ty::Generics)
497481
-> String
498482
{
499483
let mut strs = Vec::new();
@@ -532,7 +516,7 @@ pub fn parameterized(cx: &ctxt,
532516
};
533517

534518
for t in tps[..tps.len() - num_defaults].iter() {
535-
strs.push(ty_to_string_with_var_ids(cx, *t, print_var_ids))
519+
strs.push(ty_to_string(cx, *t))
536520
}
537521

538522
if cx.sess.verbose() {
@@ -743,7 +727,7 @@ impl Repr for ty::TraitRef {
743727
let trait_def = ty::lookup_trait_def(tcx, self.def_id);
744728
format!("<{} as {}>",
745729
self.substs.self_ty().repr(tcx),
746-
parameterized(tcx, base.as_slice(), &self.substs, &trait_def.generics, false))
730+
parameterized(tcx, base.as_slice(), &self.substs, &trait_def.generics))
747731
}
748732
}
749733

@@ -1128,22 +1112,16 @@ impl UserString for ty::BuiltinBounds {
11281112

11291113
impl UserString for ty::TraitRef {
11301114
fn user_string(&self, tcx: &ctxt) -> String {
1131-
self.user_string_with_var_ids(tcx, false)
1132-
}
1133-
fn user_string_with_var_ids(&self, tcx: &ctxt, print_var_ids: bool) -> String {
11341115
let base = ty::item_path_str(tcx, self.def_id);
11351116
let trait_def = ty::lookup_trait_def(tcx, self.def_id);
1136-
parameterized(tcx, base.as_slice(), &self.substs, &trait_def.generics, print_var_ids)
1117+
parameterized(tcx, base.as_slice(), &self.substs, &trait_def.generics)
11371118
}
11381119
}
11391120

11401121
impl UserString for ty::t {
11411122
fn user_string(&self, tcx: &ctxt) -> String {
11421123
ty_to_string(tcx, *self)
11431124
}
1144-
fn user_string_with_var_ids(&self, tcx: &ctxt, print_var_ids: bool) -> String {
1145-
ty_to_string_with_var_ids(tcx, *self, print_var_ids)
1146-
}
11471125
}
11481126

11491127
impl UserString for ast::Ident {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags:-Z verbose
12+
13+
fn main() {
14+
let x = [1,2];
15+
let y = match x {
16+
[] => None,
17+
//~^ ERROR types: expected `[_#0i, ..2]`, found `[_#7, ..0]`
18+
// (expected array of 2 elements, found array of 0 elements)
19+
[a,_] => Some(a)
20+
};
21+
}

src/test/compile-fail/issue-13482.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
let x = [1,2];
1313
let y = match x {
1414
[] => None,
15-
//~^ ERROR types: expected `[_#0i, ..2]`, found `[_#7, ..0]`
15+
//~^ ERROR types: expected `[_#i, ..2]`, found `[_, ..0]`
1616
// (expected array of 2 elements, found array of 0 elements)
1717
[a,_] => Some(a)
1818
};

src/test/compile-fail/issue-3680.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
fn main() {
1212
match None {
1313
Err(_) => ()
14-
//~^ ERROR mismatched types: expected `core::option::Option<_#1>`
15-
// , found `core::result::Result<_#2, _#3>`
14+
//~^ ERROR mismatched types: expected `core::option::Option<_>`
15+
// , found `core::result::Result<_, _>`
1616
}
1717
}

src/test/compile-fail/issue-4201.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
let a = if true {
1313
0
1414
} else if false {
15-
//~^ ERROR if may be missing an else clause: expected `()`, found `_#1i`
15+
//~^ ERROR if may be missing an else clause: expected `()`, found `_#i`
1616
1
1717
};
1818
}

src/test/compile-fail/issue-4968.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
const A: (int,int) = (4,2);
1414
fn main() {
1515
match 42 { A => () }
16-
//~^ ERROR mismatched types: expected `_#0i`, found `(int, int)`
16+
//~^ ERROR mismatched types: expected `_#i`, found `(int, int)`
1717
// (expected integral variable, found tuple)
1818
}

0 commit comments

Comments
 (0)