Rollup merge of #27071 - AlisdairO:diagnostics, r=Manishearth
Added some detailed diagnostics for E0364 and E0365.
This commit is contained in:
commit
00653da41a
@ -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
|
||||
|
@ -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, ¬e_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, ¬e_msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user