2014-09-23 23:07:21 +00:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2015-03-22 20:13:15 +00:00
|
|
|
// pretty-expanded FIXME #23616
|
|
|
|
|
2014-12-22 17:04:23 +00:00
|
|
|
use std::ops::{Deref, DerefMut};
|
|
|
|
|
2014-09-23 23:07:21 +00:00
|
|
|
// Generic unique/owned smaht pointer.
|
|
|
|
struct Own<T> {
|
|
|
|
value: *mut T
|
|
|
|
}
|
|
|
|
|
2015-01-01 19:53:20 +00:00
|
|
|
impl<T> Deref for Own<T> {
|
|
|
|
type Target = T;
|
|
|
|
|
2014-09-23 23:07:21 +00:00
|
|
|
fn deref<'a>(&'a self) -> &'a T {
|
|
|
|
unsafe { &*self.value }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-01 19:53:20 +00:00
|
|
|
impl<T> DerefMut for Own<T> {
|
2014-09-23 23:07:21 +00:00
|
|
|
fn deref_mut<'a>(&'a mut self) -> &'a mut T {
|
|
|
|
unsafe { &mut *self.value }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Point {
|
|
|
|
x: int,
|
|
|
|
y: int
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Point {
|
|
|
|
fn get(&mut self) -> (int, int) {
|
|
|
|
(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() {}
|