Skip to content

Commit

Permalink
Update error messages and error descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Dec 18, 2015
1 parent 26a2f85 commit f8ae31f
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 41 deletions.
17 changes: 10 additions & 7 deletions src/librustc_privacy/diagnostics.rs
Expand Up @@ -21,13 +21,14 @@ trait Foo {
fn dummy(&self) { }
}
pub trait Bar : Foo {} // error: private trait in exported type parameter bound
pub trait Bar : Foo {} // error: private trait in public interface
pub struct Bar<T: Foo>(pub T); // same error
pub fn foo<T: Foo> (t: T) {} // same error
```
To solve this error, please ensure that the trait is also public and accessible
at the same level of the public functions or types which are bound on it.
To solve this error, please ensure that the trait is also public. The trait
can be made inaccessible if necessary by placing it into a private inner module,
but it still has to be marked with `pub`.
Example:
```
Expand All @@ -42,20 +43,22 @@ pub fn foo<T: Foo> (t: T) {} // ok!
"##,

E0446: r##"
A private type was used in an exported type signature. Erroneous code example:
A private type was used in an public type signature. Erroneous code example:
```
mod Foo {
struct Bar(u32);
pub fn bar() -> Bar { // error: private type in exported type signature
pub fn bar() -> Bar { // error: private type in public interface
Bar(0)
}
}
```
To solve this error, please ensure that the type is also public and accessible
at the same level of the public functions or types which use it. Example:
To solve this error, please ensure that the type is also public. The type
can be made inaccessible if necessary by placing it into a private inner module,
but it still has to be marked with `pub`.
Example:
```
mod Foo {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_privacy/lib.rs
Expand Up @@ -1136,7 +1136,7 @@ impl<'a, 'tcx: 'a, 'v> Visitor<'v> for SearchInterfaceForPrivateItemsVisitor<'a,
if item.vis != hir::Public {
if !self.is_quiet {
span_err!(self.tcx.sess, ty.span, E0446,
"private type in exported type signature");
"private type in public interface");
}
self.is_public = false;
}
Expand All @@ -1162,7 +1162,7 @@ impl<'a, 'tcx: 'a, 'v> Visitor<'v> for SearchInterfaceForPrivateItemsVisitor<'a,
if item.vis != hir::Public {
if !self.is_quiet {
span_err!(self.tcx.sess, trait_ref.path.span, E0445,
"private trait in exported type parameter bound");
"private trait in public interface");
}
self.is_public = false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-18389.rs
Expand Up @@ -14,7 +14,7 @@ use std::any::TypeId;
trait Private<P, R> {
fn call(&self, p: P, r: R);
}
pub trait Public: Private< //~ ERROR private trait in exported type parameter bound
pub trait Public: Private< //~ ERROR private trait in public interface
<Self as Public>::P,
<Self as Public>::R
> {
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-22912.rs
Expand Up @@ -20,7 +20,7 @@ trait PrivateTrait {
}

impl PublicTrait for PublicType {
type Item = PrivateType; //~ ERROR private type in exported type signature
type Item = PrivateType; //~ ERROR private type in public interface
}

// OK
Expand Down
6 changes: 3 additions & 3 deletions src/test/compile-fail/issue-28325.rs
Expand Up @@ -16,7 +16,7 @@ mod y {
struct Bar { x: u32 }

impl Foo {
pub fn foo(&self, x: Self, y: Bar) { } //~ ERROR private type in exported type signature
pub fn foo(&self, x: Self, y: Bar) { } //~ ERROR private type in public interface
}
}

Expand All @@ -26,9 +26,9 @@ mod x {
struct Bar { _x: u32 }

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

Expand Down
10 changes: 5 additions & 5 deletions src/test/compile-fail/issue-28450.rs
Expand Up @@ -15,21 +15,21 @@ struct Priv;
pub use self::private::public;

mod private {
pub type Priv = super::Priv; //~ ERROR private type in exported type signature
pub type Priv = super::Priv; //~ ERROR private type in public interface

pub fn public(_x: Priv) {
}
}

struct __CFArray;
pub type CFArrayRef = *const __CFArray; //~ ERROR private type in exported type signature
pub type CFArrayRef = *const __CFArray; //~ ERROR private type in public interface
trait Pointer { type Pointee; }
impl<T> Pointer for *const T { type Pointee = T; }
pub type __CFArrayRevealed = <CFArrayRef as Pointer>::Pointee;
//~^ ERROR private type in exported type signature
//~^ ERROR private type in public interface

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

pub trait Exporter {
type Output;
Expand All @@ -43,7 +43,7 @@ pub fn block() -> <Helper as Exporter>::Output {
}

impl Exporter for Helper {
type Output = Inner; //~ ERROR private type in exported type signature
type Output = Inner; //~ ERROR private type in public interface
}

Inner
Expand Down
22 changes: 11 additions & 11 deletions src/test/compile-fail/lint-visible-private-types.rs
Expand Up @@ -36,17 +36,17 @@ impl Public<Private<isize>> {
fn d() -> Private<isize> { panic!() }
}
impl Public<isize> {
pub fn e(&self) -> Private<isize> { panic!() } //~ ERROR private type in exported type signature
pub fn e(&self) -> Private<isize> { panic!() } //~ ERROR private type in public interface
fn f(&self) -> Private<isize> { panic!() }
}

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

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


pub struct Foo {
pub x: Private<isize>, //~ ERROR private type in exported type signature
pub x: Private<isize>, //~ ERROR private type in public interface
y: Private<isize>
}

Expand All @@ -55,9 +55,9 @@ struct Bar {
}

pub enum Baz {
Baz1(Private<isize>), //~ ERROR private type in exported type signature
Baz1(Private<isize>), //~ ERROR private type in public interface
Baz2 {
y: Private<isize> //~ ERROR private type in exported type signature
y: Private<isize> //~ ERROR private type in public interface
},
}

Expand All @@ -69,14 +69,14 @@ enum Qux {
}

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

impl PubTrait for Public<isize> {
fn bar(&self) -> Private<isize> { panic!() } //~ ERROR private type in exported type signature
fn baz() -> Private<isize> { panic!() } //~ ERROR private type in exported type signature
fn bar(&self) -> Private<isize> { panic!() } //~ ERROR private type in public interface
fn baz() -> Private<isize> { panic!() } //~ ERROR private type in public interface
}
impl PubTrait for Public<Private<isize>> {
fn bar(&self) -> Private<isize> { panic!() }
Expand Down Expand Up @@ -117,7 +117,7 @@ impl ParamTrait<Private<isize>> for Private<isize> {
fn foo() -> Private<isize> { panic!( )}
}

impl<T: ParamTrait<Private<isize>>> //~ ERROR private type in exported type signature
impl<T: ParamTrait<Private<isize>>> //~ ERROR private type in public interface
ParamTrait<T> for Public<i8> {
fn foo() -> T { panic!() }
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/priv_in_pub_sig_priv_mod.rs
Expand Up @@ -14,12 +14,12 @@
mod a {
struct Priv;

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

mod b {
pub fn expose_b() -> super::Priv { //~Error: private type in exported type signature
pub fn expose_b() -> super::Priv { //~Error: private type in public interface
panic!();
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/test/compile-fail/visible-private-types-generics.rs
Expand Up @@ -14,52 +14,52 @@ trait Foo {

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

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

pub struct S;

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

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

pub struct S1<
T
: Foo //~ ERROR private trait in exported type parameter bound
: Foo //~ ERROR private trait in public interface
> {
x: T
}

pub struct S2<T> where
T
: Foo //~ ERROR private trait in exported type parameter bound
: Foo //~ ERROR private trait in public interface
{
x: T
}

pub enum E1<
T
: Foo //~ ERROR private trait in exported type parameter bound
: Foo //~ ERROR private trait in public interface
> {
V1(T)
}

pub enum E2<T> where
T
: Foo //~ ERROR private trait in exported type parameter bound
: Foo //~ ERROR private trait in public interface
{
V2(T)
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/visible-private-types-supertrait.rs
Expand Up @@ -12,6 +12,6 @@ trait Foo {
fn dummy(&self) { }
}

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

fn main() {}

0 comments on commit f8ae31f

Please sign in to comment.