about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2012-10-02 18:13:56 -0700
committerPatrick Walton <pcwalton@mimiga.net>2012-10-02 18:15:19 -0700
commit2f451a7bd7d856daad1e487f7bc7a14c40840c2d (patch)
tree939578793823dcef8262a839d5dc3992a513b02f
parent8a5545e9cd3f9fa82e8003c2e71eee595492ad64 (diff)
downloadrust-2f451a7bd7d856daad1e487f7bc7a14c40840c2d.tar.gz
rust-2f451a7bd7d856daad1e487f7bc7a14c40840c2d.zip
rustc: Only allow imports marked with "pub" to be imported from other modules
-rw-r--r--src/libcore/gc.rs2
-rw-r--r--src/libcore/os.rs8
-rw-r--r--src/libcore/repr.rs3
-rw-r--r--src/libsyntax/parse/parser.rs6
-rw-r--r--src/rustc/middle/resolve.rs23
5 files changed, 29 insertions, 13 deletions
diff --git a/src/libcore/gc.rs b/src/libcore/gc.rs
index de2e4412812..464600b9469 100644
--- a/src/libcore/gc.rs
+++ b/src/libcore/gc.rs
@@ -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;
diff --git a/src/libcore/os.rs b/src/libcore/os.rs
index 1ffb27aaa36..d37bdabd48a 100644
--- a/src/libcore/os.rs
+++ b/src/libcore/os.rs
@@ -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)
         }
     }
 
diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs
index 30b43dd7f84..ff82ed3fb41 100644
--- a/src/libcore/repr.rs
+++ b/src/libcore/repr.rs
@@ -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
 
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index d81bd09f37a..8860d1b5cea 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -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");
diff --git a/src/rustc/middle/resolve.rs b/src/rustc/middle/resolve.rs
index fc66b5dc7a1..eca0687f2fd 100644
--- a/src/rustc/middle/resolve.rs
+++ b/src/rustc/middle/resolve.rs
@@ -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;
             }
         }