1 syntax::register_diagnostics! {
4 A private trait was used on a public type parameter bound.
6 Erroneous code examples:
9 #![deny(private_in_public)]
15 pub trait Bar : Foo {} // error: private trait in public interface
16 pub struct Bar2<T: Foo>(pub T); // same error
17 pub fn foo<T: Foo> (t: T) {} // same error
20 To solve this error, please ensure that the trait is also public. The trait
21 can be made inaccessible if necessary by placing it into a private inner
22 module, but it still has to be marked with `pub`. Example:
25 pub trait Foo { // we set the Foo trait public
29 pub trait Bar : Foo {} // ok!
30 pub struct Bar2<T: Foo>(pub T); // ok!
31 pub fn foo<T: Foo> (t: T) {} // ok!
36 A private type was used in a public type signature.
38 Erroneous code example:
41 #![deny(private_in_public)]
46 pub fn bar() -> Bar { // error: private type in public interface
52 To solve this error, please ensure that the type is also public. The type
53 can be made inaccessible if necessary by placing it into a private inner
54 module, but it still has to be marked with `pub`.
59 pub struct Bar(u32); // we set the Bar type public
61 pub fn bar() -> Bar { // ok!
69 #### Note: this error code is no longer emitted by the compiler.
71 The `pub` keyword was used inside a function.
73 Erroneous code example:
77 pub struct Bar; // error: visibility has no effect inside functions
81 Since we cannot access items defined inside a function, the visibility of its
82 items does not impact outer code. So using the `pub` keyword in this context
87 #### Note: this error code is no longer emitted by the compiler.
89 The `pub` keyword was used inside a public enum.
91 Erroneous code example:
95 pub Bar, // error: unnecessary `pub` visibility
99 Since the enum is already public, adding `pub` on one its elements is
100 unnecessary. Example:
108 This is the correct syntax:
118 A struct constructor with private fields was invoked.
120 Erroneous code example:
122 ```compile_fail,E0451
130 let f = Bar::Foo{ a: 0, b: 0 }; // error: field `b` of struct `Bar::Foo`
134 To fix this error, please ensure that all the fields of the struct are public,
135 or implement a function for easy instantiation. Examples:
141 pub b: isize, // we set `b` field public
145 let f = Bar::Foo{ a: 0, b: 0 }; // ok!
154 b: isize, // still private
158 pub fn new() -> Foo { // we create a method to instantiate `Foo`
164 let f = Bar::Foo::new(); // ok!
168 // E0450, moved into resolve