Skip to content

Commit 548e681

Browse files
committed
rustc_privacy: switch private-in-public checking to Ty.
1 parent fcdb4de commit 548e681

File tree

8 files changed

+289
-234
lines changed

8 files changed

+289
-234
lines changed

src/librustc_privacy/lib.rs

+183-149
Large diffs are not rendered by default.

src/test/compile-fail/E0445.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ trait Foo {
1313
}
1414

1515
pub trait Bar : Foo {}
16-
//~^ ERROR private trait in public interface [E0445]
16+
//~^ ERROR private trait `Foo` in public interface [E0445]
1717
//~| NOTE private trait can't be public
1818
pub struct Bar2<T: Foo>(pub T);
19-
//~^ ERROR private trait in public interface [E0445]
19+
//~^ ERROR private trait `Foo` in public interface [E0445]
2020
//~| NOTE private trait can't be public
2121
pub fn foo<T: Foo> (t: T) {}
22-
//~^ ERROR private trait in public interface [E0445]
22+
//~^ ERROR private trait `Foo` in public interface [E0445]
2323
//~| NOTE private trait can't be public
2424

2525
fn main() {}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use std::any::TypeId;
1414
trait Private<P, R> {
1515
fn call(&self, p: P, r: R);
1616
}
17-
pub trait Public: Private< //~ ERROR private trait in public interface
17+
pub trait Public: Private<
18+
//~^ ERROR private trait `Private<<Self as Public>::P, <Self as Public>::R>` in public interface
1819
<Self as Public>::P,
1920
<Self as Public>::R
2021
> {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod inner {
2121
fn b(&self) { }
2222
}
2323

24-
pub trait C: A + B { //~ ERROR private trait in public interface
24+
pub trait C: A + B { //~ ERROR private trait `inner::A` in public interface
2525
//~^ WARN will become a hard error
2626
fn c(&self) { }
2727
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct SemiPriv;
1616
mod m1 {
1717
struct Priv;
1818
impl ::SemiPriv {
19-
pub fn f(_: Priv) {} //~ ERROR private type in public interface
19+
pub fn f(_: Priv) {} //~ ERROR private type `m1::Priv` in public interface
2020
//~^ WARNING hard error
2121
}
2222

@@ -28,7 +28,7 @@ mod m1 {
2828
mod m2 {
2929
struct Priv;
3030
impl ::std::ops::Deref for ::SemiPriv {
31-
type Target = Priv; //~ ERROR private type in public interface
31+
type Target = Priv; //~ ERROR private type `m2::Priv` in public interface
3232
//~^ WARNING hard error
3333
fn deref(&self) -> &Self::Target { unimplemented!() }
3434
}
@@ -46,7 +46,7 @@ trait SemiPrivTrait {
4646
mod m3 {
4747
struct Priv;
4848
impl ::SemiPrivTrait for () {
49-
type Assoc = Priv; //~ ERROR private type in public interface
49+
type Assoc = Priv; //~ ERROR private type `m3::Priv` in public interface
5050
//~^ WARNING hard error
5151
}
5252
}

src/test/compile-fail/private-in-public-lint.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mod m1 {
1313
struct Priv;
1414

1515
impl Pub {
16-
pub fn f() -> Priv {Priv} //~ ERROR private type in public interface
16+
pub fn f() -> Priv {Priv} //~ ERROR private type `m1::Priv` in public interface
1717
}
1818
}
1919

@@ -24,7 +24,7 @@ mod m2 {
2424
struct Priv;
2525

2626
impl Pub {
27-
pub fn f() -> Priv {Priv} //~ ERROR private type in public interface
27+
pub fn f() -> Priv {Priv} //~ ERROR private type `m2::Priv` in public interface
2828
}
2929
}
3030

src/test/compile-fail/private-in-public-warn.rs

+53-44
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,34 @@ mod types {
2424
type Alias;
2525
}
2626

27-
pub type Alias = Priv; //~ ERROR private type in public interface
27+
pub type Alias = Priv; //~ ERROR private type `types::Priv` in public interface
2828
//~^ WARNING hard error
2929
pub enum E {
30-
V1(Priv), //~ ERROR private type in public interface
30+
V1(Priv), //~ ERROR private type `types::Priv` in public interface
3131
//~^ WARNING hard error
32-
V2 { field: Priv }, //~ ERROR private type in public interface
32+
V2 { field: Priv }, //~ ERROR private type `types::Priv` in public interface
3333
//~^ WARNING hard error
3434
}
3535
pub trait Tr {
36-
const C: Priv = Priv; //~ ERROR private type in public interface
36+
const C: Priv = Priv; //~ ERROR private type `types::Priv` in public interface
3737
//~^ WARNING hard error
38-
type Alias = Priv; //~ ERROR private type in public interface
38+
type Alias = Priv; //~ ERROR private type `types::Priv` in public interface
3939
//~^ WARNING hard error
40-
fn f1(arg: Priv) {} //~ ERROR private type in public interface
40+
fn f1(arg: Priv) {} //~ ERROR private type `types::Priv` in public interface
4141
//~^ WARNING hard error
42-
fn f2() -> Priv { panic!() } //~ ERROR private type in public interface
42+
fn f2() -> Priv { panic!() } //~ ERROR private type `types::Priv` in public interface
4343
//~^ WARNING hard error
4444
}
4545
extern {
46-
pub static ES: Priv; //~ ERROR private type in public interface
46+
pub static ES: Priv; //~ ERROR private type `types::Priv` in public interface
4747
//~^ WARNING hard error
48-
pub fn ef1(arg: Priv); //~ ERROR private type in public interface
48+
pub fn ef1(arg: Priv); //~ ERROR private type `types::Priv` in public interface
4949
//~^ WARNING hard error
50-
pub fn ef2() -> Priv; //~ ERROR private type in public interface
50+
pub fn ef2() -> Priv; //~ ERROR private type `types::Priv` in public interface
5151
//~^ WARNING hard error
5252
}
5353
impl PubTr for Pub {
54-
type Alias = Priv; //~ ERROR private type in public interface
54+
type Alias = Priv; //~ ERROR private type `types::Priv` in public interface
5555
//~^ WARNING hard error
5656
}
5757
}
@@ -61,22 +61,23 @@ mod traits {
6161
pub struct Pub<T>(T);
6262
pub trait PubTr {}
6363

64-
pub type Alias<T: PrivTr> = T; //~ ERROR private trait in public interface
64+
pub type Alias<T: PrivTr> = T; //~ ERROR private trait `traits::PrivTr` in public interface
6565
//~^ WARN trait bounds are not (yet) enforced in type definitions
6666
//~| WARNING hard error
67-
pub trait Tr1: PrivTr {} //~ ERROR private trait in public interface
67+
pub trait Tr1: PrivTr {} //~ ERROR private trait `traits::PrivTr` in public interface
6868
//~^ WARNING hard error
69-
pub trait Tr2<T: PrivTr> {} //~ ERROR private trait in public interface
69+
pub trait Tr2<T: PrivTr> {} //~ ERROR private trait `traits::PrivTr` in public interface
7070
//~^ WARNING hard error
7171
pub trait Tr3 {
72-
type Alias: PrivTr; //~ ERROR private trait in public interface
73-
//~^ WARNING hard error
74-
fn f<T: PrivTr>(arg: T) {} //~ ERROR private trait in public interface
72+
//~^ ERROR private trait `traits::PrivTr` in public interface
73+
//~| WARNING hard error
74+
type Alias: PrivTr;
75+
fn f<T: PrivTr>(arg: T) {} //~ ERROR private trait `traits::PrivTr` in public interface
7576
//~^ WARNING hard error
7677
}
77-
impl<T: PrivTr> Pub<T> {} //~ ERROR private trait in public interface
78+
impl<T: PrivTr> Pub<T> {} //~ ERROR private trait `traits::PrivTr` in public interface
7879
//~^ WARNING hard error
79-
impl<T: PrivTr> PubTr for Pub<T> {} //~ ERROR private trait in public interface
80+
impl<T: PrivTr> PubTr for Pub<T> {} //~ ERROR private trait `traits::PrivTr` in public interface
8081
//~^ WARNING hard error
8182
}
8283

@@ -85,18 +86,23 @@ mod traits_where {
8586
pub struct Pub<T>(T);
8687
pub trait PubTr {}
8788

88-
pub type Alias<T> where T: PrivTr = T; //~ ERROR private trait in public interface
89-
//~^ WARNING hard error
90-
pub trait Tr2<T> where T: PrivTr {} //~ ERROR private trait in public interface
91-
//~^ WARNING hard error
89+
pub type Alias<T> where T: PrivTr = T;
90+
//~^ ERROR private trait `traits_where::PrivTr` in public interface
91+
//~| WARNING hard error
92+
pub trait Tr2<T> where T: PrivTr {}
93+
//~^ ERROR private trait `traits_where::PrivTr` in public interface
94+
//~| WARNING hard error
9295
pub trait Tr3 {
93-
fn f<T>(arg: T) where T: PrivTr {} //~ ERROR private trait in public interface
94-
//~^ WARNING hard error
96+
fn f<T>(arg: T) where T: PrivTr {}
97+
//~^ ERROR private trait `traits_where::PrivTr` in public interface
98+
//~| WARNING hard error
9599
}
96-
impl<T> Pub<T> where T: PrivTr {} //~ ERROR private trait in public interface
97-
//~^ WARNING hard error
98-
impl<T> PubTr for Pub<T> where T: PrivTr {} //~ ERROR private trait in public interface
99-
//~^ WARNING hard error
100+
impl<T> Pub<T> where T: PrivTr {}
101+
//~^ ERROR private trait `traits_where::PrivTr` in public interface
102+
//~| WARNING hard error
103+
impl<T> PubTr for Pub<T> where T: PrivTr {}
104+
//~^ ERROR private trait `traits_where::PrivTr` in public interface
105+
//~| WARNING hard error
100106
}
101107

102108
mod generics {
@@ -105,13 +111,14 @@ mod generics {
105111
trait PrivTr<T> {}
106112
pub trait PubTr<T> {}
107113

108-
pub trait Tr1: PrivTr<Pub> {} //~ ERROR private trait in public interface
109-
//~^ WARNING hard error
110-
pub trait Tr2: PubTr<Priv> {} //~ ERROR private type in public interface
114+
pub trait Tr1: PrivTr<Pub> {}
115+
//~^ ERROR private trait `generics::PrivTr<generics::Pub>` in public interface
116+
//~| WARNING hard error
117+
pub trait Tr2: PubTr<Priv> {} //~ ERROR private type `generics::Priv` in public interface
111118
//~^ WARNING hard error
112-
pub trait Tr3: PubTr<[Priv; 1]> {} //~ ERROR private type in public interface
119+
pub trait Tr3: PubTr<[Priv; 1]> {} //~ ERROR private type `generics::Priv` in public interface
113120
//~^ WARNING hard error
114-
pub trait Tr4: PubTr<Pub<Priv>> {} //~ ERROR private type in public interface
121+
pub trait Tr4: PubTr<Pub<Priv>> {} //~ ERROR private type `generics::Priv` in public interface
115122
//~^ WARNING hard error
116123
}
117124

@@ -138,7 +145,7 @@ mod impls {
138145
type Alias = Priv; // OK
139146
}
140147
impl PubTr for Pub {
141-
type Alias = Priv; //~ ERROR private type in public interface
148+
type Alias = Priv; //~ ERROR private type `impls::Priv` in public interface
142149
//~^ WARNING hard error
143150
}
144151
}
@@ -210,23 +217,23 @@ mod aliases_pub {
210217
pub trait Tr2: PrivUseAliasTr<PrivAlias> {} // OK
211218

212219
impl PrivAlias {
213-
pub fn f(arg: Priv) {} //~ ERROR private type in public interface
220+
pub fn f(arg: Priv) {} //~ ERROR private type `aliases_pub::Priv` in public interface
214221
//~^ WARNING hard error
215222
}
216223
// This doesn't even parse
217224
// impl <Priv as PrivTr>::AssocAlias {
218-
// pub fn f(arg: Priv) {} // ERROR private type in public interface
225+
// pub fn f(arg: Priv) {} // ERROR private type `aliases_pub::Priv` in public interface
219226
// }
220227
impl PrivUseAliasTr for PrivUseAlias {
221-
type Check = Priv; //~ ERROR private type in public interface
228+
type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
222229
//~^ WARNING hard error
223230
}
224231
impl PrivUseAliasTr for PrivAlias {
225-
type Check = Priv; //~ ERROR private type in public interface
232+
type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
226233
//~^ WARNING hard error
227234
}
228235
impl PrivUseAliasTr for <Priv as PrivTr>::AssocAlias {
229-
type Check = Priv; //~ ERROR private type in public interface
236+
type Check = Priv; //~ ERROR private type `aliases_pub::Priv` in public interface
230237
//~^ WARNING hard error
231238
}
232239
}
@@ -251,11 +258,13 @@ mod aliases_priv {
251258
type AssocAlias = Priv3;
252259
}
253260

254-
pub trait Tr1: PrivUseAliasTr {} //~ ERROR private trait in public interface
255-
//~^ WARNING hard error
256-
pub trait Tr2: PrivUseAliasTr<PrivAlias> {} //~ ERROR private trait in public interface
257-
//~^ ERROR private type in public interface
261+
pub trait Tr1: PrivUseAliasTr {}
262+
//~^ ERROR private trait `aliases_priv::PrivTr1` in public interface
263+
//~| WARNING hard error
264+
pub trait Tr2: PrivUseAliasTr<PrivAlias> {}
265+
//~^ ERROR private trait `aliases_priv::PrivTr1<aliases_priv::Priv2>` in public interface
258266
//~| WARNING hard error
267+
//~| ERROR private type `aliases_priv::Priv2` in public interface
259268
//~| WARNING hard error
260269

261270
impl PrivUseAlias {

0 commit comments

Comments
 (0)