]> git.lizzy.rs Git - rust.git/blob - src/test/ui/self/arbitrary_self_types_stdlib_pointers.rs
Update ui tests
[rust.git] / src / test / ui / self / arbitrary_self_types_stdlib_pointers.rs
1 // run-pass
2 #![feature(arbitrary_self_types)]
3 #![feature(rustc_attrs)]
4
5 use std::{
6     rc::Rc,
7     sync::Arc,
8     pin::Pin,
9 };
10
11 trait Trait {
12     fn by_rc(self: Rc<Self>) -> i64;
13     fn by_arc(self: Arc<Self>) -> i64;
14     fn by_pin_mut(self: Pin<&mut Self>) -> i64;
15     fn by_pin_box(self: Pin<Box<Self>>) -> i64;
16     fn by_pin_pin_pin_ref(self: Pin<Pin<Pin<&Self>>>) -> i64;
17 }
18
19 impl Trait for i64 {
20     fn by_rc(self: Rc<Self>) -> i64 {
21         *self
22     }
23     fn by_arc(self: Arc<Self>) -> i64 {
24         *self
25     }
26     fn by_pin_mut(self: Pin<&mut Self>) -> i64 {
27         *self
28     }
29     fn by_pin_box(self: Pin<Box<Self>>) -> i64 {
30         *self
31     }
32     fn by_pin_pin_pin_ref(self: Pin<Pin<Pin<&Self>>>) -> i64 {
33         *self
34     }
35 }
36
37 fn main() {
38     let rc = Rc::new(1i64) as Rc<dyn Trait>;
39     assert_eq!(1, rc.by_rc());
40
41     let arc = Arc::new(2i64) as Arc<dyn Trait>;
42     assert_eq!(2, arc.by_arc());
43
44     let mut value = 3i64;
45     let pin_mut = Pin::new(&mut value) as Pin<&mut dyn Trait>;
46     assert_eq!(3, pin_mut.by_pin_mut());
47
48     let pin_box = Into::<Pin<Box<i64>>>::into(Box::new(4i64)) as Pin<Box<dyn Trait>>;
49     assert_eq!(4, pin_box.by_pin_box());
50
51     let value = 5i64;
52     let pin_pin_pin_ref = Pin::new(Pin::new(Pin::new(&value))) as Pin<Pin<Pin<&dyn Trait>>>;
53     assert_eq!(5, pin_pin_pin_ref.by_pin_pin_pin_ref());
54 }