]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/traits/trait-alias-bounds.rs
Fixed bug with Self type param coming before lifetimes.
[rust.git] / src / test / run-pass / traits / trait-alias-bounds.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(trait_alias)]
12
13 use std::marker::PhantomData;
14
15 trait Empty {}
16 trait EmptyAlias = Empty;
17 trait CloneDefault = Clone + Default;
18 trait SendSyncAlias = Send + Sync;
19 trait WhereSendAlias = where Self: Send;
20 trait SendEqAlias<T> = Send where T: PartialEq<Self>;
21 trait I32Iterator = Iterator<Item = i32>;
22
23 #[allow(dead_code)]
24 struct Foo<T: SendSyncAlias>(PhantomData<T>);
25 #[allow(dead_code)]
26 struct Bar<T>(PhantomData<T>) where T: SendSyncAlias;
27
28 impl EmptyAlias {}
29
30 impl<T: SendSyncAlias> Empty for T {}
31
32 fn a<T: CloneDefault>() -> (T, T) {
33     let one = T::default();
34     let two = one.clone();
35     (one, two)
36 }
37
38 fn b(x: &impl SendEqAlias<i32>) -> bool {
39     22_i32 == *x
40 }
41
42 fn c<T: I32Iterator>(x: &mut T) -> Option<i32> {
43     x.next()
44 }
45
46 fn d<T: SendSyncAlias>() {
47     is_send_and_sync::<T>();
48 }
49
50 fn is_send_and_sync<T: Send + Sync>() {}
51
52 fn main() {
53     let both = a::<i32>();
54     assert_eq!(both.0, 0);
55     assert_eq!(both.1, 0);
56     let both: (i32, i32) = a();
57     assert_eq!(both.0, 0);
58     assert_eq!(both.1, 0);
59
60     assert!(b(&22));
61
62     assert_eq!(c(&mut vec![22].into_iter()), Some(22));
63
64     d::<i32>();
65 }