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

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() { }