mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 19:58:32 +00:00
Improve tests
This commit is contained in:
parent
38bef43652
commit
48c20b0e73
@ -25,9 +25,10 @@ mod inner {
|
|||||||
pub a: isize,
|
pub a: isize,
|
||||||
b: isize,
|
b: isize,
|
||||||
}
|
}
|
||||||
|
pub struct Z(pub isize, isize);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test(a: A, b: inner::A, c: inner::B, d: xc::A, e: xc::B) {
|
fn test(a: A, b: inner::A, c: inner::B, d: xc::A, e: xc::B, z: inner::Z) {
|
||||||
a.a;
|
a.a;
|
||||||
b.a; //~ ERROR: field `a` of struct `inner::A` is private
|
b.a; //~ ERROR: field `a` of struct `inner::A` is private
|
||||||
b.b;
|
b.b;
|
||||||
@ -39,6 +40,9 @@ fn test(a: A, b: inner::A, c: inner::B, d: xc::A, e: xc::B) {
|
|||||||
|
|
||||||
e.a;
|
e.a;
|
||||||
e.b; //~ ERROR: field `b` of struct `xc::B` is private
|
e.b; //~ ERROR: field `b` of struct `xc::B` is private
|
||||||
|
|
||||||
|
z.0;
|
||||||
|
z.1; //~ ERROR: field `1` of struct `inner::Z` is private
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
@ -10,40 +10,51 @@
|
|||||||
|
|
||||||
// Check we do not select a private method or field when computing autoderefs
|
// Check we do not select a private method or field when computing autoderefs
|
||||||
|
|
||||||
#![feature(rustc_attrs)]
|
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct Bar2 { i: i32 }
|
pub struct Bar2 { i: i32 }
|
||||||
|
#[derive(Default)]
|
||||||
pub struct Baz2(i32);
|
pub struct Baz2(i32);
|
||||||
|
|
||||||
impl Bar2 {
|
impl Bar2 {
|
||||||
fn f(&self) {}
|
fn f(&self) -> bool { true }
|
||||||
}
|
}
|
||||||
|
|
||||||
mod foo {
|
mod foo {
|
||||||
pub struct Bar { i: i32 }
|
#[derive(Default)]
|
||||||
pub struct Baz(i32);
|
pub struct Bar { i: ::Bar2 }
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct Baz(::Baz2);
|
||||||
|
|
||||||
impl Bar {
|
impl Bar {
|
||||||
fn f(&self) {}
|
fn f(&self) -> bool { false }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::std::ops::Deref for Bar {
|
impl ::std::ops::Deref for Bar {
|
||||||
type Target = ::Bar2;
|
type Target = ::Bar2;
|
||||||
fn deref(&self) -> &::Bar2 { unimplemented!() }
|
fn deref(&self) -> &::Bar2 { &self.i }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::std::ops::Deref for Baz {
|
impl ::std::ops::Deref for Baz {
|
||||||
type Target = ::Baz2;
|
type Target = ::Baz2;
|
||||||
fn deref(&self) -> &::Baz2 { unimplemented!() }
|
fn deref(&self) -> &::Baz2 { &self.0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn f(bar: foo::Bar, baz: foo::Baz) {
|
fn main() {
|
||||||
let _ = bar.i;
|
let bar = foo::Bar::default();
|
||||||
let _ = baz.0;
|
let baz = foo::Baz::default();
|
||||||
let _ = bar.f();
|
foo::f(&bar, &baz);
|
||||||
}
|
|
||||||
|
|
||||||
#[rustc_error]
|
let _: i32 = bar.i;
|
||||||
fn main() {} //~ ERROR compilation successful
|
let _: i32 = baz.0;
|
||||||
|
assert!(bar.f());
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user