]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/arbitrary_self_types_stdlib_pointers.rs
Add new tests and update existing for object-safe custom receivers
[rust.git] / src / test / run-pass / arbitrary_self_types_stdlib_pointers.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(arbitrary_self_types)]
12 #![feature(pin)]
13 #![feature(rustc_attrs)]
14
15 use std::{
16     rc::Rc,
17     sync::Arc,
18     pin::Pin,
19 };
20
21 trait Trait {
22     fn by_rc(self: Rc<Self>) -> i64;
23     fn by_arc(self: Arc<Self>) -> i64;
24     fn by_pin_mut(self: Pin<&mut Self>) -> i64;
25     fn by_pin_box(self: Pin<Box<Self>>) -> i64;
26 }
27
28 impl Trait for i64 {
29     fn by_rc(self: Rc<Self>) -> i64 {
30         *self
31     }
32     fn by_arc(self: Arc<Self>) -> i64 {
33         *self
34     }
35     fn by_pin_mut(self: Pin<&mut Self>) -> i64 {
36         *self
37     }
38     fn by_pin_box(self: Pin<Box<Self>>) -> i64 {
39         *self
40     }
41 }
42
43 fn main() {
44     let rc = Rc::new(1i64) as Rc<dyn Trait>;
45     assert_eq!(1, rc.by_rc());
46
47     let arc = Arc::new(2i64) as Arc<dyn Trait>;
48     assert_eq!(2, arc.by_arc());
49
50     let mut value = 3i64;
51     let pin_mut = Pin::new(&mut value) as Pin<&mut dyn Trait>;
52     assert_eq!(3, pin_mut.by_pin_mut());
53
54     let pin_box = Into::<Pin<Box<i64>>>::into(Box::new(4i64)) as Pin<Box<dyn Trait>>;
55     assert_eq!(4, pin_box.by_pin_box());
56 }