]> git.proxmox.com Git - rustc.git/blame - src/test/ui/self/arbitrary_self_types_pin_lifetime.rs
New upstream version 1.67.1+dfsg1
[rustc.git] / src / test / ui / self / arbitrary_self_types_pin_lifetime.rs
CommitLineData
dc9dc135 1// check-pass
48663c56
XL
2
3use std::pin::Pin;
4use std::task::{Context, Poll};
5
6struct Foo;
7
8impl Foo {
9 fn pin_ref(self: Pin<&Self>) -> Pin<&Self> { self }
10
11 fn pin_mut(self: Pin<&mut Self>) -> Pin<&mut Self> { self }
12
13 fn pin_pin_pin_ref(self: Pin<Pin<Pin<&Self>>>) -> Pin<Pin<Pin<&Self>>> { self }
14
15 fn pin_ref_impl_trait(self: Pin<&Self>) -> impl Clone + '_ { self }
16
17 fn b(self: Pin<&Foo>, f: &Foo) -> Pin<&Foo> { self }
18}
19
20type Alias<T> = Pin<T>;
21impl Foo {
22 fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> Alias<&Self> { self }
23}
24
25struct Bar<T: Unpin, U: Unpin> {
26 field1: T,
27 field2: U,
28}
29
30impl<T: Unpin, U: Unpin> Bar<T, U> {
31 fn fields(self: Pin<&mut Self>) -> (Pin<&mut T>, Pin<&mut U>) {
32 let this = self.get_mut();
33 (Pin::new(&mut this.field1), Pin::new(&mut this.field2))
34 }
35}
36
37trait AsyncBufRead {
38 fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>)
39 -> Poll<std::io::Result<&[u8]>>;
40}
41
42struct Baz(Vec<u8>);
43
44impl AsyncBufRead for Baz {
45 fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>)
46 -> Poll<std::io::Result<&[u8]>>
47 {
48 Poll::Ready(Ok(&self.get_mut().0))
49 }
50}
51
52fn main() {
53 let mut foo = Foo;
54 { Pin::new(&foo).pin_ref() };
55 { Pin::new(&mut foo).pin_mut() };
56 { Pin::new(Pin::new(Pin::new(&foo))).pin_pin_pin_ref() };
57 { Pin::new(&foo).pin_ref_impl_trait() };
58 let mut bar = Bar { field1: 0u8, field2: 1u8 };
59 { Pin::new(&mut bar).fields() };
60}