about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-08-15 22:43:25 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-08-18 03:22:48 +0000
commit165b0b618cbe83bf15d40742bd2cb9db935097d6 (patch)
tree274dde4a2c675617b33e36038aaef5986b2ea555 /src
parente1c9efcba48f098482ee6033835a4fe321268709 (diff)
downloadrust-165b0b618cbe83bf15d40742bd2cb9db935097d6.tar.gz
rust-165b0b618cbe83bf15d40742bd2cb9db935097d6.zip
Check privacy in `resolve_name_in_module`.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_resolve/lib.rs19
-rw-r--r--src/librustc_resolve/resolve_imports.rs5
2 files changed, 6 insertions, 18 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index d514d7e906a..68964396405 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -1304,9 +1304,6 @@ impl<'a> Resolver<'a> {
                     // Check to see whether there are type bindings, and, if
                     // so, whether there is a module within.
                     if let Some(module_def) = binding.module() {
-                        if let Some(span) = span {
-                            self.check_privacy(name, binding, span);
-                        }
                         search_module = module_def;
                     } else {
                         let msg = format!("Not a module `{}`", name);
@@ -2614,10 +2611,7 @@ impl<'a> Resolver<'a> {
         let name = segments.last().unwrap().identifier.name;
         let result =
             self.resolve_name_in_module(containing_module, name, namespace, false, Some(span));
-        result.success().map(|binding| {
-            self.check_privacy(name, binding, span);
-            binding
-        }).ok_or(false)
+        result.success().ok_or(false)
     }
 
     /// Invariant: This must be called only during main resolution, not during
@@ -2656,10 +2650,7 @@ impl<'a> Resolver<'a> {
         let name = segments.last().unwrap().name();
         let result =
             self.resolve_name_in_module(containing_module, name, namespace, false, Some(span));
-        result.success().map(|binding| {
-            self.check_privacy(name, binding, span);
-            binding
-        }).ok_or(false)
+        result.success().ok_or(false)
     }
 
     fn with_no_errors<T, F>(&mut self, f: F) -> T
@@ -3276,12 +3267,6 @@ impl<'a> Resolver<'a> {
         vis.is_at_least(self.current_vis, self)
     }
 
-    fn check_privacy(&mut self, name: Name, binding: &'a NameBinding<'a>, span: Span) {
-        if !self.is_accessible(binding.vis) {
-            self.privacy_errors.push(PrivacyError(span, name, binding));
-        }
-    }
-
     fn report_privacy_errors(&self) {
         if self.privacy_errors.len() == 0 { return }
         let mut reported_spans = HashSet::new();
diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs
index 6e1128c6773..0757ff7ddbf 100644
--- a/src/librustc_resolve/resolve_imports.rs
+++ b/src/librustc_resolve/resolve_imports.rs
@@ -165,8 +165,11 @@ impl<'a> Resolver<'a> {
                 if !allow_private_imports && binding.is_import() && !binding.is_pseudo_public() {
                     return Failed(None);
                 }
-                if record_used.is_some() {
+                if let Some(span) = record_used {
                     self.record_use(name, ns, binding);
+                    if !self.is_accessible(binding.vis) {
+                        self.privacy_errors.push(PrivacyError(span, name, binding));
+                    }
                 }
                 Success(binding)
             });