|
| 1 | +// compile-pass |
| 2 | + |
| 3 | +use std::pin::Pin; |
| 4 | +use std::task::{Context, Poll}; |
| 5 | + |
| 6 | +struct Foo; |
| 7 | + |
| 8 | +impl 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 | + |
| 20 | +type Alias<T> = Pin<T>; |
| 21 | +impl Foo { |
| 22 | + fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> &() { arg } |
| 23 | +} |
| 24 | + |
| 25 | +struct Bar<T: Unpin, U: Unpin> { |
| 26 | + field1: T, |
| 27 | + field2: U, |
| 28 | +} |
| 29 | + |
| 30 | +impl<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 | + |
| 37 | +trait AsyncBufRead { |
| 38 | + fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) |
| 39 | + -> Poll<std::io::Result<&[u8]>>; |
| 40 | +} |
| 41 | + |
| 42 | +struct Baz(Vec<u8>); |
| 43 | + |
| 44 | +impl 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 | + |
| 52 | +fn 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 | +} |
0 commit comments