2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2016-02-26 12:58:45 -06:00
|
|
|
// Check we do not select a private method or field when computing autoderefs
|
|
|
|
|
|
|
|
#![allow(unused)]
|
|
|
|
|
2016-03-29 19:35:53 -05:00
|
|
|
#[derive(Default)]
|
2016-02-26 12:58:45 -06:00
|
|
|
pub struct Bar2 { i: i32 }
|
2016-03-29 19:35:53 -05:00
|
|
|
#[derive(Default)]
|
2016-02-26 12:58:45 -06:00
|
|
|
pub struct Baz2(i32);
|
|
|
|
|
|
|
|
impl Bar2 {
|
2016-03-29 19:35:53 -05:00
|
|
|
fn f(&self) -> bool { true }
|
2016-02-26 12:58:45 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
mod foo {
|
2016-03-29 19:35:53 -05:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct Bar { i: ::Bar2 }
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct Baz(::Baz2);
|
2016-02-26 12:58:45 -06:00
|
|
|
|
|
|
|
impl Bar {
|
2016-03-29 19:35:53 -05:00
|
|
|
fn f(&self) -> bool { false }
|
2016-02-26 12:58:45 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ::std::ops::Deref for Bar {
|
|
|
|
type Target = ::Bar2;
|
2016-03-29 19:35:53 -05:00
|
|
|
fn deref(&self) -> &::Bar2 { &self.i }
|
2016-02-26 12:58:45 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ::std::ops::Deref for Baz {
|
|
|
|
type Target = ::Baz2;
|
2016-03-29 19:35:53 -05:00
|
|
|
fn deref(&self) -> &::Baz2 { &self.0 }
|
2016-02-26 12:58:45 -06:00
|
|
|
}
|
|
|
|
|
2016-03-29 19:35:53 -05:00
|
|
|
pub fn f(bar: &Bar, baz: &Baz) {
|
|
|
|
// Since the private fields and methods are visible here, there should be no autoderefs.
|
|
|
|
let _: &::Bar2 = &bar.i;
|
|
|
|
let _: &::Baz2 = &baz.0;
|
|
|
|
assert!(!bar.f());
|
|
|
|
}
|
2016-02-26 12:58:45 -06:00
|
|
|
}
|
|
|
|
|
2016-03-29 19:35:53 -05:00
|
|
|
fn main() {
|
|
|
|
let bar = foo::Bar::default();
|
|
|
|
let baz = foo::Baz::default();
|
|
|
|
foo::f(&bar, &baz);
|
|
|
|
|
|
|
|
let _: i32 = bar.i;
|
|
|
|
let _: i32 = baz.0;
|
|
|
|
assert!(bar.f());
|
|
|
|
}
|