Skip to content

Commit 7e51198

Browse files
committed
---
yaml --- r: 40768 b: refs/heads/dist-snap c: d42bdf1 h: refs/heads/master v: v3
1 parent 993b40a commit 7e51198

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
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278
99
refs/heads/incoming: e90142e536c150df0d9b4b2f11352152177509b5
10-
refs/heads/dist-snap: a7159be24a9c81517a46e09c7ff62cadc72759b6
10+
refs/heads/dist-snap: d42bdf1997ebaeb8a893947df563ff07d039cf08
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/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/dist-snap/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)