Fix merge fallout of privacy changes
This commit is contained in:
parent
2c76cdae3e
commit
7cd6692425
13 changed files with 74 additions and 14 deletions
|
@ -1624,6 +1624,8 @@ pub mod submodule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# fn main() {}
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
For a rust program to pass the privacy checking pass, all paths must be valid
|
For a rust program to pass the privacy checking pass, all paths must be valid
|
||||||
|
@ -1643,6 +1645,8 @@ pub use api = self::implementation;
|
||||||
mod implementation {
|
mod implementation {
|
||||||
pub fn f() {}
|
pub fn f() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# fn main() {}
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
This means that any external crate referencing `implementation::f` would receive
|
This means that any external crate referencing `implementation::f` would receive
|
||||||
|
|
|
@ -623,6 +623,7 @@ fn encode_info_for_mod(ecx: &EncodeContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
encode_path(ecx, ebml_w, path, ast_map::path_mod(name));
|
encode_path(ecx, ebml_w, path, ast_map::path_mod(name));
|
||||||
|
encode_visibility(ebml_w, vis);
|
||||||
|
|
||||||
// Encode the reexports of this module, if this module is public.
|
// Encode the reexports of this module, if this module is public.
|
||||||
if vis == public {
|
if vis == public {
|
||||||
|
|
|
@ -64,20 +64,27 @@ impl<'self> Visitor<()> for ParentVisitor<'self> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trait methods are always considered "public", but if the trait is
|
||||||
|
// private then we need some private item in the chain from the
|
||||||
|
// method to the root. In this case, if the trait is private, then
|
||||||
|
// parent all the methods to the trait to indicate that they're
|
||||||
|
// private.
|
||||||
|
ast::item_trait(_, _, ref methods) if item.vis != ast::public => {
|
||||||
|
for m in methods.iter() {
|
||||||
|
match *m {
|
||||||
|
ast::provided(ref m) => self.parents.insert(m.id, item.id),
|
||||||
|
ast::required(ref m) => self.parents.insert(m.id, item.id),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
visit::walk_item(self, item, ());
|
visit::walk_item(self, item, ());
|
||||||
self.curparent = prev;
|
self.curparent = prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_trait_method(&mut self, m: &ast::trait_method, _: ()) {
|
|
||||||
match *m {
|
|
||||||
ast::provided(ref m) => self.parents.insert(m.id, self.curparent),
|
|
||||||
ast::required(ref m) => self.parents.insert(m.id, self.curparent),
|
|
||||||
};
|
|
||||||
visit::walk_trait_method(self, m, ());
|
|
||||||
}
|
|
||||||
|
|
||||||
fn visit_foreign_item(&mut self, a: @ast::foreign_item, _: ()) {
|
fn visit_foreign_item(&mut self, a: @ast::foreign_item, _: ()) {
|
||||||
self.parents.insert(a.id, self.curparent);
|
self.parents.insert(a.id, self.curparent);
|
||||||
visit::walk_foreign_item(self, a, ());
|
visit::walk_foreign_item(self, a, ());
|
||||||
|
@ -85,7 +92,12 @@ impl<'self> Visitor<()> for ParentVisitor<'self> {
|
||||||
|
|
||||||
fn visit_fn(&mut self, a: &visit::fn_kind, b: &ast::fn_decl,
|
fn visit_fn(&mut self, a: &visit::fn_kind, b: &ast::fn_decl,
|
||||||
c: &ast::Block, d: Span, id: ast::NodeId, _: ()) {
|
c: &ast::Block, d: Span, id: ast::NodeId, _: ()) {
|
||||||
self.parents.insert(id, self.curparent);
|
// We already took care of some trait methods above, otherwise things
|
||||||
|
// like impl methods and pub trait methods are parented to the
|
||||||
|
// containing module, not the containing trait.
|
||||||
|
if !self.parents.contains_key(&id) {
|
||||||
|
self.parents.insert(id, self.curparent);
|
||||||
|
}
|
||||||
visit::walk_fn(self, a, b, c, d, id, ());
|
visit::walk_fn(self, a, b, c, d, id, ());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1649,7 +1649,15 @@ impl Resolver {
|
||||||
external crate) building external def, priv {:?}",
|
external crate) building external def, priv {:?}",
|
||||||
vis);
|
vis);
|
||||||
let is_public = vis == ast::public;
|
let is_public = vis == ast::public;
|
||||||
if is_public {
|
let is_exported = is_public && match new_parent {
|
||||||
|
ModuleReducedGraphParent(module) => {
|
||||||
|
match module.def_id {
|
||||||
|
None => true,
|
||||||
|
Some(did) => self.external_exports.contains(&did)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if is_exported {
|
||||||
self.external_exports.insert(def_id_of_def(def));
|
self.external_exports.insert(def_id_of_def(def));
|
||||||
}
|
}
|
||||||
match def {
|
match def {
|
||||||
|
@ -1725,7 +1733,7 @@ impl Resolver {
|
||||||
if explicit_self != sty_static {
|
if explicit_self != sty_static {
|
||||||
interned_method_names.insert(method_name.name);
|
interned_method_names.insert(method_name.name);
|
||||||
}
|
}
|
||||||
if is_public {
|
if is_exported {
|
||||||
self.external_exports.insert(method_def_id);
|
self.external_exports.insert(method_def_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1952,7 +1960,7 @@ impl Resolver {
|
||||||
/// Builds the reduced graph rooted at the 'use' directive for an external
|
/// Builds the reduced graph rooted at the 'use' directive for an external
|
||||||
/// crate.
|
/// crate.
|
||||||
fn build_reduced_graph_for_external_crate(&mut self,
|
fn build_reduced_graph_for_external_crate(&mut self,
|
||||||
root: @mut Module) {
|
root: @mut Module) {
|
||||||
do csearch::each_top_level_item_of_crate(self.session.cstore,
|
do csearch::each_top_level_item_of_crate(self.session.cstore,
|
||||||
root.def_id.unwrap().crate)
|
root.def_id.unwrap().crate)
|
||||||
|def_like, ident, visibility| {
|
|def_like, ident, visibility| {
|
||||||
|
|
|
@ -16,7 +16,6 @@ use lib::llvm::{llvm, TargetData, TypeNames};
|
||||||
use lib::llvm::mk_target_data;
|
use lib::llvm::mk_target_data;
|
||||||
use metadata::common::LinkMeta;
|
use metadata::common::LinkMeta;
|
||||||
use middle::astencode;
|
use middle::astencode;
|
||||||
use middle::privacy;
|
|
||||||
use middle::resolve;
|
use middle::resolve;
|
||||||
use middle::trans::adt;
|
use middle::trans::adt;
|
||||||
use middle::trans::base;
|
use middle::trans::base;
|
||||||
|
|
|
@ -1069,7 +1069,7 @@ fn test_try_fail() {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn get_sched_id() -> int {
|
fn get_sched_id() -> int {
|
||||||
do Local::borrow |sched: &mut ::rt::sched::Scheduler| {
|
do Local::borrow |sched: &mut ::rt::shouldnt_be_public::Scheduler| {
|
||||||
sched.sched_id() as int
|
sched.sched_id() as int
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
// Make sure that globs only bring in public things.
|
// Make sure that globs only bring in public things.
|
||||||
|
|
||||||
|
#[feature(globs)];
|
||||||
|
|
||||||
use bar::*;
|
use bar::*;
|
||||||
|
|
||||||
mod bar {
|
mod bar {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#[feature(globs)];
|
||||||
|
|
||||||
// ensures that 'use foo:*' doesn't import non-public item
|
// ensures that 'use foo:*' doesn't import non-public item
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#[feature(globs)];
|
||||||
#[no_std]; // makes debugging this test *a lot* easier (during resolve)
|
#[no_std]; // makes debugging this test *a lot* easier (during resolve)
|
||||||
|
|
||||||
mod bar {
|
mod bar {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#[feature(globs)];
|
||||||
#[no_std]; // makes debugging this test *a lot* easier (during resolve)
|
#[no_std]; // makes debugging this test *a lot* easier (during resolve)
|
||||||
|
|
||||||
// Test to make sure that globs don't leak in regular `use` statements.
|
// Test to make sure that globs don't leak in regular `use` statements.
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#[feature(globs)];
|
||||||
#[no_std]; // makes debugging this test *a lot* easier (during resolve)
|
#[no_std]; // makes debugging this test *a lot* easier (during resolve)
|
||||||
|
|
||||||
// Test to make sure that private items imported through globs remain private
|
// Test to make sure that private items imported through globs remain private
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
|
#[feature(globs)];
|
||||||
#[no_std]; // makes debugging this test *a lot* easier (during resolve)
|
#[no_std]; // makes debugging this test *a lot* easier (during resolve)
|
||||||
|
|
||||||
// Test to make sure that private items imported through globs remain private
|
// Test to make sure that private items imported through globs remain private
|
||||||
|
|
29
src/test/run-pass/privacy1.rs
Normal file
29
src/test/run-pass/privacy1.rs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
pub mod test2 {
|
||||||
|
// This used to generate an ICE (make sure that default functions are
|
||||||
|
// parented to their trait to find the first private thing as the trait).
|
||||||
|
|
||||||
|
struct B;
|
||||||
|
trait A { fn foo(&self) {} }
|
||||||
|
impl A for B {}
|
||||||
|
|
||||||
|
mod tests {
|
||||||
|
use super::A;
|
||||||
|
fn foo() {
|
||||||
|
let a = super::B;
|
||||||
|
a.foo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn main() {}
|
Loading…
Add table
Add a link
Reference in a new issue