@@ -23,6 +23,7 @@ use rustc::hir::def_id::DefId;
2323use rustc:: hir:: def:: * ;
2424use rustc:: session:: DiagnosticMessageId ;
2525use rustc:: util:: nodemap:: { FxHashMap , FxHashSet } ;
26+ use rustc_errors:: { DiagnosticBuilder , DiagnosticId } ;
2627
2728use syntax:: ast:: { Ident , Name , SpannedIdent , NodeId } ;
2829use syntax:: ext:: base:: Determinacy :: { self , Determined , Undetermined } ;
@@ -599,6 +600,18 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
599600 !indeterminate
600601 }
601602
603+ fn private_reexport_error ( & self , span : Span , ns : Namespace , ident : Ident )
604+ -> DiagnosticBuilder {
605+ __diagnostic_used ! ( E0364 ) ;
606+ __diagnostic_used ! ( E0365 ) ;
607+ let code = match ns {
608+ TypeNS => DiagnosticId ( "E0365" ) ,
609+ _ => DiagnosticId ( "E0364" ) ,
610+ } ;
611+ let msg = format ! ( "`{}` is private and cannot be reexported" , ident) ;
612+ self . session . struct_span_err_with_code ( span, & msg, code)
613+ }
614+
602615 // If appropriate, returns an error to report.
603616 fn finalize_import ( & mut self , directive : & ' b ImportDirective < ' b > ) -> Option < ( Span , String ) > {
604617 self . current_module = directive. parent ;
@@ -756,19 +769,12 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
756769 directive. id ,
757770 directive. span ,
758771 & msg) ;
759- } else if ns == TypeNS {
760- struct_span_err ! ( self . session, directive. span, E0365 ,
761- "`{}` is private, and cannot be reexported" , ident)
762- . span_label ( directive. span , format ! ( "reexport of private `{}`" , ident) )
763- . note ( & format ! ( "consider declaring type or module `{}` with `pub`" , ident) )
764- . emit ( ) ;
765772 } else {
766- let msg = format ! ( "`{}` is private, and cannot be reexported" , ident) ;
767- let note_msg =
768- format ! ( "consider marking `{}` as `pub` in the imported module" , ident) ;
769- struct_span_err ! ( self . session, directive. span, E0364 , "{}" , & msg)
770- . span_note ( directive. span , & note_msg)
771- . emit ( ) ;
773+ let mut err = self . private_reexport_error ( directive. span , ns, ident) ;
774+ // FIXME: use a structured suggestion (taking care to get the spans
775+ // right even if there's an existing `pub(in path)`, &c.)
776+ err. help ( "consider making it public" ) ;
777+ err. emit ( ) ;
772778 }
773779 }
774780
0 commit comments