summaryrefslogtreecommitdiffstats
path: root/tests/ui/self/arbitrary_self_types_stdlib_pointers.rs
blob: 29563fbbd867660929f19d2599431ba3babfb2fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// run-pass
#![feature(arbitrary_self_types)]
#![feature(rustc_attrs)]

use std::{
    rc::Rc,
    sync::Arc,
    pin::Pin,
};

trait Trait {
    fn by_rc(self: Rc<Self>) -> i64;
    fn by_arc(self: Arc<Self>) -> i64;
    fn by_pin_mut(self: Pin<&mut Self>) -> i64;
    fn by_pin_box(self: Pin<Box<Self>>) -> i64;
    fn by_pin_pin_pin_ref(self: Pin<Pin<Pin<&Self>>>) -> i64;
}

impl Trait for i64 {
    fn by_rc(self: Rc<Self>) -> i64 {
        *self
    }
    fn by_arc(self: Arc<Self>) -> i64 {
        *self
    }
    fn by_pin_mut(self: Pin<&mut Self>) -> i64 {
        *self
    }
    fn by_pin_box(self: Pin<Box<Self>>) -> i64 {
        *self
    }
    fn by_pin_pin_pin_ref(self: Pin<Pin<Pin<&Self>>>) -> i64 {
        *self
    }
}

fn main() {
    let rc = Rc::new(1i64) as Rc<dyn Trait>;
    assert_eq!(1, rc.by_rc());

    let arc = Arc::new(2i64) as Arc<dyn Trait>;
    assert_eq!(2, arc.by_arc());

    let mut value = 3i64;
    let pin_mut = Pin::new(&mut value) as Pin<&mut dyn Trait>;
    assert_eq!(3, pin_mut.by_pin_mut());

    let pin_box = Into::<Pin<Box<i64>>>::into(Box::new(4i64)) as Pin<Box<dyn Trait>>;
    assert_eq!(4, pin_box.by_pin_box());

    let value = 5i64;
    let pin_pin_pin_ref = Pin::new(Pin::new(Pin::new(&value))) as Pin<Pin<Pin<&dyn Trait>>>;
    assert_eq!(5, pin_pin_pin_ref.by_pin_pin_pin_ref());
}