Skip to content

Commit 7cd6692

Browse files
committed
Fix merge fallout of privacy changes
1 parent 2c76cda commit 7cd6692

File tree

13 files changed

+74
-14
lines changed

13 files changed

+74
-14
lines changed

doc/rust.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,8 @@ pub mod submodule {
16241624
}
16251625
}
16261626
}
1627+
1628+
# fn main() {}
16271629
~~~
16281630

16291631
For a rust program to pass the privacy checking pass, all paths must be valid
@@ -1643,6 +1645,8 @@ pub use api = self::implementation;
16431645
mod implementation {
16441646
pub fn f() {}
16451647
}
1648+
1649+
# fn main() {}
16461650
~~~
16471651

16481652
This means that any external crate referencing `implementation::f` would receive

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,7 @@ fn encode_info_for_mod(ecx: &EncodeContext,
623623
}
624624

625625
encode_path(ecx, ebml_w, path, ast_map::path_mod(name));
626+
encode_visibility(ebml_w, vis);
626627

627628
// Encode the reexports of this module, if this module is public.
628629
if vis == public {

src/librustc/middle/privacy.rs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,40 @@ impl<'self> Visitor<()> for ParentVisitor<'self> {
6464
}
6565
}
6666
}
67+
68+
// Trait methods are always considered "public", but if the trait is
69+
// private then we need some private item in the chain from the
70+
// method to the root. In this case, if the trait is private, then
71+
// parent all the methods to the trait to indicate that they're
72+
// private.
73+
ast::item_trait(_, _, ref methods) if item.vis != ast::public => {
74+
for m in methods.iter() {
75+
match *m {
76+
ast::provided(ref m) => self.parents.insert(m.id, item.id),
77+
ast::required(ref m) => self.parents.insert(m.id, item.id),
78+
};
79+
}
80+
}
81+
6782
_ => {}
6883
}
6984
visit::walk_item(self, item, ());
7085
self.curparent = prev;
7186
}
7287

73-
fn visit_trait_method(&mut self, m: &ast::trait_method, _: ()) {
74-
match *m {
75-
ast::provided(ref m) => self.parents.insert(m.id, self.curparent),
76-
ast::required(ref m) => self.parents.insert(m.id, self.curparent),
77-
};
78-
visit::walk_trait_method(self, m, ());
79-
}
80-
8188
fn visit_foreign_item(&mut self, a: @ast::foreign_item, _: ()) {
8289
self.parents.insert(a.id, self.curparent);
8390
visit::walk_foreign_item(self, a, ());
8491
}
8592

8693
fn visit_fn(&mut self, a: &visit::fn_kind, b: &ast::fn_decl,
8794
c: &ast::Block, d: Span, id: ast::NodeId, _: ()) {
88-
self.parents.insert(id, self.curparent);
95+
// We already took care of some trait methods above, otherwise things
96+
// like impl methods and pub trait methods are parented to the
97+
// containing module, not the containing trait.
98+
if !self.parents.contains_key(&id) {
99+
self.parents.insert(id, self.curparent);
100+
}
89101
visit::walk_fn(self, a, b, c, d, id, ());
90102
}
91103

src/librustc/middle/resolve.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,7 +1649,15 @@ impl Resolver {
16491649
external crate) building external def, priv {:?}",
16501650
vis);
16511651
let is_public = vis == ast::public;
1652-
if is_public {
1652+
let is_exported = is_public && match new_parent {
1653+
ModuleReducedGraphParent(module) => {
1654+
match module.def_id {
1655+
None => true,
1656+
Some(did) => self.external_exports.contains(&did)
1657+
}
1658+
}
1659+
};
1660+
if is_exported {
16531661
self.external_exports.insert(def_id_of_def(def));
16541662
}
16551663
match def {
@@ -1725,7 +1733,7 @@ impl Resolver {
17251733
if explicit_self != sty_static {
17261734
interned_method_names.insert(method_name.name);
17271735
}
1728-
if is_public {
1736+
if is_exported {
17291737
self.external_exports.insert(method_def_id);
17301738
}
17311739
}
@@ -1952,7 +1960,7 @@ impl Resolver {
19521960
/// Builds the reduced graph rooted at the 'use' directive for an external
19531961
/// crate.
19541962
fn build_reduced_graph_for_external_crate(&mut self,
1955-
root: @mut Module) {
1963+
root: @mut Module) {
19561964
do csearch::each_top_level_item_of_crate(self.session.cstore,
19571965
root.def_id.unwrap().crate)
19581966
|def_like, ident, visibility| {

src/librustc/middle/trans/context.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use lib::llvm::{llvm, TargetData, TypeNames};
1616
use lib::llvm::mk_target_data;
1717
use metadata::common::LinkMeta;
1818
use middle::astencode;
19-
use middle::privacy;
2019
use middle::resolve;
2120
use middle::trans::adt;
2221
use middle::trans::base;

src/libstd/task/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ fn test_try_fail() {
10691069
10701070
#[cfg(test)]
10711071
fn get_sched_id() -> int {
1072-
do Local::borrow |sched: &mut ::rt::sched::Scheduler| {
1072+
do Local::borrow |sched: &mut ::rt::shouldnt_be_public::Scheduler| {
10731073
sched.sched_id() as int
10741074
}
10751075
}

src/test/compile-fail/glob-resolve1.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
// Make sure that globs only bring in public things.
1212

13+
#[feature(globs)];
14+
1315
use bar::*;
1416

1517
mod bar {

src/test/compile-fail/issue-4366-2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#[feature(globs)];
1112

1213
// ensures that 'use foo:*' doesn't import non-public item
1314

src/test/compile-fail/privacy1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#[feature(globs)];
1112
#[no_std]; // makes debugging this test *a lot* easier (during resolve)
1213

1314
mod bar {

src/test/compile-fail/privacy2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#[feature(globs)];
1112
#[no_std]; // makes debugging this test *a lot* easier (during resolve)
1213

1314
// Test to make sure that globs don't leak in regular `use` statements.

src/test/compile-fail/privacy3.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#[feature(globs)];
1112
#[no_std]; // makes debugging this test *a lot* easier (during resolve)
1213

1314
// Test to make sure that private items imported through globs remain private

src/test/compile-fail/privacy4.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#[feature(globs)];
1112
#[no_std]; // makes debugging this test *a lot* easier (during resolve)
1213

1314
// Test to make sure that private items imported through globs remain private

src/test/run-pass/privacy1.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub mod test2 {
12+
// This used to generate an ICE (make sure that default functions are
13+
// parented to their trait to find the first private thing as the trait).
14+
15+
struct B;
16+
trait A { fn foo(&self) {} }
17+
impl A for B {}
18+
19+
mod tests {
20+
use super::A;
21+
fn foo() {
22+
let a = super::B;
23+
a.foo();
24+
}
25+
}
26+
}
27+
28+
29+
pub fn main() {}

0 commit comments

Comments
 (0)