-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lints
Description
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);
}
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>
.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lints
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
glandium commentedon Jul 11, 2018
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 thatPrintContext::parameterized
has.