]> git.lizzy.rs Git - rust.git/commitdiff
Error if `pub use` references a private item.
authorNick Cameron <ncameron@mozilla.com>
Sun, 15 Mar 2015 05:47:00 +0000 (18:47 +1300)
committerNick Cameron <ncameron@mozilla.com>
Sun, 15 Mar 2015 22:03:54 +0000 (11:03 +1300)
[breaking-change]

Closes #23266

src/librustc_resolve/diagnostics.rs
src/librustc_resolve/lib.rs

index 124aa39243529178149313bbc03b7744e55fe7c7..c586faae6e886dd32f5c398085c401904fe3fa41 100644 (file)
@@ -24,7 +24,9 @@
     E0258, // import conflicts with existing submodule
     E0259, // an extern crate has already been imported into this module
     E0260, // name conflicts with an external crate that has been imported into this module
-    E0317 // user-defined types or type parameters cannot shadow the primitive types
+    E0317, // user-defined types or type parameters cannot shadow the primitive types
+    E0364, // item is private
+    E0365  // item is private
 }
 
 __build_diagnostic_array! { DIAGNOSTICS }
index 605385754044d45f0a0b7ceac39798af7eaa76d2..cf974024e8b554248786aaf1a07831329dac2b6b 100644 (file)
@@ -857,6 +857,19 @@ fn span_for_namespace(&self, namespace: Namespace) -> Option<Span> {
             None
         }
     }
+
+    fn is_public(&self, namespace: Namespace) -> bool {
+        match namespace {
+            TypeNS  => {
+                let type_def = self.type_def.borrow();
+                type_def.as_ref().unwrap().modifiers.contains(PUBLIC)
+            }
+            ValueNS => {
+                let value_def = self.value_def.borrow();
+                value_def.as_ref().unwrap().modifiers.contains(PUBLIC)
+            }
+        }
+    }
 }
 
 /// Interns the names of the primitive types.
@@ -1334,22 +1347,33 @@ fn resolve_single_import(&mut self,
         let mut type_result = UnknownResult;
 
         // Search for direct children of the containing module.
-        build_reduced_graph::populate_module_if_necessary(self, &containing_module);
+        build_reduced_graph::populate_module_if_necessary(self, &target_module);
 
-        match containing_module.children.borrow().get(&source) {
+        match target_module.children.borrow().get(&source) {
             None => {
                 // Continue.
             }
             Some(ref child_name_bindings) => {
+                // pub_err makes sure we don't give the same error twice.
+                let mut pub_err = false;
                 if child_name_bindings.defined_in_namespace(ValueNS) {
                     debug!("(resolving single import) found value binding");
-                    value_result = BoundResult(containing_module.clone(),
+                    value_result = BoundResult(target_module.clone(),
                                                (*child_name_bindings).clone());
+                    if directive.is_public && !child_name_bindings.is_public(ValueNS) {
+                        let msg = format!("`{}` is private", token::get_name(source));
+                        span_err!(self.session, directive.span, E0364, "{}", &msg);
+                        pub_err = true;
+                    }
                 }
                 if child_name_bindings.defined_in_namespace(TypeNS) {
                     debug!("(resolving single import) found type binding");
-                    type_result = BoundResult(containing_module.clone(),
+                    type_result = BoundResult(target_module.clone(),
                                               (*child_name_bindings).clone());
+                    if !pub_err && directive.is_public && !child_name_bindings.is_public(TypeNS) {
+                        let msg = format!("`{}` is private", token::get_name(source));
+                        span_err!(self.session, directive.span, E0365, "{}", &msg);
+                    }
                 }
             }
         }