Skip to content

Commit f8ae31f

Browse files
committed
Update error messages and error descriptions
1 parent 26a2f85 commit f8ae31f

10 files changed

+44
-41
lines changed

src/librustc_privacy/diagnostics.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ trait Foo {
2121
fn dummy(&self) { }
2222
}
2323
24-
pub trait Bar : Foo {} // error: private trait in exported type parameter bound
24+
pub trait Bar : Foo {} // error: private trait in public interface
2525
pub struct Bar<T: Foo>(pub T); // same error
2626
pub fn foo<T: Foo> (t: T) {} // same error
2727
```
2828
29-
To solve this error, please ensure that the trait is also public and accessible
30-
at the same level of the public functions or types which are bound on it.
29+
To solve this error, please ensure that the trait is also public. The trait
30+
can be made inaccessible if necessary by placing it into a private inner module,
31+
but it still has to be marked with `pub`.
3132
Example:
3233
3334
```
@@ -42,20 +43,22 @@ pub fn foo<T: Foo> (t: T) {} // ok!
4243
"##,
4344

4445
E0446: r##"
45-
A private type was used in an exported type signature. Erroneous code example:
46+
A private type was used in an public type signature. Erroneous code example:
4647
4748
```
4849
mod Foo {
4950
struct Bar(u32);
5051
51-
pub fn bar() -> Bar { // error: private type in exported type signature
52+
pub fn bar() -> Bar { // error: private type in public interface
5253
Bar(0)
5354
}
5455
}
5556
```
5657
57-
To solve this error, please ensure that the type is also public and accessible
58-
at the same level of the public functions or types which use it. Example:
58+
To solve this error, please ensure that the type is also public. The type
59+
can be made inaccessible if necessary by placing it into a private inner module,
60+
but it still has to be marked with `pub`.
61+
Example:
5962
6063
```
6164
mod Foo {

src/librustc_privacy/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ impl<'a, 'tcx: 'a, 'v> Visitor<'v> for SearchInterfaceForPrivateItemsVisitor<'a,
11361136
if item.vis != hir::Public {
11371137
if !self.is_quiet {
11381138
span_err!(self.tcx.sess, ty.span, E0446,
1139-
"private type in exported type signature");
1139+
"private type in public interface");
11401140
}
11411141
self.is_public = false;
11421142
}
@@ -1162,7 +1162,7 @@ impl<'a, 'tcx: 'a, 'v> Visitor<'v> for SearchInterfaceForPrivateItemsVisitor<'a,
11621162
if item.vis != hir::Public {
11631163
if !self.is_quiet {
11641164
span_err!(self.tcx.sess, trait_ref.path.span, E0445,
1165-
"private trait in exported type parameter bound");
1165+
"private trait in public interface");
11661166
}
11671167
self.is_public = false;
11681168
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ 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 exported type parameter bound
17+
pub trait Public: Private< //~ ERROR private trait in public interface
1818
<Self as Public>::P,
1919
<Self as Public>::R
2020
> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ trait PrivateTrait {
2020
}
2121

2222
impl PublicTrait for PublicType {
23-
type Item = PrivateType; //~ ERROR private type in exported type signature
23+
type Item = PrivateType; //~ ERROR private type in public interface
2424
}
2525

2626
// OK

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mod y {
1616
struct Bar { x: u32 }
1717

1818
impl Foo {
19-
pub fn foo(&self, x: Self, y: Bar) { } //~ ERROR private type in exported type signature
19+
pub fn foo(&self, x: Self, y: Bar) { } //~ ERROR private type in public interface
2020
}
2121
}
2222

@@ -26,9 +26,9 @@ mod x {
2626
struct Bar { _x: u32 }
2727

2828
impl Foo {
29-
pub fn foo(&self, _x: Self, _y: Bar) { } //~ ERROR private type in exported type signature
29+
pub fn foo(&self, _x: Self, _y: Bar) { } //~ ERROR private type in public interface
3030
pub fn bar(&self) -> Bar { Bar { _x: self.x } }
31-
//~^ ERROR private type in exported type signature
31+
//~^ ERROR private type in public interface
3232
}
3333
}
3434

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ struct Priv;
1515
pub use self::private::public;
1616

1717
mod private {
18-
pub type Priv = super::Priv; //~ ERROR private type in exported type signature
18+
pub type Priv = super::Priv; //~ ERROR private type in public interface
1919

2020
pub fn public(_x: Priv) {
2121
}
2222
}
2323

2424
struct __CFArray;
25-
pub type CFArrayRef = *const __CFArray; //~ ERROR private type in exported type signature
25+
pub type CFArrayRef = *const __CFArray; //~ ERROR private type in public interface
2626
trait Pointer { type Pointee; }
2727
impl<T> Pointer for *const T { type Pointee = T; }
2828
pub type __CFArrayRevealed = <CFArrayRef as Pointer>::Pointee;
29-
//~^ ERROR private type in exported type signature
29+
//~^ ERROR private type in public interface
3030

3131
type Foo = u8;
32-
pub fn foo(f: Foo) {} //~ ERROR private type in exported type signature
32+
pub fn foo(f: Foo) {} //~ ERROR private type in public interface
3333

3434
pub trait Exporter {
3535
type Output;
@@ -43,7 +43,7 @@ pub fn block() -> <Helper as Exporter>::Output {
4343
}
4444

4545
impl Exporter for Helper {
46-
type Output = Inner; //~ ERROR private type in exported type signature
46+
type Output = Inner; //~ ERROR private type in public interface
4747
}
4848

4949
Inner

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ impl Public<Private<isize>> {
3636
fn d() -> Private<isize> { panic!() }
3737
}
3838
impl Public<isize> {
39-
pub fn e(&self) -> Private<isize> { panic!() } //~ ERROR private type in exported type signature
39+
pub fn e(&self) -> Private<isize> { panic!() } //~ ERROR private type in public interface
4040
fn f(&self) -> Private<isize> { panic!() }
4141
}
4242

43-
pub fn x(_: Private<isize>) {} //~ ERROR private type in exported type signature
43+
pub fn x(_: Private<isize>) {} //~ ERROR private type in public interface
4444

4545
fn y(_: Private<isize>) {}
4646

4747

4848
pub struct Foo {
49-
pub x: Private<isize>, //~ ERROR private type in exported type signature
49+
pub x: Private<isize>, //~ ERROR private type in public interface
5050
y: Private<isize>
5151
}
5252

@@ -55,9 +55,9 @@ struct Bar {
5555
}
5656

5757
pub enum Baz {
58-
Baz1(Private<isize>), //~ ERROR private type in exported type signature
58+
Baz1(Private<isize>), //~ ERROR private type in public interface
5959
Baz2 {
60-
y: Private<isize> //~ ERROR private type in exported type signature
60+
y: Private<isize> //~ ERROR private type in public interface
6161
},
6262
}
6363

@@ -69,14 +69,14 @@ enum Qux {
6969
}
7070

7171
pub trait PubTrait {
72-
fn foo(&self) -> Private<isize> { panic!( )} //~ ERROR private type in exported type signature
73-
fn bar(&self) -> Private<isize>; //~ ERROR private type in exported type signature
74-
fn baz() -> Private<isize>; //~ ERROR private type in exported type signature
72+
fn foo(&self) -> Private<isize> { panic!( )} //~ ERROR private type in public interface
73+
fn bar(&self) -> Private<isize>; //~ ERROR private type in public interface
74+
fn baz() -> Private<isize>; //~ ERROR private type in public interface
7575
}
7676

7777
impl PubTrait for Public<isize> {
78-
fn bar(&self) -> Private<isize> { panic!() } //~ ERROR private type in exported type signature
79-
fn baz() -> Private<isize> { panic!() } //~ ERROR private type in exported type signature
78+
fn bar(&self) -> Private<isize> { panic!() } //~ ERROR private type in public interface
79+
fn baz() -> Private<isize> { panic!() } //~ ERROR private type in public interface
8080
}
8181
impl PubTrait for Public<Private<isize>> {
8282
fn bar(&self) -> Private<isize> { panic!() }
@@ -117,7 +117,7 @@ impl ParamTrait<Private<isize>> for Private<isize> {
117117
fn foo() -> Private<isize> { panic!( )}
118118
}
119119

120-
impl<T: ParamTrait<Private<isize>>> //~ ERROR private type in exported type signature
120+
impl<T: ParamTrait<Private<isize>>> //~ ERROR private type in public interface
121121
ParamTrait<T> for Public<i8> {
122122
fn foo() -> T { panic!() }
123123
}

src/test/compile-fail/priv_in_pub_sig_priv_mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
mod a {
1515
struct Priv;
1616

17-
pub fn expose_a() -> Priv { //~Error: private type in exported type signature
17+
pub fn expose_a() -> Priv { //~Error: private type in public interface
1818
panic!();
1919
}
2020

2121
mod b {
22-
pub fn expose_b() -> super::Priv { //~Error: private type in exported type signature
22+
pub fn expose_b() -> super::Priv { //~Error: private type in public interface
2323
panic!();
2424
}
2525
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,52 +14,52 @@ trait Foo {
1414

1515
pub fn f<
1616
T
17-
: Foo //~ ERROR private trait in exported type parameter bound
17+
: Foo //~ ERROR private trait in public interface
1818
>() {}
1919

2020
pub fn g<T>() where
2121
T
22-
: Foo //~ ERROR private trait in exported type parameter bound
22+
: Foo //~ ERROR private trait in public interface
2323
{}
2424

2525
pub struct S;
2626

2727
impl S {
2828
pub fn f<
2929
T
30-
: Foo //~ ERROR private trait in exported type parameter bound
30+
: Foo //~ ERROR private trait in public interface
3131
>() {}
3232

3333
pub fn g<T>() where
3434
T
35-
: Foo //~ ERROR private trait in exported type parameter bound
35+
: Foo //~ ERROR private trait in public interface
3636
{}
3737
}
3838

3939
pub struct S1<
4040
T
41-
: Foo //~ ERROR private trait in exported type parameter bound
41+
: Foo //~ ERROR private trait in public interface
4242
> {
4343
x: T
4444
}
4545

4646
pub struct S2<T> where
4747
T
48-
: Foo //~ ERROR private trait in exported type parameter bound
48+
: Foo //~ ERROR private trait in public interface
4949
{
5050
x: T
5151
}
5252

5353
pub enum E1<
5454
T
55-
: Foo //~ ERROR private trait in exported type parameter bound
55+
: Foo //~ ERROR private trait in public interface
5656
> {
5757
V1(T)
5858
}
5959

6060
pub enum E2<T> where
6161
T
62-
: Foo //~ ERROR private trait in exported type parameter bound
62+
: Foo //~ ERROR private trait in public interface
6363
{
6464
V2(T)
6565
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ trait Foo {
1212
fn dummy(&self) { }
1313
}
1414

15-
pub trait Bar : Foo {} //~ ERROR private trait in exported type
15+
pub trait Bar : Foo {} //~ ERROR private trait in public interface
1616

1717
fn main() {}

0 commit comments

Comments
 (0)