Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error messages don't "simplify" types with default generic params in some cases #52097

Closed
glandium opened this issue Jul 6, 2018 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@glandium
Copy link
Contributor

glandium commented Jul 6, 2018

In #50882, adding an Alloc parameter to the Box type, that defaults to Global induces changes to UI tests that are indicative of something that seemed to need improvement in the compiler, namely that when you have a type Foo<A, B = Bar>, errors should present Foo<A> instead of Foo<A, Bar> when they can.

It turns out, the compiler does. But not consistently. The following is derived from src/test/compile-fail/terr-sorts.rs:

#![crate_type = "lib"]
trait Alloc {}
struct Global;
impl Alloc for Global {}

struct Foo<T, A: Alloc = Global>(T, A);

struct foo {
    a: isize,
    b: isize,
}

type bar = Foo<foo>;
type baz = Foo<usize>;

fn want_foo(f: foo) {}
fn have_bar(b: bar) {
    want_foo(b);
}
fn want_usize(f: usize) {}
fn have_baz(b: baz) {
    want_usize(b);
}

(Playground version)

This yields the following errors:

error[E0308]: mismatched types
  --> src/lib.rs:18:14
   |
18 |     want_foo(b);
   |              ^ expected struct `foo`, found struct `Foo`
   |
   = note: expected type `foo`
              found type `Foo<foo, Global>`

error[E0308]: mismatched types
  --> src/lib.rs:22:16
   |
22 |     want_usize(b);
   |                ^ expected usize, found struct `Foo`
   |
   = note: expected type `usize`
              found type `Foo<usize>`

See how it prints Foo<foo, Global> instead of the (imho) desired Foo<foo>, but Foo<usize>, not Foo<usize, Global>.

@varkor varkor added the A-diagnostics Area: Messages for errors, warnings, and lints label Jul 6, 2018
@glandium
Copy link
Contributor Author

This all stems from the fact that in some cases, types are just printed out by formatting the Ty<'ctx> instances, while in other cases, there is manual machinery to highlight parts of the type that handle things, and that doesn't have the default-param elimination that PrintContext::parameterized has.

@bors bors closed this as completed in b5c2b79 Jul 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

2 participants