@@ -23,6 +23,7 @@ use rustc::hir::def_id::DefId;
23
23
use rustc:: hir:: def:: * ;
24
24
use rustc:: session:: DiagnosticMessageId ;
25
25
use rustc:: util:: nodemap:: { FxHashMap , FxHashSet } ;
26
+ use rustc_errors:: { DiagnosticBuilder , DiagnosticId } ;
26
27
27
28
use syntax:: ast:: { Ident , Name , SpannedIdent , NodeId } ;
28
29
use syntax:: ext:: base:: Determinacy :: { self , Determined , Undetermined } ;
@@ -599,6 +600,18 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
599
600
!indeterminate
600
601
}
601
602
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
+
602
615
// If appropriate, returns an error to report.
603
616
fn finalize_import ( & mut self , directive : & ' b ImportDirective < ' b > ) -> Option < ( Span , String ) > {
604
617
self . current_module = directive. parent ;
@@ -756,19 +769,12 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
756
769
directive. id ,
757
770
directive. span ,
758
771
& 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 ( ) ;
765
772
} 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 ( ) ;
772
778
}
773
779
}
774
780
0 commit comments