2019-07-26 16:54:25 -05:00
|
|
|
// run-pass
|
|
|
|
|
2018-09-14 05:20:28 -05:00
|
|
|
#![allow(dead_code)]
|
2015-03-22 15:13:15 -05:00
|
|
|
// pretty-expanded FIXME #23616
|
|
|
|
|
2014-12-22 11:04:23 -06:00
|
|
|
use std::ops::{Deref, DerefMut};
|
|
|
|
|
2014-09-23 18:07:21 -05:00
|
|
|
// Generic unique/owned smaht pointer.
|
|
|
|
struct Own<T> {
|
|
|
|
value: *mut T
|
|
|
|
}
|
|
|
|
|
2015-01-01 13:53:20 -06:00
|
|
|
impl<T> Deref for Own<T> {
|
|
|
|
type Target = T;
|
|
|
|
|
2014-09-23 18:07:21 -05:00
|
|
|
fn deref<'a>(&'a self) -> &'a T {
|
|
|
|
unsafe { &*self.value }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-01 13:53:20 -06:00
|
|
|
impl<T> DerefMut for Own<T> {
|
2014-09-23 18:07:21 -05:00
|
|
|
fn deref_mut<'a>(&'a mut self) -> &'a mut T {
|
|
|
|
unsafe { &mut *self.value }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Point {
|
2015-03-25 19:06:52 -05:00
|
|
|
x: isize,
|
|
|
|
y: isize
|
2014-09-23 18:07:21 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Point {
|
2015-03-25 19:06:52 -05:00
|
|
|
fn get(&mut self) -> (isize, isize) {
|
2014-09-23 18:07:21 -05:00
|
|
|
(self.x, self.y)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test0(mut x: Own<Point>) {
|
|
|
|
let _ = x.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test1(mut x: Own<Own<Own<Point>>>) {
|
|
|
|
let _ = x.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test2(mut x: Own<Own<Own<Point>>>) {
|
|
|
|
let _ = (**x).get();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|