From 2e7ec80bcce454d55d31c6bd335bb2ad64a7298e Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 18 Mar 2013 17:20:45 -0700 Subject: librustc: Enforce privacy for static methods. This starts moving a bunch of privacy checks into the privacy checking phase and out of resolve. --- src/libsyntax/ast_map.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 5266d1b049a..9371055556e 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -87,7 +87,7 @@ pub fn path_elt_to_str(pe: path_elt, itr: @ident_interner) -> ~str { pub enum ast_node { node_item(@item, @path), - node_foreign_item(@foreign_item, foreign_abi, @path), + node_foreign_item(@foreign_item, foreign_abi, visibility, @path), node_trait_method(@trait_method, def_id /* trait did */, @path /* path to the trait */), node_method(@method, def_id /* impl did */, @path /* path to the impl */), @@ -170,7 +170,9 @@ pub fn map_decoded_item(diag: @span_handler, match ii { ii_item(*) | ii_dtor(*) => { /* fallthrough */ } ii_foreign(i) => { - cx.map.insert(i.id, node_foreign_item(i, foreign_abi_rust_intrinsic, + cx.map.insert(i.id, node_foreign_item(i, + foreign_abi_rust_intrinsic, + i.vis, // Wrong but OK @path)); } ii_method(impl_did, m) => { @@ -277,10 +279,18 @@ pub fn map_item(i: @item, &&cx: @mut Ctx, v: visit::vt<@mut Ctx>) { Right(abi) => abi }; for nm.items.each |nitem| { + // Compute the visibility for this native item. + let visibility = match nitem.vis { + public => public, + private => private, + inherited => i.vis + }; + cx.map.insert(nitem.id, node_foreign_item( *nitem, abi, + visibility, // FIXME (#2543) if nm.sort == ast::named { extend(cx, i.ident) @@ -380,7 +390,7 @@ pub fn node_id_to_str(map: map, id: node_id, itr: @ident_interner) -> ~str { }; fmt!("%s %s (id=%?)", item_str, path_str, id) } - Some(node_foreign_item(item, abi, path)) => { + Some(node_foreign_item(item, abi, _, path)) => { fmt!("foreign item %s with abi %? (id=%?)", path_ident_to_str(*path, item.ident, itr), abi, id) } -- cgit 1.4.1-3-g733a5