Skip to content

Commit ac84af2

Browse files
author
Jorge Aparicio
committed
privacy: walk associated types in trait impls
1 parent b4c965e commit ac84af2

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

src/librustc_privacy/lib.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1376,10 +1376,11 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
13761376
}
13771377
}
13781378
Some(ref tr) => {
1379-
// Any private types in a trait impl fall into two
1379+
// Any private types in a trait impl fall into three
13801380
// categories.
13811381
// 1. mentioned in the trait definition
13821382
// 2. mentioned in the type params/generics
1383+
// 3. mentioned in the associated types of the impl
13831384
//
13841385
// Those in 1. can only occur if the trait is in
13851386
// this crate and will've been warned about on the
@@ -1389,6 +1390,16 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
13891390
// Those in 2. are warned via walk_generics and this
13901391
// call here.
13911392
visit::walk_path(self, &tr.path);
1393+
1394+
// Those in 3. are warned with this call.
1395+
for impl_item in impl_items {
1396+
match *impl_item {
1397+
ast::MethodImplItem(..) => {},
1398+
ast::TypeImplItem(ref typedef) => {
1399+
self.visit_ty(&typedef.typ);
1400+
}
1401+
}
1402+
}
13921403
}
13931404
}
13941405
} else if trait_ref.is_none() && self_is_public_path {

src/test/compile-fail/issue-22912.rs

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub struct PublicType;
12+
struct PrivateType;
13+
14+
pub trait PublicTrait {
15+
type Item;
16+
}
17+
18+
trait PrivateTrait {
19+
type Item;
20+
}
21+
22+
impl PublicTrait for PublicType {
23+
type Item = PrivateType; //~ ERROR private type in exported type signature
24+
}
25+
26+
// OK
27+
impl PublicTrait for PrivateType {
28+
type Item = PrivateType;
29+
}
30+
31+
// OK
32+
impl PrivateTrait for PublicType {
33+
type Item = PrivateType;
34+
}
35+
36+
// OK
37+
impl PrivateTrait for PrivateType {
38+
type Item = PrivateType;
39+
}
40+
41+
fn main() {}

0 commit comments

Comments
 (0)