]> git.lizzy.rs Git - rust.git/blob - tests/ui/generics/generic-type-params-name-repr.rs
Rollup merge of #107389 - zvavybir:master, r=estebank
[rust.git] / tests / ui / generics / generic-type-params-name-repr.rs
1 use std::marker;
2
3 struct A;
4 struct B;
5 struct C;
6 struct Foo<T = A, U = B, V = C>(marker::PhantomData<(T,U,V)>);
7
8 struct Hash<T>(marker::PhantomData<T>);
9 struct HashMap<K, V, H = Hash<K>>(marker::PhantomData<(K,V,H)>);
10
11 fn main() {
12     // Ensure that the printed type doesn't include the default type params...
13     let _: Foo<isize> = ();
14     //~^ ERROR mismatched types
15     //~| expected `Foo<isize>`, found `()`
16     //~| expected struct `Foo<isize>`
17     //~| found unit type `()`
18
19     // ...even when they're present, but the same types as the defaults.
20     let _: Foo<isize, B, C> = ();
21     //~^ ERROR mismatched types
22     //~| expected `Foo<isize>`, found `()`
23     //~| expected struct `Foo<isize>`
24     //~| found unit type `()`
25
26     // Including cases where the default is using previous type params.
27     let _: HashMap<String, isize> = ();
28     //~^ ERROR mismatched types
29     //~| expected `HashMap<String, isize>`, found `()`
30     //~| expected struct `HashMap<String, isize>`
31     //~| found unit type `()`
32     let _: HashMap<String, isize, Hash<String>> = ();
33     //~^ ERROR mismatched types
34     //~| expected `HashMap<String, isize>`, found `()`
35     //~| expected struct `HashMap<String, isize>`
36     //~| found unit type `()`
37
38     // But not when there's a different type in between.
39     let _: Foo<A, isize, C> = ();
40     //~^ ERROR mismatched types
41     //~| expected `Foo<A, isize>`, found `()`
42     //~| expected struct `Foo<A, isize>`
43     //~| found unit type `()`
44
45     // And don't print <> at all when there's just defaults.
46     let _: Foo<A, B, C> = ();
47     //~^ ERROR mismatched types
48     //~| expected `Foo`, found `()`
49     //~| expected struct `Foo`
50     //~| found unit type `()`
51 }