rustc: Only allow imports marked with "pub" to be imported from other modules
This commit is contained in:
parent
8a5545e9cd
commit
2f451a7bd7
|
@ -29,7 +29,7 @@ with destructors.
|
||||||
#[forbid(deprecated_mode)];
|
#[forbid(deprecated_mode)];
|
||||||
#[forbid(deprecated_pattern)];
|
#[forbid(deprecated_pattern)];
|
||||||
|
|
||||||
use stackwalk::Word;
|
pub use stackwalk::Word;
|
||||||
use libc::size_t;
|
use libc::size_t;
|
||||||
use libc::uintptr_t;
|
use libc::uintptr_t;
|
||||||
use send_map::linear::LinearMap;
|
use send_map::linear::LinearMap;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
use libc::{c_char, c_void, c_int, c_uint, size_t, ssize_t,
|
use libc::{c_char, c_void, c_int, c_uint, size_t, ssize_t,
|
||||||
mode_t, pid_t, FILE};
|
mode_t, pid_t, FILE};
|
||||||
use libc::{close, fclose};
|
pub use libc::{close, fclose};
|
||||||
|
|
||||||
use option::{Some, None};
|
use option::{Some, None};
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ mod global_env {
|
||||||
pub fn setenv(n: &str, v: &str) {
|
pub fn setenv(n: &str, v: &str) {
|
||||||
do str::as_c_str(n) |nbuf| {
|
do str::as_c_str(n) |nbuf| {
|
||||||
do str::as_c_str(v) |vbuf| {
|
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")]
|
#[cfg(target_os = "macos")]
|
||||||
fn load_self() -> Option<~str> {
|
fn load_self() -> Option<~str> {
|
||||||
do fill_charp_buf() |buf, sz| {
|
do fill_charp_buf() |buf, sz| {
|
||||||
libc::_NSGetExecutablePath(buf, ptr::mut_addr_of(&(sz as u32)))
|
libc::funcs::extra::_NSGetExecutablePath(
|
||||||
== (0 as c_int)
|
buf, ptr::mut_addr_of(&(sz as u32))) == (0 as c_int)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,8 @@ use cast::transmute;
|
||||||
use intrinsic::{TyDesc, TyVisitor, visit_tydesc};
|
use intrinsic::{TyDesc, TyVisitor, visit_tydesc};
|
||||||
use reflect::{MovePtr, MovePtrAdaptor};
|
use reflect::{MovePtr, MovePtrAdaptor};
|
||||||
use vec::raw::{VecRepr, UnboxedVecRepr, SliceRepr};
|
use vec::raw::{VecRepr, UnboxedVecRepr, SliceRepr};
|
||||||
use box::raw::{BoxRepr, BoxHeaderRepr};
|
pub use box::raw::BoxRepr;
|
||||||
|
use box::raw::BoxHeaderRepr;
|
||||||
|
|
||||||
/// Helpers
|
/// Helpers
|
||||||
|
|
||||||
|
|
|
@ -3511,8 +3511,8 @@ impl parser {
|
||||||
self.token_is_keyword(~"mod", next_tok))
|
self.token_is_keyword(~"mod", next_tok))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_view_item(+attrs: ~[attribute]) -> @view_item {
|
fn parse_view_item(+attrs: ~[attribute], vis: visibility) -> @view_item {
|
||||||
let lo = self.span.lo, vis = self.parse_visibility();
|
let lo = self.span.lo;
|
||||||
let node = if self.eat_keyword(~"use") {
|
let node = if self.eat_keyword(~"use") {
|
||||||
self.parse_use()
|
self.parse_use()
|
||||||
} else if self.eat_keyword(~"export") {
|
} else if self.eat_keyword(~"export") {
|
||||||
|
@ -3644,7 +3644,7 @@ impl parser {
|
||||||
_ => self.unexpected()
|
_ => self.unexpected()
|
||||||
}
|
}
|
||||||
} else if self.is_view_item() {
|
} 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 spanned(lo, vi.span.hi, cdir_view_item(vi));
|
||||||
}
|
}
|
||||||
return self.fatal(~"expected crate directive");
|
return self.fatal(~"expected crate directive");
|
||||||
|
|
|
@ -367,8 +367,7 @@ struct ImportResolution {
|
||||||
mut used: bool,
|
mut used: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ImportResolution(privacy: Privacy,
|
fn ImportResolution(privacy: Privacy, span: span) -> ImportResolution {
|
||||||
span: span) -> ImportResolution {
|
|
||||||
ImportResolution {
|
ImportResolution {
|
||||||
privacy: privacy,
|
privacy: privacy,
|
||||||
span: span,
|
span: span,
|
||||||
|
@ -1639,11 +1638,20 @@ impl Resolver {
|
||||||
|
|
||||||
match *subclass {
|
match *subclass {
|
||||||
SingleImport(target, _, _) => {
|
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) {
|
match module_.import_resolutions.find(target) {
|
||||||
Some(resolution) => {
|
Some(resolution) => {
|
||||||
|
debug!("(building import directive) bumping \
|
||||||
|
reference");
|
||||||
resolution.outstanding_references += 1u;
|
resolution.outstanding_references += 1u;
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
|
debug!("(building import directive) creating new");
|
||||||
let resolution = @ImportResolution(privacy, span);
|
let resolution = @ImportResolution(privacy, span);
|
||||||
resolution.outstanding_references = 1u;
|
resolution.outstanding_references = 1u;
|
||||||
module_.import_resolutions.insert(target, resolution);
|
module_.import_resolutions.insert(target, resolution);
|
||||||
|
@ -1967,6 +1975,12 @@ impl Resolver {
|
||||||
namespace: Namespace)
|
namespace: Namespace)
|
||||||
-> NamespaceResult {
|
-> NamespaceResult {
|
||||||
|
|
||||||
|
// Import resolutions must be declared with "pub"
|
||||||
|
// in order to be exported.
|
||||||
|
if import_resolution.privacy == Private {
|
||||||
|
return UnboundResult;
|
||||||
|
}
|
||||||
|
|
||||||
match (*import_resolution).
|
match (*import_resolution).
|
||||||
target_for_namespace(namespace) {
|
target_for_namespace(namespace) {
|
||||||
None => {
|
None => {
|
||||||
|
@ -4229,7 +4243,8 @@ impl Resolver {
|
||||||
|
|
||||||
// Next, search import resolutions.
|
// Next, search import resolutions.
|
||||||
match containing_module.import_resolutions.find(name) {
|
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) {
|
match (*import_resolution).target_for_namespace(namespace) {
|
||||||
Some(target) => {
|
Some(target) => {
|
||||||
match (*target.bindings)
|
match (*target.bindings)
|
||||||
|
@ -4252,7 +4267,7 @@ impl Resolver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
Some(_) | None => {
|
||||||
return NoNameDefinition;
|
return NoNameDefinition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue