]> git.proxmox.com Git - rustc.git/blob - src/test/ui/traits/alias/bounds.rs
New upstream version 1.52.0~beta.3+dfsg1
[rustc.git] / src / test / ui / traits / alias / bounds.rs
1 // run-pass
2
3 #![feature(trait_alias)]
4
5 use std::marker::PhantomData;
6
7 trait Empty {}
8 trait EmptyAlias = Empty;
9 trait CloneDefault = Clone + Default;
10 trait SendSyncAlias = Send + Sync;
11 trait WhereSendAlias = where Self: Send;
12 trait SendEqAlias<T> = Send where T: PartialEq<Self>;
13 trait I32Iterator = Iterator<Item = i32>;
14
15 #[allow(dead_code)]
16 struct Foo<T: SendSyncAlias>(PhantomData<T>);
17 #[allow(dead_code)]
18 struct Bar<T>(PhantomData<T>) where T: SendSyncAlias;
19
20 impl dyn EmptyAlias {}
21
22 impl<T: SendSyncAlias> Empty for T {}
23
24 fn a<T: CloneDefault>() -> (T, T) {
25 let one = T::default();
26 let two = one.clone();
27 (one, two)
28 }
29
30 fn b(x: &impl SendEqAlias<i32>) -> bool {
31 22_i32 == *x
32 }
33
34 fn c<T: I32Iterator>(x: &mut T) -> Option<i32> {
35 x.next()
36 }
37
38 fn d<T: SendSyncAlias>() {
39 is_send_and_sync::<T>();
40 }
41
42 fn is_send_and_sync<T: Send + Sync>() {}
43
44 fn main() {
45 let both = a::<i32>();
46 assert_eq!(both.0, 0);
47 assert_eq!(both.1, 0);
48 let both: (i32, i32) = a();
49 assert_eq!(both.0, 0);
50 assert_eq!(both.1, 0);
51
52 assert!(b(&22));
53
54 assert_eq!(c(&mut vec![22].into_iter()), Some(22));
55
56 d::<i32>();
57 }