Skip to content

Commit

Permalink
auto merge of #19953 : sanxiyn/rust/privacy-span, r=alexcrichton
Browse files Browse the repository at this point in the history
Fix #19062.
  • Loading branch information
bors committed Dec 21, 2014
2 parents ce468e6 + 2800695 commit c141f22
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/librustc/middle/privacy.rs
Expand Up @@ -1307,13 +1307,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");
}
}
Expand Down Expand Up @@ -1357,7 +1357,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)
}
}

Expand Down Expand Up @@ -1495,14 +1495,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::RegionPredicate(_) => {}
Expand Down
53 changes: 46 additions & 7 deletions src/test/compile-fail/visible-private-types-generics.rs
Expand Up @@ -10,17 +10,56 @@

trait Foo {}

pub fn f<T:Foo>() {} //~ ERROR private type in exported type
pub fn f<
T
: Foo //~ ERROR private trait in exported type parameter bound
>() {}

pub fn g<T>() where T: Foo {} //~ ERROR private type in exported type
pub fn g<T>() where
T
: Foo //~ ERROR private trait in exported type parameter bound
{}

pub struct H<T:Foo> { //~ 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<T>() where
T
: Foo //~ ERROR private trait in exported type parameter bound
{}
}

pub struct I<T> 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<T> 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<T> where
T
: Foo //~ ERROR private trait in exported type parameter bound
{
V2(T)
}

fn main() {}
3 changes: 1 addition & 2 deletions src/test/compile-fail/visible-private-types-supertrait.rs
Expand Up @@ -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() {}

0 comments on commit c141f22

Please sign in to comment.