Skip to content

Commit c141f22

Browse files
committed
auto merge of #19953 : sanxiyn/rust/privacy-span, r=alexcrichton
Fix #19062.
2 parents ce468e6 + 2800695 commit c141f22

File tree

3 files changed

+52
-14
lines changed

3 files changed

+52
-14
lines changed

src/librustc/middle/privacy.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1307,13 +1307,13 @@ impl<'a, 'tcx> VisiblePrivateTypesVisitor<'a, 'tcx> {
13071307
}
13081308

13091309
fn check_ty_param_bound(&self,
1310-
span: Span,
13111310
ty_param_bound: &ast::TyParamBound) {
13121311
if let ast::TraitTyParamBound(ref trait_ref) = *ty_param_bound {
13131312
if !self.tcx.sess.features.borrow().visible_private_types &&
13141313
self.path_is_private_type(trait_ref.trait_ref.ref_id) {
1314+
let span = trait_ref.trait_ref.path.span;
13151315
self.tcx.sess.span_err(span,
1316-
"private type in exported type \
1316+
"private trait in exported type \
13171317
parameter bound");
13181318
}
13191319
}
@@ -1357,7 +1357,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
13571357
}
13581358

13591359
for bound in bounds.iter() {
1360-
self.check_ty_param_bound(item.span, bound)
1360+
self.check_ty_param_bound(bound)
13611361
}
13621362
}
13631363

@@ -1495,14 +1495,14 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
14951495
fn visit_generics(&mut self, generics: &ast::Generics) {
14961496
for ty_param in generics.ty_params.iter() {
14971497
for bound in ty_param.bounds.iter() {
1498-
self.check_ty_param_bound(ty_param.span, bound)
1498+
self.check_ty_param_bound(bound)
14991499
}
15001500
}
15011501
for predicate in generics.where_clause.predicates.iter() {
15021502
match predicate {
15031503
&ast::WherePredicate::BoundPredicate(ref bound_pred) => {
15041504
for bound in bound_pred.bounds.iter() {
1505-
self.check_ty_param_bound(bound_pred.span, bound)
1505+
self.check_ty_param_bound(bound)
15061506
}
15071507
}
15081508
&ast::WherePredicate::RegionPredicate(_) => {}

src/test/compile-fail/visible-private-types-generics.rs

+46-7
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,56 @@
1010

1111
trait Foo {}
1212

13-
pub fn f<T:Foo>() {} //~ ERROR private type in exported type
13+
pub fn f<
14+
T
15+
: Foo //~ ERROR private trait in exported type parameter bound
16+
>() {}
1417

15-
pub fn g<T>() where T: Foo {} //~ ERROR private type in exported type
18+
pub fn g<T>() where
19+
T
20+
: Foo //~ ERROR private trait in exported type parameter bound
21+
{}
1622

17-
pub struct H<T:Foo> { //~ ERROR private type in exported type
18-
x: T,
23+
pub struct S;
24+
25+
impl S {
26+
pub fn f<
27+
T
28+
: Foo //~ ERROR private trait in exported type parameter bound
29+
>() {}
30+
31+
pub fn g<T>() where
32+
T
33+
: Foo //~ ERROR private trait in exported type parameter bound
34+
{}
1935
}
2036

21-
pub struct I<T> where T: Foo { //~ ERROR private type in exported type
22-
x: T,
37+
pub struct S1<
38+
T
39+
: Foo //~ ERROR private trait in exported type parameter bound
40+
> {
41+
x: T
2342
}
2443

25-
fn main() {}
44+
pub struct S2<T> where
45+
T
46+
: Foo //~ ERROR private trait in exported type parameter bound
47+
{
48+
x: T
49+
}
2650

51+
pub enum E1<
52+
T
53+
: Foo //~ ERROR private trait in exported type parameter bound
54+
> {
55+
V1(T)
56+
}
57+
58+
pub enum E2<T> where
59+
T
60+
: Foo //~ ERROR private trait in exported type parameter bound
61+
{
62+
V2(T)
63+
}
64+
65+
fn main() {}

src/test/compile-fail/visible-private-types-supertrait.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
trait Foo {}
1212

13-
pub trait Bar : Foo {} //~ ERROR private type in exported type
13+
pub trait Bar : Foo {} //~ ERROR private trait in exported type
1414

1515
fn main() {}
16-

0 commit comments

Comments
 (0)