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