Skip to content

Commit ce60f93

Browse files
committed
---
yaml --- r: 271879 b: refs/heads/master c: 48c20b0 h: refs/heads/master i: 271877: a0dd87d 271875: f904ebf 271871: 7356c63
1 parent 852adad commit ce60f93

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 38bef4365219dba7b82a3de19a2b84b1d322abf1
2+
refs/heads/master: 48c20b0e73b083090c6dcf65ecd460eb073cc0b4
33
refs/heads/snap-stage3: 235d77457d80b549dad3ac36d94f235208a1eafb
44
refs/heads/try: 49312a405e14a449b98fe0056b12a40ac128be4a
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

trunk/src/test/compile-fail/struct-field-privacy.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ mod inner {
2525
pub a: isize,
2626
b: isize,
2727
}
28+
pub struct Z(pub isize, isize);
2829
}
2930

30-
fn test(a: A, b: inner::A, c: inner::B, d: xc::A, e: xc::B) {
31+
fn test(a: A, b: inner::A, c: inner::B, d: xc::A, e: xc::B, z: inner::Z) {
3132
a.a;
3233
b.a; //~ ERROR: field `a` of struct `inner::A` is private
3334
b.b;
@@ -39,6 +40,9 @@ fn test(a: A, b: inner::A, c: inner::B, d: xc::A, e: xc::B) {
3940

4041
e.a;
4142
e.b; //~ ERROR: field `b` of struct `xc::B` is private
43+
44+
z.0;
45+
z.1; //~ ERROR: field `1` of struct `inner::Z` is private
4246
}
4347

4448
fn main() {}

trunk/src/test/compile-fail/autoderef-privacy.rs renamed to trunk/src/test/run-pass/autoderef-privacy.rs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,51 @@
1010

1111
// Check we do not select a private method or field when computing autoderefs
1212

13-
#![feature(rustc_attrs)]
1413
#![allow(unused)]
1514

15+
#[derive(Default)]
1616
pub struct Bar2 { i: i32 }
17+
#[derive(Default)]
1718
pub struct Baz2(i32);
1819

1920
impl Bar2 {
20-
fn f(&self) {}
21+
fn f(&self) -> bool { true }
2122
}
2223

2324
mod foo {
24-
pub struct Bar { i: i32 }
25-
pub struct Baz(i32);
25+
#[derive(Default)]
26+
pub struct Bar { i: ::Bar2 }
27+
#[derive(Default)]
28+
pub struct Baz(::Baz2);
2629

2730
impl Bar {
28-
fn f(&self) {}
31+
fn f(&self) -> bool { false }
2932
}
3033

3134
impl ::std::ops::Deref for Bar {
3235
type Target = ::Bar2;
33-
fn deref(&self) -> &::Bar2 { unimplemented!() }
36+
fn deref(&self) -> &::Bar2 { &self.i }
3437
}
3538

3639
impl ::std::ops::Deref for Baz {
3740
type Target = ::Baz2;
38-
fn deref(&self) -> &::Baz2 { unimplemented!() }
41+
fn deref(&self) -> &::Baz2 { &self.0 }
3942
}
40-
}
4143

42-
fn f(bar: foo::Bar, baz: foo::Baz) {
43-
let _ = bar.i;
44-
let _ = baz.0;
45-
let _ = bar.f();
44+
pub fn f(bar: &Bar, baz: &Baz) {
45+
// Since the private fields and methods are visible here, there should be no autoderefs.
46+
let _: &::Bar2 = &bar.i;
47+
let _: &::Baz2 = &baz.0;
48+
assert!(!bar.f());
49+
}
4650
}
4751

48-
#[rustc_error]
49-
fn main() {} //~ ERROR compilation successful
52+
fn main() {
53+
let bar = foo::Bar::default();
54+
let baz = foo::Baz::default();
55+
foo::f(&bar, &baz);
56+
57+
let _: i32 = bar.i;
58+
let _: i32 = baz.0;
59+
assert!(bar.f());
60+
}

0 commit comments

Comments
 (0)