Skip to content

Commit 0a89592

Browse files
committed
---
yaml --- r: 36673 b: refs/heads/try2 c: d42bdf1 h: refs/heads/master i: 36671: 141f922 v: v3
1 parent 34cdabb commit 0a89592

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: a7159be24a9c81517a46e09c7ff62cadc72759b6
8+
refs/heads/try2: d42bdf1997ebaeb8a893947df563ff07d039cf08
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try2/src/librustc/middle/privacy.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
199199
visit_expr: |expr, method_map: &method_map, visitor| {
200200
match expr.node {
201201
expr_field(base, ident, _) => {
202-
match ty::get(ty::expr_ty(tcx, base)).sty {
202+
// With type_autoderef, make sure we don't
203+
// allow pointers to violate privacy
204+
match ty::get(ty::type_autoderef(tcx, ty::expr_ty(tcx,
205+
base))).sty {
203206
ty_struct(id, _)
204207
if id.crate != local_crate ||
205208
!privileged_items.contains(&(id.node)) => {
@@ -220,7 +223,9 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
220223
}
221224
}
222225
expr_method_call(base, _, _, _, _) => {
223-
match ty::get(ty::expr_ty(tcx, base)).sty {
226+
// Ditto
227+
match ty::get(ty::type_autoderef(tcx, ty::expr_ty(tcx,
228+
base))).sty {
224229
ty_struct(id, _)
225230
if id.crate != local_crate ||
226231
!privileged_items.contains(&(id.node)) => {

branches/try2/src/test/compile-fail/issue-3763.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,25 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// xfail-test
1211
mod my_mod {
1312
pub struct MyStruct {
1413
priv priv_field: int
1514
}
1615
pub fn MyStruct () -> MyStruct {
1716
MyStruct {priv_field: 4}
1817
}
18+
impl MyStruct {
19+
priv fn happyfun() {}
20+
}
1921
}
2022

2123
fn main() {
2224
let my_struct = my_mod::MyStruct();
23-
let _woohoo = (&my_struct).priv_field; // compiles but shouldn't
24-
let _woohoo = (~my_struct).priv_field; // ditto
25-
let _woohoo = (@my_struct).priv_field; // ditto
26-
// let nope = my_struct.priv_field; // compile error as expected
25+
let _woohoo = (&my_struct).priv_field; //~ ERROR field `priv_field` is private
26+
let _woohoo = (~my_struct).priv_field; //~ ERROR field `priv_field` is private
27+
let _woohoo = (@my_struct).priv_field; //~ ERROR field `priv_field` is private
28+
(&my_struct).happyfun(); //~ ERROR method `happyfun` is private
29+
(~my_struct).happyfun(); //~ ERROR method `happyfun` is private
30+
(@my_struct).happyfun(); //~ ERROR method `happyfun` is private
31+
let nope = my_struct.priv_field; //~ ERROR field `priv_field` is private
2732
}

0 commit comments

Comments
 (0)