auto merge of #21205 : alexcrichton/rust/issue-21202, r=nikomatsakis

Loading methods from external crates was erroneously using the type's privacy
for each method instead of each method's privacy. This commit fixes that.

Closes #21202

This commit also moves privacy to its own crate because I thought that was where the bug was. Turns out it wasn't, but it helped me iterate at least!
This commit is contained in:
bors 2015-01-17 08:51:38 +00:00
commit 3e6eaeb69f
8 changed files with 1655 additions and 1568 deletions

View File

@ -54,7 +54,7 @@ TARGET_CRATES := libc std flate arena term \
log regex graphviz core rbml alloc \
unicode
RUSTC_CRATES := rustc rustc_typeck rustc_borrowck rustc_resolve rustc_driver \
rustc_trans rustc_back rustc_llvm
rustc_trans rustc_back rustc_llvm rustc_privacy
HOST_CRATES := syntax $(RUSTC_CRATES) rustdoc fmt_macros
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
TOOLS := compiletest rustdoc rustc rustbook
@ -68,12 +68,15 @@ DEPS_std := core libc rand alloc collections unicode \
DEPS_graphviz := std
DEPS_syntax := std term serialize log fmt_macros arena libc
DEPS_rustc_driver := arena flate getopts graphviz libc rustc rustc_back rustc_borrowck \
rustc_typeck rustc_resolve log syntax serialize rustc_llvm rustc_trans
rustc_typeck rustc_resolve log syntax serialize rustc_llvm \
rustc_trans rustc_privacy
DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back \
log syntax serialize rustc_llvm
DEPS_rustc_typeck := rustc syntax
DEPS_rustc_borrowck := rustc log graphviz syntax
DEPS_rustc_resolve := rustc log syntax
DEPS_rustc_privacy := rustc log syntax
DEPS_rustc := syntax flate arena serialize getopts rbml \
log graphviz rustc_llvm rustc_back
DEPS_rustc_llvm := native:rustllvm libc std
@ -122,12 +125,13 @@ DOC_CRATES := $(filter-out rustc, \
$(filter-out rustc_borrowck, \
$(filter-out rustc_resolve, \
$(filter-out rustc_driver, \
$(filter-out rustc_privacy, \
$(filter-out log, \
$(filter-out regex, \
$(filter-out getopts, \
$(filter-out syntax, $(CRATES)))))))))))
$(filter-out syntax, $(CRATES))))))))))))
COMPILER_DOC_CRATES := rustc rustc_trans rustc_borrowck rustc_resolve \
rustc_typeck rustc_driver syntax
rustc_typeck rustc_driver syntax rustc_privacy
# This macro creates some simple definitions for each crate being built, just
# some munging of all of the parameters above.

File diff suppressed because it is too large Load Diff

View File

@ -26,6 +26,7 @@ use rustc_trans::back::link;
use rustc_trans::back::write;
use rustc_trans::trans;
use rustc_typeck as typeck;
use rustc_privacy;
use serialize::json;
@ -630,7 +631,7 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
let maps = (external_exports, last_private_map);
let (exported_items, public_items) =
time(time_passes, "privacy checking", maps, |(a, b)|
middle::privacy::check_crate(&ty_cx, &export_map, a, b));
rustc_privacy::check_crate(&ty_cx, &export_map, a, b));
time(time_passes, "intrinsic checking", (), |_|
middle::intrinsicck::check_crate(&ty_cx));

View File

@ -38,6 +38,7 @@ extern crate libc;
extern crate rustc;
extern crate rustc_back;
extern crate rustc_borrowck;
extern crate rustc_privacy;
extern crate rustc_resolve;
extern crate rustc_trans;
extern crate rustc_typeck;

1598
src/librustc_privacy/lib.rs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -999,7 +999,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
root: &Rc<Module>,
def_like: DefLike,
name: Name,
visibility: Visibility) {
def_visibility: Visibility) {
match def_like {
DlDef(def) => {
// Add the new child item, if necessary.
@ -1027,7 +1027,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
DUMMY_SP);
self.handle_external_def(def,
visibility,
def_visibility,
&*child_name_bindings,
token::get_name(name).get(),
name,
@ -1106,7 +1106,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
let def = DefFn(method_info.def_id, false);
// NB: not IMPORTABLE
let modifiers = if visibility == ast::Public {
let modifiers = if method_info.vis == ast::Public {
PUBLIC
} else {
DefModifiers::empty()

View File

@ -0,0 +1,16 @@
// Copyright 2015 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 A {
pub struct Foo;
impl Foo {
fn foo(&self) { }
}
}

View File

@ -0,0 +1,25 @@
// Copyright 2015 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.
// aux-build:issue-21202.rs
extern crate "issue-21202" as crate1;
use crate1::A;
mod B {
use crate1::A::Foo;
fn bar(f: Foo) {
Foo::foo(&f);
//~^ ERROR: function `foo` is private
}
}
fn main() { }