@@ -857,6 +857,19 @@ impl NameBindings {
857
857
None
858
858
}
859
859
}
860
+
861
+ fn is_public ( & self , namespace : Namespace ) -> bool {
862
+ match namespace {
863
+ TypeNS => {
864
+ let type_def = self . type_def . borrow ( ) ;
865
+ type_def. as_ref ( ) . unwrap ( ) . modifiers . contains ( PUBLIC )
866
+ }
867
+ ValueNS => {
868
+ let value_def = self . value_def . borrow ( ) ;
869
+ value_def. as_ref ( ) . unwrap ( ) . modifiers . contains ( PUBLIC )
870
+ }
871
+ }
872
+ }
860
873
}
861
874
862
875
/// Interns the names of the primitive types.
@@ -1334,22 +1347,33 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1334
1347
let mut type_result = UnknownResult ;
1335
1348
1336
1349
// Search for direct children of the containing module.
1337
- build_reduced_graph:: populate_module_if_necessary ( self , & containing_module ) ;
1350
+ build_reduced_graph:: populate_module_if_necessary ( self , & target_module ) ;
1338
1351
1339
- match containing_module . children . borrow ( ) . get ( & source) {
1352
+ match target_module . children . borrow ( ) . get ( & source) {
1340
1353
None => {
1341
1354
// Continue.
1342
1355
}
1343
1356
Some ( ref child_name_bindings) => {
1357
+ // pub_err makes sure we don't give the same error twice.
1358
+ let mut pub_err = false ;
1344
1359
if child_name_bindings. defined_in_namespace ( ValueNS ) {
1345
1360
debug ! ( "(resolving single import) found value binding" ) ;
1346
- value_result = BoundResult ( containing_module . clone ( ) ,
1361
+ value_result = BoundResult ( target_module . clone ( ) ,
1347
1362
( * child_name_bindings) . clone ( ) ) ;
1363
+ if directive. is_public && !child_name_bindings. is_public ( ValueNS ) {
1364
+ let msg = format ! ( "`{}` is private" , token:: get_name( source) ) ;
1365
+ span_err ! ( self . session, directive. span, E0364 , "{}" , & msg) ;
1366
+ pub_err = true ;
1367
+ }
1348
1368
}
1349
1369
if child_name_bindings. defined_in_namespace ( TypeNS ) {
1350
1370
debug ! ( "(resolving single import) found type binding" ) ;
1351
- type_result = BoundResult ( containing_module . clone ( ) ,
1371
+ type_result = BoundResult ( target_module . clone ( ) ,
1352
1372
( * child_name_bindings) . clone ( ) ) ;
1373
+ if !pub_err && directive. is_public && !child_name_bindings. is_public ( TypeNS ) {
1374
+ let msg = format ! ( "`{}` is private" , token:: get_name( source) ) ;
1375
+ span_err ! ( self . session, directive. span, E0365 , "{}" , & msg) ;
1376
+ }
1353
1377
}
1354
1378
}
1355
1379
}
0 commit comments