Auto-deref when checking field and method privacy

This disallows using pointers to sneak around priv qualifiers.

Deeming this too small for review as well. Closes #3763
This commit is contained in:
Tim Chevalier 2012-12-11 19:15:12 -08:00
parent a7159be24a
commit d42bdf1997
2 changed files with 17 additions and 7 deletions

View file

@ -199,7 +199,10 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
visit_expr: |expr, method_map: &method_map, visitor| {
match expr.node {
expr_field(base, ident, _) => {
match ty::get(ty::expr_ty(tcx, base)).sty {
// With type_autoderef, make sure we don't
// allow pointers to violate privacy
match ty::get(ty::type_autoderef(tcx, ty::expr_ty(tcx,
base))).sty {
ty_struct(id, _)
if id.crate != local_crate ||
!privileged_items.contains(&(id.node)) => {
@ -220,7 +223,9 @@ fn check_crate(tcx: ty::ctxt, method_map: &method_map, crate: @ast::crate) {
}
}
expr_method_call(base, _, _, _, _) => {
match ty::get(ty::expr_ty(tcx, base)).sty {
// Ditto
match ty::get(ty::type_autoderef(tcx, ty::expr_ty(tcx,
base))).sty {
ty_struct(id, _)
if id.crate != local_crate ||
!privileged_items.contains(&(id.node)) => {