@@ -16,7 +16,6 @@ use std::mem::replace;
1616
1717use metadata:: csearch;
1818use middle:: def;
19- use lint;
2019use middle:: resolve;
2120use middle:: ty;
2221use middle:: typeck:: { MethodCall , MethodMap , MethodOrigin , MethodParam , MethodTypeParam } ;
@@ -1289,19 +1288,38 @@ impl<'a, 'tcx> VisiblePrivateTypesVisitor<'a, 'tcx> {
12891288 } ;
12901289 // A path can only be private if:
12911290 // 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+ }
12981300 }
12991301
13001302 fn trait_is_public ( & self , trait_id : ast:: NodeId ) -> bool {
13011303 // FIXME: this would preferably be using `exported_items`, but all
13021304 // traits are exported currently (see `EmbargoVisitor.exported_trait`)
13031305 self . public_items . contains ( & trait_id)
13041306 }
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+ }
13051323}
13061324
13071325impl < ' 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> {
13381356 // namespace (the contents have their own privacies).
13391357 ast:: ItemForeignMod ( _) => { }
13401358
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+ }
13421368
13431369 // impls need some special handling to try to offer useful
13441370 // error messages without (too many) false positives
@@ -1471,6 +1497,19 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
14711497 visit:: walk_item ( self , item) ;
14721498 }
14731499
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+
14741513 fn visit_foreign_item ( & mut self , item : & ast:: ForeignItem ) {
14751514 if self . exported_items . contains ( & item. id ) {
14761515 visit:: walk_foreign_item ( self , item)
@@ -1488,12 +1527,11 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
14881527 fn visit_ty ( & mut self , t : & ast:: Ty ) {
14891528 match t. node {
14901529 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") ;
14971535 }
14981536 }
14991537 _ => { }
0 commit comments