]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-type-bounds/dyn-lcsit.rs
Merge commit '3e7c6dec244539970b593824334876f8b6ed0b18' into clippyup
[rust.git] / src / test / ui / associated-type-bounds / dyn-lcsit.rs
1 // run-pass
2
3 #![feature(associated_type_bounds)]
4 #![feature(impl_trait_in_bindings)]
5 //~^ WARNING `impl_trait_in_bindings` is incomplete
6 #![allow(non_upper_case_globals)]
7
8 use std::ops::Add;
9
10 trait Tr1 { type As1; fn mk(&self) -> Self::As1; }
11 trait Tr2<'a> { fn tr2(self) -> &'a Self; }
12
13 fn assert_copy<T: Copy>(x: T) { let _x = x; let _x = x; }
14 fn assert_static<T: 'static>(_: T) {}
15 fn assert_forall_tr2<T: for<'a> Tr2<'a>>(_: T) {}
16
17 #[derive(Copy, Clone)]
18 struct S1;
19 #[derive(Copy, Clone)]
20 struct S2;
21 impl Tr1 for S1 { type As1 = S2; fn mk(&self) -> Self::As1 { S2 } }
22
23 const cdef_et1: &dyn Tr1<As1: Copy> = &S1;
24 const sdef_et1: &dyn Tr1<As1: Copy> = &S1;
25 pub fn use_et1() { assert_copy(cdef_et1.mk()); assert_copy(sdef_et1.mk()); }
26
27 const cdef_et2: &(dyn Tr1<As1: 'static> + Sync) = &S1;
28 static sdef_et2: &(dyn Tr1<As1: 'static> + Sync) = &S1;
29 pub fn use_et2() { assert_static(cdef_et2.mk()); assert_static(sdef_et2.mk()); }
30
31 const cdef_et3: &dyn Tr1<As1: Clone + Iterator<Item: Add<u8, Output: Into<u8>>>> = {
32     struct A;
33     impl Tr1 for A {
34         type As1 = core::ops::Range<u8>;
35         fn mk(&self) -> Self::As1 { 0..10 }
36     };
37     &A
38 };
39 pub fn use_et3() {
40     let _0 = cdef_et3.mk().clone();
41     let mut s = 0u8;
42     for _1 in _0 {
43         let _2 = _1 + 1u8;
44         s += _2.into();
45     }
46     assert_eq!(s, (0..10).map(|x| x + 1).sum());
47 }
48
49 const cdef_et4: &(dyn Tr1<As1: for<'a> Tr2<'a>> + Sync) = {
50     #[derive(Copy, Clone)]
51     struct A;
52     impl Tr1 for A {
53         type As1 = A;
54         fn mk(&self) -> A { A }
55     }
56     impl<'a> Tr2<'a> for A {
57         fn tr2(self) -> &'a Self { &A }
58     }
59     &A
60 };
61 static sdef_et4: &(dyn Tr1<As1: for<'a> Tr2<'a>> + Sync) = cdef_et4;
62 pub fn use_et4() { assert_forall_tr2(cdef_et4.mk()); assert_forall_tr2(sdef_et4.mk()); }
63
64 fn main() {
65     let _ = use_et1();
66     let _ = use_et2();
67     let _ = use_et3();
68     let _ = use_et4();
69 }