rustc_resolve: Correctly record privacy of methods

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 is contained in:
Alex Crichton 2015-01-15 10:49:47 -08:00
parent a9decbdc44
commit 8115222607
4 changed files with 45 additions and 4 deletions

View File

@ -888,7 +888,7 @@ fn visit_expr(&mut self, expr: &ast::Expr) {
struct type?!"),
}
}
ast::ExprPath(..) => {
ast::ExprPath(_) | ast::ExprQPath(_) => {
let guard = |&: did: ast::DefId| {
let fields = ty::lookup_struct_fields(self.tcx, did);
let any_priv = fields.iter().any(|f| {

View File

@ -999,7 +999,7 @@ fn build_reduced_graph_for_external_crate_def(&mut self,
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 @@ fn build_reduced_graph_for_external_crate_def(&mut self,
DUMMY_SP);
self.handle_external_def(def,
visibility,
def_visibility,
&*child_name_bindings,
token::get_name(name).get(),
name,
@ -1106,7 +1106,7 @@ fn build_reduced_graph_for_external_crate_def(&mut self,
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() { }