Skip to content

Commit

Permalink
Write diagnostics for E0364 and E0365
Browse files Browse the repository at this point in the history
  • Loading branch information
AlisdairO committed Jul 17, 2015
1 parent d4432b3 commit 94b1ca8
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 4 deletions.
60 changes: 58 additions & 2 deletions src/librustc_resolve/diagnostics.rs
Expand Up @@ -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
"##

}
Expand All @@ -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
Expand Down
13 changes: 11 additions & 2 deletions src/librustc_resolve/resolve_imports.rs
Expand Up @@ -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;
}
}
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit 94b1ca8

Please sign in to comment.