diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 8cce1321d728b..2ec65424163b5 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -1261,13 +1261,13 @@ impl<'a, 'tcx> VisiblePrivateTypesVisitor<'a, 'tcx> { } fn check_ty_param_bound(&self, - span: Span, ty_param_bound: &ast::TyParamBound) { if let ast::TraitTyParamBound(ref trait_ref) = *ty_param_bound { if !self.tcx.sess.features.borrow().visible_private_types && self.path_is_private_type(trait_ref.trait_ref.ref_id) { + let span = trait_ref.trait_ref.path.span; self.tcx.sess.span_err(span, - "private type in exported type \ + "private trait in exported type \ parameter bound"); } } @@ -1311,7 +1311,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> { } for bound in bounds.iter() { - self.check_ty_param_bound(item.span, bound) + self.check_ty_param_bound(bound) } } @@ -1449,14 +1449,14 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> { fn visit_generics(&mut self, generics: &ast::Generics) { for ty_param in generics.ty_params.iter() { for bound in ty_param.bounds.iter() { - self.check_ty_param_bound(ty_param.span, bound) + self.check_ty_param_bound(bound) } } for predicate in generics.where_clause.predicates.iter() { match predicate { &ast::WherePredicate::BoundPredicate(ref bound_pred) => { for bound in bound_pred.bounds.iter() { - self.check_ty_param_bound(bound_pred.span, bound) + self.check_ty_param_bound(bound) } } &ast::WherePredicate::EqPredicate(ref eq_pred) => { diff --git a/src/test/compile-fail/visible-private-types-generics.rs b/src/test/compile-fail/visible-private-types-generics.rs index 740848e93cbea..7ff18f8e0886c 100644 --- a/src/test/compile-fail/visible-private-types-generics.rs +++ b/src/test/compile-fail/visible-private-types-generics.rs @@ -10,17 +10,56 @@ trait Foo {} -pub fn f() {} //~ ERROR private type in exported type +pub fn f< + T + : Foo //~ ERROR private trait in exported type parameter bound +>() {} -pub fn g() where T: Foo {} //~ ERROR private type in exported type +pub fn g() where + T + : Foo //~ ERROR private trait in exported type parameter bound +{} -pub struct H { //~ ERROR private type in exported type - x: T, +pub struct S; + +impl S { + pub fn f< + T + : Foo //~ ERROR private trait in exported type parameter bound + >() {} + + pub fn g() where + T + : Foo //~ ERROR private trait in exported type parameter bound + {} } -pub struct I where T: Foo { //~ ERROR private type in exported type - x: T, +pub struct S1< + T + : Foo //~ ERROR private trait in exported type parameter bound +> { + x: T } -fn main() {} +pub struct S2 where + T + : Foo //~ ERROR private trait in exported type parameter bound +{ + x: T +} +pub enum E1< + T + : Foo //~ ERROR private trait in exported type parameter bound +> { + V1(T) +} + +pub enum E2 where + T + : Foo //~ ERROR private trait in exported type parameter bound +{ + V2(T) +} + +fn main() {} diff --git a/src/test/compile-fail/visible-private-types-supertrait.rs b/src/test/compile-fail/visible-private-types-supertrait.rs index c4457aaf1e1f3..dc6d446154ac7 100644 --- a/src/test/compile-fail/visible-private-types-supertrait.rs +++ b/src/test/compile-fail/visible-private-types-supertrait.rs @@ -10,7 +10,6 @@ trait Foo {} -pub trait Bar : Foo {} //~ ERROR private type in exported type +pub trait Bar : Foo {} //~ ERROR private trait in exported type fn main() {} -