@@ -25,6 +25,7 @@ use {resolve_error, ResolutionError};
25
25
26
26
use build_reduced_graph;
27
27
28
+ use rustc:: lint;
28
29
use rustc:: middle:: def:: * ;
29
30
use rustc:: middle:: def_id:: DefId ;
30
31
use rustc:: middle:: privacy:: * ;
@@ -443,7 +444,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
443
444
debug ! ( "(resolving single import) found value binding" ) ;
444
445
value_result = BoundResult ( target_module. clone ( ) ,
445
446
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 ( ) {
447
448
let msg = format ! ( "`{}` is private, and cannot be reexported" , source) ;
448
449
let note_msg = format ! ( "Consider marking `{}` as `pub` in the imported \
449
450
module",
@@ -452,19 +453,40 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
452
453
self . resolver . session . span_note ( directive. span , & note_msg) ;
453
454
pub_err = true ;
454
455
}
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
+ }
455
467
}
456
468
if child_name_bindings. type_ns . defined ( ) {
457
469
debug ! ( "(resolving single import) found type binding" ) ;
458
470
type_result = BoundResult ( target_module. clone ( ) ,
459
471
child_name_bindings. type_ns . clone ( ) ) ;
460
472
if !pub_err && directive. is_public &&
461
- !child_name_bindings. type_ns . is_reexportable ( ) {
473
+ !child_name_bindings. type_ns . is_public ( ) {
462
474
let msg = format ! ( "`{}` is private, and cannot be reexported" , source) ;
463
475
let note_msg = format ! ( "Consider declaring module `{}` as a `pub mod`" ,
464
476
source) ;
465
477
span_err ! ( self . resolver. session, directive. span, E0365 , "{}" , & msg) ;
466
478
self . resolver . session . span_note ( directive. span , & note_msg) ;
467
479
}
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
+ }
468
490
}
469
491
}
470
492
}
@@ -842,10 +864,22 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
842
864
module_to_string( module_) ) ;
843
865
844
866
// 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 ;
845
869
{
846
870
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
+ }
848
881
882
+ let modifier = DefModifiers :: IMPORTABLE | DefModifiers :: PUBLIC ;
849
883
if name_bindings[ namespace] . defined_with ( modifier) {
850
884
let namespace_name = match namespace {
851
885
TypeNS => "type" ,
0 commit comments