rustc: Only allow imports marked with "pub" to be imported from other modules

This commit is contained in:
Patrick Walton 2012-10-02 18:13:56 -07:00
parent 8a5545e9cd
commit 2f451a7bd7
5 changed files with 29 additions and 13 deletions

View File

@ -29,7 +29,7 @@ with destructors.
#[forbid(deprecated_mode)];
#[forbid(deprecated_pattern)];
use stackwalk::Word;
pub use stackwalk::Word;
use libc::size_t;
use libc::uintptr_t;
use send_map::linear::LinearMap;

View File

@ -22,7 +22,7 @@
use libc::{c_char, c_void, c_int, c_uint, size_t, ssize_t,
mode_t, pid_t, FILE};
use libc::{close, fclose};
pub use libc::{close, fclose};
use option::{Some, None};
@ -225,7 +225,7 @@ mod global_env {
pub fn setenv(n: &str, v: &str) {
do str::as_c_str(n) |nbuf| {
do str::as_c_str(v) |vbuf| {
libc::setenv(nbuf, vbuf, 1i32);
libc::funcs::posix01::unistd::setenv(nbuf, vbuf, 1i32);
}
}
}
@ -384,8 +384,8 @@ pub fn self_exe_path() -> Option<Path> {
#[cfg(target_os = "macos")]
fn load_self() -> Option<~str> {
do fill_charp_buf() |buf, sz| {
libc::_NSGetExecutablePath(buf, ptr::mut_addr_of(&(sz as u32)))
== (0 as c_int)
libc::funcs::extra::_NSGetExecutablePath(
buf, ptr::mut_addr_of(&(sz as u32))) == (0 as c_int)
}
}

View File

@ -13,7 +13,8 @@ use cast::transmute;
use intrinsic::{TyDesc, TyVisitor, visit_tydesc};
use reflect::{MovePtr, MovePtrAdaptor};
use vec::raw::{VecRepr, UnboxedVecRepr, SliceRepr};
use box::raw::{BoxRepr, BoxHeaderRepr};
pub use box::raw::BoxRepr;
use box::raw::BoxHeaderRepr;
/// Helpers

View File

@ -3511,8 +3511,8 @@ impl parser {
self.token_is_keyword(~"mod", next_tok))
}
fn parse_view_item(+attrs: ~[attribute]) -> @view_item {
let lo = self.span.lo, vis = self.parse_visibility();
fn parse_view_item(+attrs: ~[attribute], vis: visibility) -> @view_item {
let lo = self.span.lo;
let node = if self.eat_keyword(~"use") {
self.parse_use()
} else if self.eat_keyword(~"export") {
@ -3644,7 +3644,7 @@ impl parser {
_ => self.unexpected()
}
} else if self.is_view_item() {
let vi = self.parse_view_item(outer_attrs);
let vi = self.parse_view_item(outer_attrs, vis);
return spanned(lo, vi.span.hi, cdir_view_item(vi));
}
return self.fatal(~"expected crate directive");

View File

@ -367,8 +367,7 @@ struct ImportResolution {
mut used: bool,
}
fn ImportResolution(privacy: Privacy,
span: span) -> ImportResolution {
fn ImportResolution(privacy: Privacy, span: span) -> ImportResolution {
ImportResolution {
privacy: privacy,
span: span,
@ -1639,11 +1638,20 @@ impl Resolver {
match *subclass {
SingleImport(target, _, _) => {
debug!("(building import directive) building import \
directive: privacy %? %s::%s",
privacy,
self.idents_to_str(module_path.get()),
self.session.str_of(target));
match module_.import_resolutions.find(target) {
Some(resolution) => {
debug!("(building import directive) bumping \
reference");
resolution.outstanding_references += 1u;
}
None => {
debug!("(building import directive) creating new");
let resolution = @ImportResolution(privacy, span);
resolution.outstanding_references = 1u;
module_.import_resolutions.insert(target, resolution);
@ -1967,6 +1975,12 @@ impl Resolver {
namespace: Namespace)
-> NamespaceResult {
// Import resolutions must be declared with "pub"
// in order to be exported.
if import_resolution.privacy == Private {
return UnboundResult;
}
match (*import_resolution).
target_for_namespace(namespace) {
None => {
@ -4229,7 +4243,8 @@ impl Resolver {
// Next, search import resolutions.
match containing_module.import_resolutions.find(name) {
Some(import_resolution) => {
Some(import_resolution) if import_resolution.privacy == Public ||
xray == Xray => {
match (*import_resolution).target_for_namespace(namespace) {
Some(target) => {
match (*target.bindings)
@ -4252,7 +4267,7 @@ impl Resolver {
}
}
}
None => {
Some(_) | None => {
return NoNameDefinition;
}
}