]> git.lizzy.rs Git - rust.git/blob - src/test/ui/impl-trait/equality-rpass.rs
:arrow_up: rust-analyzer
[rust.git] / src / test / ui / impl-trait / equality-rpass.rs
1 // run-pass
2
3 #![feature(specialization)] //~ WARN the feature `specialization` is incomplete
4
5 trait Foo: std::fmt::Debug + Eq {}
6
7 impl<T: std::fmt::Debug + Eq> Foo for T {}
8
9 fn hide<T: Foo>(x: T) -> impl Foo {
10     x
11 }
12
13 trait Leak<T>: Sized {
14     fn leak(self) -> T;
15 }
16 impl<T, U> Leak<T> for U {
17     default fn leak(self) -> T { panic!("type mismatch") }
18 }
19 impl<T> Leak<T> for T {
20     fn leak(self) -> T { self }
21 }
22
23 trait CheckIfSend: Sized {
24     type T: Default;
25     fn check(self) -> Self::T { Default::default() }
26 }
27 impl<T> CheckIfSend for T {
28     default type T = ();
29 }
30 impl<T: Send> CheckIfSend for T {
31     type T = bool;
32 }
33
34 fn lucky_seven() -> impl Fn(usize) -> u8 {
35     let a = [1, 2, 3, 4, 5, 6, 7];
36     move |i| a[i]
37 }
38
39 fn main() {
40     assert_eq!(hide(42), hide(42));
41
42     assert_eq!(std::mem::size_of_val(&hide([0_u8; 5])), 5);
43     assert_eq!(std::mem::size_of_val(&lucky_seven()), 7);
44
45     assert_eq!(Leak::<i32>::leak(hide(5_i32)), 5_i32);
46
47     assert_eq!(CheckIfSend::check(hide(0_i32)), false);
48 }