From 3e0cdb63391af29ef83050f1b08a4232911f81f3 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Wed, 17 Dec 2014 23:23:20 +0900 Subject: [PATCH 1/2] Correct span in privacy error --- src/librustc/middle/privacy.rs | 10 +++++----- .../visible-private-types-generics.rs | 19 ++++++++----------- .../visible-private-types-supertrait.rs | 3 +-- 3 files changed, 14 insertions(+), 18 deletions(-) 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..397ac5373bb7b 100644 --- a/src/test/compile-fail/visible-private-types-generics.rs +++ b/src/test/compile-fail/visible-private-types-generics.rs @@ -10,17 +10,14 @@ 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 struct H { //~ ERROR private type in exported type - x: T, -} - -pub struct I where T: Foo { //~ ERROR private type in exported type - x: T, -} +pub fn g() where + T + : Foo //~ ERROR private trait in exported type parameter bound +{} 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() {} - From 2800695fb064a9fcc10ecc21fee175c24d145030 Mon Sep 17 00:00:00 2001 From: Seo Sanghyeon Date: Fri, 19 Dec 2014 16:11:17 +0900 Subject: [PATCH 2/2] Add privacy tests --- .../visible-private-types-generics.rs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/test/compile-fail/visible-private-types-generics.rs b/src/test/compile-fail/visible-private-types-generics.rs index 397ac5373bb7b..7ff18f8e0886c 100644 --- a/src/test/compile-fail/visible-private-types-generics.rs +++ b/src/test/compile-fail/visible-private-types-generics.rs @@ -20,4 +20,46 @@ pub fn g() where : Foo //~ ERROR private trait in exported type parameter bound {} +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 S1< + T + : Foo //~ ERROR private trait in exported type parameter bound +> { + x: T +} + +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() {}