about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-01-15 10:49:47 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-01-16 08:39:56 -0800
commit811522260760d5c1d6a4c8162ba816a471f37232 (patch)
tree783543281e8affb0adc0e0b1b33d4798d17aaee3
parenta9decbdc443f120d1ca2efb1798bfc20bad7c2d4 (diff)
downloadrust-811522260760d5c1d6a4c8162ba816a471f37232.tar.gz
rust-811522260760d5c1d6a4c8162ba816a471f37232.zip
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
-rw-r--r--src/librustc_privacy/lib.rs2
-rw-r--r--src/librustc_resolve/build_reduced_graph.rs6
-rw-r--r--src/test/auxiliary/issue-21202.rs16
-rw-r--r--src/test/compile-fail/issue-21202.rs25
4 files changed, 45 insertions, 4 deletions
diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs
index 85ca3b05d12..8e5f7c57690 100644
--- a/src/librustc_privacy/lib.rs
+++ b/src/librustc_privacy/lib.rs
@@ -888,7 +888,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> {
                                                             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| {
diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs
index 466bd608736..8d62c5e1ca0 100644
--- a/src/librustc_resolve/build_reduced_graph.rs
+++ b/src/librustc_resolve/build_reduced_graph.rs
@@ -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()
diff --git a/src/test/auxiliary/issue-21202.rs b/src/test/auxiliary/issue-21202.rs
new file mode 100644
index 00000000000..afdbf78aa82
--- /dev/null
+++ b/src/test/auxiliary/issue-21202.rs
@@ -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) { }
+    }
+}
diff --git a/src/test/compile-fail/issue-21202.rs b/src/test/compile-fail/issue-21202.rs
new file mode 100644
index 00000000000..5c1de6dfc55
--- /dev/null
+++ b/src/test/compile-fail/issue-21202.rs
@@ -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() { }