1 // Copyright 2014 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.
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.
13 struct DerefWrapper<X, Y> {
18 impl<X, Y> DerefWrapper<X, Y> {
24 impl<X, Y> Deref<Y> for DerefWrapper<X, Y> {
25 fn deref<'a>(&'a self) -> &'a Y {
31 pub struct DerefWrapperHideX<X, Y> {
36 impl<X, Y> DerefWrapperHideX<X, Y> {
37 pub fn new(x: X, y: Y) -> DerefWrapperHideX<X, Y> {
45 impl<X, Y> Deref<Y> for DerefWrapperHideX<X, Y> {
46 fn deref<'a>(&'a self) -> &'a Y {
53 let nested = DerefWrapper {x: true, y: DerefWrapper {x: 0i, y: 1i}};
55 // Use the first field that you can find.
56 assert_eq!(nested.x, true);
57 assert_eq!((*nested).x, 0);
59 // Same for methods, even though there are multiple
60 // candidates (at different nesting levels).
61 assert_eq!(nested.get_x(), true);
62 assert_eq!((*nested).get_x(), 0);
64 // Also go through multiple levels of indirection.
65 assert_eq!(Rc::new(nested).x, true);
67 let nested_priv = priv_test::DerefWrapperHideX::new(true, DerefWrapper {x: 0i, y: 1i});
68 // FIXME(eddyb) #12808 should skip private fields.
69 // assert_eq!(nested_priv.x, 0);
70 assert_eq!((*nested_priv).x, 0);