Skip to content

Commit 8115222

Browse files
committed
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
1 parent a9decbd commit 8115222

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

src/librustc_privacy/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
888888
struct type?!"),
889889
}
890890
}
891-
ast::ExprPath(..) => {
891+
ast::ExprPath(_) | ast::ExprQPath(_) => {
892892
let guard = |&: did: ast::DefId| {
893893
let fields = ty::lookup_struct_fields(self.tcx, did);
894894
let any_priv = fields.iter().any(|f| {

src/librustc_resolve/build_reduced_graph.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
999999
root: &Rc<Module>,
10001000
def_like: DefLike,
10011001
name: Name,
1002-
visibility: Visibility) {
1002+
def_visibility: Visibility) {
10031003
match def_like {
10041004
DlDef(def) => {
10051005
// Add the new child item, if necessary.
@@ -1027,7 +1027,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
10271027
DUMMY_SP);
10281028

10291029
self.handle_external_def(def,
1030-
visibility,
1030+
def_visibility,
10311031
&*child_name_bindings,
10321032
token::get_name(name).get(),
10331033
name,
@@ -1106,7 +1106,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
11061106
let def = DefFn(method_info.def_id, false);
11071107

11081108
// NB: not IMPORTABLE
1109-
let modifiers = if visibility == ast::Public {
1109+
let modifiers = if method_info.vis == ast::Public {
11101110
PUBLIC
11111111
} else {
11121112
DefModifiers::empty()

src/test/auxiliary/issue-21202.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2015 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 A {
12+
pub struct Foo;
13+
impl Foo {
14+
fn foo(&self) { }
15+
}
16+
}

src/test/compile-fail/issue-21202.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2015 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+
// aux-build:issue-21202.rs
12+
13+
extern crate "issue-21202" as crate1;
14+
15+
use crate1::A;
16+
17+
mod B {
18+
use crate1::A::Foo;
19+
fn bar(f: Foo) {
20+
Foo::foo(&f);
21+
//~^ ERROR: function `foo` is private
22+
}
23+
}
24+
25+
fn main() { }

0 commit comments

Comments
 (0)