about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlisdair Owens <awo101@zepler.net>2015-07-16 19:21:11 +0100
committerAlisdair Owens <awo101@zepler.net>2015-07-17 21:05:51 +0100
commit94b1ca8448a2bcf25091bfb182ddac29b3b1f2a1 (patch)
tree02a21b3e86592457689567b18172ec2de1cd3332
parentd4432b37378ec55450e06799f5344b4b0f4b94e0 (diff)
downloadrust-94b1ca8448a2bcf25091bfb182ddac29b3b1f2a1.tar.gz
rust-94b1ca8448a2bcf25091bfb182ddac29b3b1f2a1.zip
Write diagnostics for E0364 and E0365
-rw-r--r--src/librustc_resolve/diagnostics.rs60
-rw-r--r--src/librustc_resolve/resolve_imports.rs13
2 files changed, 69 insertions, 4 deletions
diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs
index 939991da203..c7125c38aa9 100644
--- a/src/librustc_resolve/diagnostics.rs
+++ b/src/librustc_resolve/diagnostics.rs
@@ -197,6 +197,64 @@ See the Types section of the reference for more information about the primitive
 types:
 
 http://doc.rust-lang.org/reference.html#types
+"##,
+
+E0364: r##"
+Private items cannot be publicly re-exported.  This error indicates that
+you attempted to `pub use` a type or value that was not itself public.
+
+Here is an example that demonstrates the error:
+
+```
+mod foo {
+    const X: u32 = 1;
+}
+pub use foo::X;
+```
+
+The solution to this problem is to ensure that the items that you are
+re-exporting are themselves marked with `pub`:
+
+```
+mod foo {
+    pub const X: u32 = 1;
+}
+pub use foo::X;
+```
+
+See the 'Use Declarations' section of the reference for more information
+on this topic:
+
+http://doc.rust-lang.org/reference.html#use-declarations
+"##,
+
+E0365: r##"
+Private modules cannot be publicly re-exported.  This error indicates
+that you attempted to `pub use` a module that was not itself public.
+
+Here is an example that demonstrates the error:
+
+```
+mod foo {
+    pub const X: u32 = 1;
+}
+pub use foo as foo2;
+
+```
+The solution to this problem is to ensure that the module that you are
+re-exporting is itself marked with `pub`:
+
+```
+pub mod foo {
+    pub const X: u32 = 1;
+}
+pub use foo as foo2;
+```
+
+See the 'Use Declarations' section of the reference for more information
+on this topic:
+
+http://doc.rust-lang.org/reference.html#use-declarations
 "##
 
 }
@@ -208,8 +266,6 @@ register_diagnostics! {
     E0254, // import conflicts with imported crate in this module
     E0257,
     E0258,
-    E0364, // item is private
-    E0365, // item is private
     E0401, // can't use type parameters from outer function
     E0402, // cannot use an outer type parameter in this context
     E0403, // the name `{}` is already used
diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs
index e797da7b8f6..c876d28f0de 100644
--- a/src/librustc_resolve/resolve_imports.rs
+++ b/src/librustc_resolve/resolve_imports.rs
@@ -434,8 +434,13 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
                     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", source);
+                        let msg = format!("`{}` is private, and cannot be reexported",
+                                          token::get_name(source));
+                        let note_msg =
+                            format!("Consider marking `{}` as `pub` in the imported module",
+                                    token::get_name(source));
                         span_err!(self.resolver.session, directive.span, E0364, "{}", &msg);
+                        self.resolver.session.span_note(directive.span, &note_msg);
                         pub_err = true;
                     }
                 }
@@ -444,8 +449,12 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
                     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", source);
+                        let msg = format!("`{}` is private, and cannot be reexported",
+                                          token::get_name(source));
+                        let note_msg = format!("Consider declaring module {} as `pub mod`",
+                                               token::get_name(source));
                         span_err!(self.resolver.session, directive.span, E0365, "{}", &msg);
+                        self.resolver.session.span_note(directive.span, &note_msg);
                     }
                 }
             }