]> git.lizzy.rs Git - rust.git/blob - src/test/ui/impl-trait/equality2.rs
Rollup merge of #95504 - jyn514:library-alias, r=Mark-Simulacrum
[rust.git] / src / test / ui / impl-trait / equality2.rs
1 #![feature(specialization)] //~ WARN the feature `specialization` is incomplete
2
3 trait Foo: Copy + ToString {}
4
5 impl<T: Copy + ToString> Foo for T {}
6
7 fn hide<T: Foo>(x: T) -> impl Foo {
8     x
9 }
10
11 trait Leak: Sized {
12     type T;
13     fn leak(self) -> Self::T;
14 }
15 impl<T> Leak for T {
16     default type T = ();
17     default fn leak(self) -> Self::T { panic!() }
18 }
19 impl Leak for i32 {
20     type T = i32;
21     fn leak(self) -> i32 { self }
22 }
23
24 fn main() {
25     let _: u32 = hide(0_u32);
26     //~^ ERROR mismatched types
27     //~| expected type `u32`
28     //~| found opaque type `impl Foo`
29     //~| expected `u32`, found opaque type
30
31     let _: i32 = Leak::leak(hide(0_i32));
32     //~^ ERROR mismatched types
33     //~| expected type `i32`
34     //~| found associated type `<impl Foo as Leak>::T`
35     //~| expected `i32`, found associated type
36
37     let mut x = (hide(0_u32), hide(0_i32));
38     x = (x.1,
39     //~^ ERROR mismatched types
40     //~| expected `u32`, found `i32`
41          x.0);
42     //~^ ERROR mismatched types
43     //~| expected `i32`, found `u32`
44 }