]> git.lizzy.rs Git - rust.git/commitdiff
Check privacy in `resolve_name_in_module`.
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Mon, 15 Aug 2016 22:43:25 +0000 (22:43 +0000)
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>
Thu, 18 Aug 2016 03:22:48 +0000 (03:22 +0000)
src/librustc_resolve/lib.rs
src/librustc_resolve/resolve_imports.rs

index d514d7e906a8d3e3387cfd6ee95cac8c2efa3e92..6896439640571435bd7f90e29fb02b4c631e8fcd 100644 (file)
@@ -1304,9 +1304,6 @@ fn search_parent_externals<'a>(this: &mut Resolver<'a>, needle: Name, module: Mo
                     // 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 @@ fn resolve_module_relative_path(&mut self,
         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 @@ fn resolve_crate_relative_path<T>(&mut self, span: Span, segments: &[T], namespa
         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 @@ fn is_accessible(&self, vis: ty::Visibility) -> bool {
         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();
index 6e1128c67735eccaccc34f94b649f9981643dc47..0757ff7ddbfd87a23f5f8608971e989923ab7afe 100644 (file)
@@ -165,8 +165,11 @@ pub fn resolve_name_in_module(&mut self,
                 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)
             });