2014-03-22 18:11:39 -05: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.
|
|
|
|
|
|
|
|
use std::ops::Deref;
|
|
|
|
|
|
|
|
struct DerefWithHelper<H, T> {
|
2014-03-28 13:09:31 -05:00
|
|
|
pub helper: H
|
2014-03-22 18:11:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
trait Helper<T> {
|
2014-07-17 23:44:59 -05:00
|
|
|
fn helper_borrow(&self) -> &T;
|
2014-03-22 18:11:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Helper<T> for Option<T> {
|
2014-07-17 23:44:59 -05:00
|
|
|
fn helper_borrow(&self) -> &T {
|
2014-03-22 18:11:39 -05:00
|
|
|
self.as_ref().unwrap()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T, H: Helper<T>> Deref<T> for DerefWithHelper<H, T> {
|
2014-07-17 23:44:59 -05:00
|
|
|
fn deref(&self) -> &T {
|
2014-03-22 18:11:39 -05:00
|
|
|
self.helper.helper_borrow()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test cross-crate autoderef + vtable.
|
2014-05-29 19:45:07 -05:00
|
|
|
pub fn check<T: PartialEq>(x: T, y: T) -> bool {
|
2014-03-22 18:11:39 -05:00
|
|
|
let d: DerefWithHelper<Option<T>, T> = DerefWithHelper { helper: Some(x) };
|
|
|
|
d.eq(&y)
|
|
|
|
}
|