Skip to content

Commit 00653da

Browse files
committed
Rollup merge of rust-lang#27071 - AlisdairO:diagnostics, r=Manishearth
Added some detailed diagnostics for E0364 and E0365.
2 parents 1cf11cc + 94b1ca8 commit 00653da

File tree

2 files changed

+69
-4
lines changed

2 files changed

+69
-4
lines changed

src/librustc_resolve/diagnostics.rs

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,64 @@ See the Types section of the reference for more information about the primitive
197197
types:
198198
199199
http://doc.rust-lang.org/reference.html#types
200+
"##,
201+
202+
E0364: r##"
203+
Private items cannot be publicly re-exported. This error indicates that
204+
you attempted to `pub use` a type or value that was not itself public.
205+
206+
Here is an example that demonstrates the error:
207+
208+
```
209+
mod foo {
210+
const X: u32 = 1;
211+
}
212+
pub use foo::X;
213+
```
214+
215+
The solution to this problem is to ensure that the items that you are
216+
re-exporting are themselves marked with `pub`:
217+
218+
```
219+
mod foo {
220+
pub const X: u32 = 1;
221+
}
222+
pub use foo::X;
223+
```
224+
225+
See the 'Use Declarations' section of the reference for more information
226+
on this topic:
227+
228+
http://doc.rust-lang.org/reference.html#use-declarations
229+
"##,
230+
231+
E0365: r##"
232+
Private modules cannot be publicly re-exported. This error indicates
233+
that you attempted to `pub use` a module that was not itself public.
234+
235+
Here is an example that demonstrates the error:
236+
237+
```
238+
mod foo {
239+
pub const X: u32 = 1;
240+
}
241+
pub use foo as foo2;
242+
243+
```
244+
The solution to this problem is to ensure that the module that you are
245+
re-exporting is itself marked with `pub`:
246+
247+
```
248+
pub mod foo {
249+
pub const X: u32 = 1;
250+
}
251+
pub use foo as foo2;
252+
```
253+
254+
See the 'Use Declarations' section of the reference for more information
255+
on this topic:
256+
257+
http://doc.rust-lang.org/reference.html#use-declarations
200258
"##
201259

202260
}
@@ -208,8 +266,6 @@ register_diagnostics! {
208266
E0254, // import conflicts with imported crate in this module
209267
E0257,
210268
E0258,
211-
E0364, // item is private
212-
E0365, // item is private
213269
E0401, // can't use type parameters from outer function
214270
E0402, // cannot use an outer type parameter in this context
215271
E0403, // the name `{}` is already used

src/librustc_resolve/resolve_imports.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,13 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
434434
value_result = BoundResult(target_module.clone(),
435435
(*child_name_bindings).clone());
436436
if directive.is_public && !child_name_bindings.is_public(ValueNS) {
437-
let msg = format!("`{}` is private", source);
437+
let msg = format!("`{}` is private, and cannot be reexported",
438+
token::get_name(source));
439+
let note_msg =
440+
format!("Consider marking `{}` as `pub` in the imported module",
441+
token::get_name(source));
438442
span_err!(self.resolver.session, directive.span, E0364, "{}", &msg);
443+
self.resolver.session.span_note(directive.span, &note_msg);
439444
pub_err = true;
440445
}
441446
}
@@ -444,8 +449,12 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
444449
type_result = BoundResult(target_module.clone(),
445450
(*child_name_bindings).clone());
446451
if !pub_err && directive.is_public && !child_name_bindings.is_public(TypeNS) {
447-
let msg = format!("`{}` is private", source);
452+
let msg = format!("`{}` is private, and cannot be reexported",
453+
token::get_name(source));
454+
let note_msg = format!("Consider declaring module {} as `pub mod`",
455+
token::get_name(source));
448456
span_err!(self.resolver.session, directive.span, E0365, "{}", &msg);
457+
self.resolver.session.span_note(directive.span, &note_msg);
449458
}
450459
}
451460
}

0 commit comments

Comments
 (0)