@@ -16,7 +16,6 @@ use std::mem::replace;
16
16
17
17
use metadata:: csearch;
18
18
use middle:: def;
19
- use lint;
20
19
use middle:: resolve;
21
20
use middle:: ty;
22
21
use middle:: typeck:: { MethodCall , MethodMap , MethodOrigin , MethodParam , MethodTypeParam } ;
@@ -1289,19 +1288,38 @@ impl<'a, 'tcx> VisiblePrivateTypesVisitor<'a, 'tcx> {
1289
1288
} ;
1290
1289
// A path can only be private if:
1291
1290
// it's in this crate...
1292
- is_local ( did) &&
1293
- // ... it's not exported (obviously) ...
1294
- !self . exported_items . contains ( & did. node ) &&
1295
- // .. and it corresponds to a type in the AST (this returns None for
1296
- // type parameters)
1297
- self . tcx . map . find ( did. node ) . is_some ( )
1291
+ if !is_local ( did) {
1292
+ return false
1293
+ }
1294
+ // .. and it corresponds to a private type in the AST (this returns
1295
+ // None for type parameters)
1296
+ match self . tcx . map . find ( did. node ) {
1297
+ Some ( ast_map:: NodeItem ( ref item) ) => item. vis != ast:: Public ,
1298
+ Some ( _) | None => false ,
1299
+ }
1298
1300
}
1299
1301
1300
1302
fn trait_is_public ( & self , trait_id : ast:: NodeId ) -> bool {
1301
1303
// FIXME: this would preferably be using `exported_items`, but all
1302
1304
// traits are exported currently (see `EmbargoVisitor.exported_trait`)
1303
1305
self . public_items . contains ( & trait_id)
1304
1306
}
1307
+
1308
+ fn check_ty_param_bound ( & self ,
1309
+ span : Span ,
1310
+ ty_param_bound : & ast:: TyParamBound ) {
1311
+ match * ty_param_bound {
1312
+ ast:: TraitTyParamBound ( ref trait_ref) => {
1313
+ if !self . tcx . sess . features . borrow ( ) . visible_private_types &&
1314
+ self . path_is_private_type ( trait_ref. ref_id ) {
1315
+ self . tcx . sess . span_err ( span,
1316
+ "private type in exported type \
1317
+ parameter bound") ;
1318
+ }
1319
+ }
1320
+ _ => { }
1321
+ }
1322
+ }
1305
1323
}
1306
1324
1307
1325
impl < ' a , ' b , ' tcx , ' v > Visitor < ' v > for CheckTypeForPrivatenessVisitor < ' a , ' b , ' tcx > {
@@ -1338,7 +1356,15 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
1338
1356
// namespace (the contents have their own privacies).
1339
1357
ast:: ItemForeignMod ( _) => { }
1340
1358
1341
- ast:: ItemTrait ( ..) if !self . trait_is_public ( item. id ) => return ,
1359
+ ast:: ItemTrait ( _, _, ref bounds, _) => {
1360
+ if !self . trait_is_public ( item. id ) {
1361
+ return
1362
+ }
1363
+
1364
+ for bound in bounds. iter ( ) {
1365
+ self . check_ty_param_bound ( item. span , bound)
1366
+ }
1367
+ }
1342
1368
1343
1369
// impls need some special handling to try to offer useful
1344
1370
// error messages without (too many) false positives
@@ -1471,6 +1497,19 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
1471
1497
visit:: walk_item ( self , item) ;
1472
1498
}
1473
1499
1500
+ fn visit_generics ( & mut self , generics : & ast:: Generics ) {
1501
+ for ty_param in generics. ty_params . iter ( ) {
1502
+ for bound in ty_param. bounds . iter ( ) {
1503
+ self . check_ty_param_bound ( ty_param. span , bound)
1504
+ }
1505
+ }
1506
+ for predicate in generics. where_clause . predicates . iter ( ) {
1507
+ for bound in predicate. bounds . iter ( ) {
1508
+ self . check_ty_param_bound ( predicate. span , bound)
1509
+ }
1510
+ }
1511
+ }
1512
+
1474
1513
fn visit_foreign_item ( & mut self , item : & ast:: ForeignItem ) {
1475
1514
if self . exported_items . contains ( & item. id ) {
1476
1515
visit:: walk_foreign_item ( self , item)
@@ -1488,12 +1527,11 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
1488
1527
fn visit_ty ( & mut self , t : & ast:: Ty ) {
1489
1528
match t. node {
1490
1529
ast:: TyPath ( ref p, _, path_id) => {
1491
- if self . path_is_private_type ( path_id) {
1492
- self . tcx . sess . add_lint (
1493
- lint:: builtin:: VISIBLE_PRIVATE_TYPES ,
1494
- path_id, p. span ,
1495
- "private type in exported type \
1496
- signature". to_string ( ) ) ;
1530
+ if !self . tcx . sess . features . borrow ( ) . visible_private_types &&
1531
+ self . path_is_private_type ( path_id) {
1532
+ self . tcx . sess . span_err ( p. span ,
1533
+ "private type in exported type \
1534
+ signature") ;
1497
1535
}
1498
1536
}
1499
1537
_ => { }
0 commit comments