@@ -25,6 +25,7 @@ use {resolve_error, ResolutionError};
2525
2626use build_reduced_graph;
2727
28+ use rustc:: lint;
2829use rustc:: middle:: def:: * ;
2930use rustc:: middle:: def_id:: DefId ;
3031use rustc:: middle:: privacy:: * ;
@@ -443,7 +444,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
443444 debug ! ( "(resolving single import) found value binding" ) ;
444445 value_result = BoundResult ( target_module. clone ( ) ,
445446 child_name_bindings. value_ns . clone ( ) ) ;
446- if directive. is_public && !child_name_bindings. value_ns . is_reexportable ( ) {
447+ if directive. is_public && !child_name_bindings. value_ns . is_public ( ) {
447448 let msg = format ! ( "`{}` is private, and cannot be reexported" , source) ;
448449 let note_msg = format ! ( "Consider marking `{}` as `pub` in the imported \
449450 module",
@@ -452,19 +453,40 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
452453 self . resolver . session . span_note ( directive. span , & note_msg) ;
453454 pub_err = true ;
454455 }
456+ if directive. is_public && child_name_bindings. value_ns .
457+ defined_with ( DefModifiers :: PRIVATE_VARIANT ) {
458+ let msg = format ! ( "variant `{}` is private, and cannot be reexported ( \
459+ error E0364), consider declaring its enum as `pub`",
460+ source) ;
461+ self . resolver . session . add_lint ( lint:: builtin:: PRIVATE_IN_PUBLIC ,
462+ directive. id ,
463+ directive. span ,
464+ msg) ;
465+ pub_err = true ;
466+ }
455467 }
456468 if child_name_bindings. type_ns . defined ( ) {
457469 debug ! ( "(resolving single import) found type binding" ) ;
458470 type_result = BoundResult ( target_module. clone ( ) ,
459471 child_name_bindings. type_ns . clone ( ) ) ;
460472 if !pub_err && directive. is_public &&
461- !child_name_bindings. type_ns . is_reexportable ( ) {
473+ !child_name_bindings. type_ns . is_public ( ) {
462474 let msg = format ! ( "`{}` is private, and cannot be reexported" , source) ;
463475 let note_msg = format ! ( "Consider declaring module `{}` as a `pub mod`" ,
464476 source) ;
465477 span_err ! ( self . resolver. session, directive. span, E0365 , "{}" , & msg) ;
466478 self . resolver . session . span_note ( directive. span , & note_msg) ;
467479 }
480+ if !pub_err && directive. is_public && child_name_bindings. type_ns .
481+ defined_with ( DefModifiers :: PRIVATE_VARIANT ) {
482+ let msg = format ! ( "variant `{}` is private, and cannot be reexported ( \
483+ error E0365), consider declaring its enum as `pub`",
484+ source) ;
485+ self . resolver . session . add_lint ( lint:: builtin:: PRIVATE_IN_PUBLIC ,
486+ directive. id ,
487+ directive. span ,
488+ msg) ;
489+ }
468490 }
469491 }
470492 }
@@ -842,10 +864,22 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
842864 module_to_string( module_) ) ;
843865
844866 // Merge the child item into the import resolution.
867+ // pub_err makes sure we don't give the same error twice.
868+ let mut pub_err = false ;
845869 {
846870 let mut merge_child_item = |namespace| {
847- let modifier = DefModifiers :: IMPORTABLE | DefModifiers :: PUBLIC ;
871+ if !pub_err && is_public &&
872+ name_bindings[ namespace] . defined_with ( DefModifiers :: PRIVATE_VARIANT ) {
873+ let msg = format ! ( "variant `{}` is private, and cannot be reexported (error \
874+ E0364), consider declaring its enum as `pub`", name) ;
875+ self . resolver . session . add_lint ( lint:: builtin:: PRIVATE_IN_PUBLIC ,
876+ import_directive. id ,
877+ import_directive. span ,
878+ msg) ;
879+ pub_err = true ;
880+ }
848881
882+ let modifier = DefModifiers :: IMPORTABLE | DefModifiers :: PUBLIC ;
849883 if name_bindings[ namespace] . defined_with ( modifier) {
850884 let namespace_name = match namespace {
851885 TypeNS => "type" ,
0 commit comments