Skip to content

Commit 2f451a7

Browse files
committed
rustc: Only allow imports marked with "pub" to be imported from other modules
1 parent 8a5545e commit 2f451a7

File tree

5 files changed

+29
-13
lines changed

5 files changed

+29
-13
lines changed

src/libcore/gc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ with destructors.
2929
#[forbid(deprecated_mode)];
3030
#[forbid(deprecated_pattern)];
3131

32-
use stackwalk::Word;
32+
pub use stackwalk::Word;
3333
use libc::size_t;
3434
use libc::uintptr_t;
3535
use send_map::linear::LinearMap;

src/libcore/os.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
use libc::{c_char, c_void, c_int, c_uint, size_t, ssize_t,
2424
mode_t, pid_t, FILE};
25-
use libc::{close, fclose};
25+
pub use libc::{close, fclose};
2626

2727
use option::{Some, None};
2828

@@ -225,7 +225,7 @@ mod global_env {
225225
pub fn setenv(n: &str, v: &str) {
226226
do str::as_c_str(n) |nbuf| {
227227
do str::as_c_str(v) |vbuf| {
228-
libc::setenv(nbuf, vbuf, 1i32);
228+
libc::funcs::posix01::unistd::setenv(nbuf, vbuf, 1i32);
229229
}
230230
}
231231
}
@@ -384,8 +384,8 @@ pub fn self_exe_path() -> Option<Path> {
384384
#[cfg(target_os = "macos")]
385385
fn load_self() -> Option<~str> {
386386
do fill_charp_buf() |buf, sz| {
387-
libc::_NSGetExecutablePath(buf, ptr::mut_addr_of(&(sz as u32)))
388-
== (0 as c_int)
387+
libc::funcs::extra::_NSGetExecutablePath(
388+
buf, ptr::mut_addr_of(&(sz as u32))) == (0 as c_int)
389389
}
390390
}
391391

src/libcore/repr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use cast::transmute;
1313
use intrinsic::{TyDesc, TyVisitor, visit_tydesc};
1414
use reflect::{MovePtr, MovePtrAdaptor};
1515
use vec::raw::{VecRepr, UnboxedVecRepr, SliceRepr};
16-
use box::raw::{BoxRepr, BoxHeaderRepr};
16+
pub use box::raw::BoxRepr;
17+
use box::raw::BoxHeaderRepr;
1718

1819
/// Helpers
1920

src/libsyntax/parse/parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3511,8 +3511,8 @@ impl parser {
35113511
self.token_is_keyword(~"mod", next_tok))
35123512
}
35133513

3514-
fn parse_view_item(+attrs: ~[attribute]) -> @view_item {
3515-
let lo = self.span.lo, vis = self.parse_visibility();
3514+
fn parse_view_item(+attrs: ~[attribute], vis: visibility) -> @view_item {
3515+
let lo = self.span.lo;
35163516
let node = if self.eat_keyword(~"use") {
35173517
self.parse_use()
35183518
} else if self.eat_keyword(~"export") {
@@ -3644,7 +3644,7 @@ impl parser {
36443644
_ => self.unexpected()
36453645
}
36463646
} else if self.is_view_item() {
3647-
let vi = self.parse_view_item(outer_attrs);
3647+
let vi = self.parse_view_item(outer_attrs, vis);
36483648
return spanned(lo, vi.span.hi, cdir_view_item(vi));
36493649
}
36503650
return self.fatal(~"expected crate directive");

src/rustc/middle/resolve.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ struct ImportResolution {
367367
mut used: bool,
368368
}
369369

370-
fn ImportResolution(privacy: Privacy,
371-
span: span) -> ImportResolution {
370+
fn ImportResolution(privacy: Privacy, span: span) -> ImportResolution {
372371
ImportResolution {
373372
privacy: privacy,
374373
span: span,
@@ -1639,11 +1638,20 @@ impl Resolver {
16391638

16401639
match *subclass {
16411640
SingleImport(target, _, _) => {
1641+
debug!("(building import directive) building import \
1642+
directive: privacy %? %s::%s",
1643+
privacy,
1644+
self.idents_to_str(module_path.get()),
1645+
self.session.str_of(target));
1646+
16421647
match module_.import_resolutions.find(target) {
16431648
Some(resolution) => {
1649+
debug!("(building import directive) bumping \
1650+
reference");
16441651
resolution.outstanding_references += 1u;
16451652
}
16461653
None => {
1654+
debug!("(building import directive) creating new");
16471655
let resolution = @ImportResolution(privacy, span);
16481656
resolution.outstanding_references = 1u;
16491657
module_.import_resolutions.insert(target, resolution);
@@ -1967,6 +1975,12 @@ impl Resolver {
19671975
namespace: Namespace)
19681976
-> NamespaceResult {
19691977

1978+
// Import resolutions must be declared with "pub"
1979+
// in order to be exported.
1980+
if import_resolution.privacy == Private {
1981+
return UnboundResult;
1982+
}
1983+
19701984
match (*import_resolution).
19711985
target_for_namespace(namespace) {
19721986
None => {
@@ -4229,7 +4243,8 @@ impl Resolver {
42294243
42304244
// Next, search import resolutions.
42314245
match containing_module.import_resolutions.find(name) {
4232-
Some(import_resolution) => {
4246+
Some(import_resolution) if import_resolution.privacy == Public ||
4247+
xray == Xray => {
42334248
match (*import_resolution).target_for_namespace(namespace) {
42344249
Some(target) => {
42354250
match (*target.bindings)
@@ -4252,7 +4267,7 @@ impl Resolver {
42524267
}
42534268
}
42544269
}
4255-
None => {
4270+
Some(_) | None => {
42564271
return NoNameDefinition;
42574272
}
42584273
}

0 commit comments

Comments
 (0)