1 register_long_diagnostics! {
4 A private trait was used on a public type parameter bound. Erroneous code
8 #![deny(private_in_public)]
14 pub trait Bar : Foo {} // error: private trait in public interface
15 pub struct Bar2<T: Foo>(pub T); // same error
16 pub fn foo<T: Foo> (t: T) {} // same error
19 To solve this error, please ensure that the trait is also public. The trait
20 can be made inaccessible if necessary by placing it into a private inner
21 module, but it still has to be marked with `pub`. Example:
24 pub trait Foo { // we set the Foo trait public
28 pub trait Bar : Foo {} // ok!
29 pub struct Bar2<T: Foo>(pub T); // ok!
30 pub fn foo<T: Foo> (t: T) {} // ok!
35 A private type was used in a public type signature. Erroneous code example:
38 #![deny(private_in_public)]
43 pub fn bar() -> Bar { // error: private type in public interface
49 To solve this error, please ensure that the type is also public. The type
50 can be made inaccessible if necessary by placing it into a private inner
51 module, but it still has to be marked with `pub`.
56 pub struct Bar(u32); // we set the Bar type public
58 pub fn bar() -> Bar { // ok!
66 #### Note: this error code is no longer emitted by the compiler.
68 The `pub` keyword was used inside a function. Erroneous code example:
72 pub struct Bar; // error: visibility has no effect inside functions
76 Since we cannot access items defined inside a function, the visibility of its
77 items does not impact outer code. So using the `pub` keyword in this context
82 The `pub` keyword was used inside a public enum. Erroneous code example:
86 pub Bar, // error: unnecessary `pub` visibility
90 Since the enum is already public, adding `pub` on one its elements is
99 This is the correct syntax:
109 A struct constructor with private fields was invoked. Erroneous code example:
111 ```compile_fail,E0451
119 let f = Bar::Foo{ a: 0, b: 0 }; // error: field `b` of struct `Bar::Foo`
123 To fix this error, please ensure that all the fields of the struct are public,
124 or implement a function for easy instantiation. Examples:
130 pub b: isize, // we set `b` field public
134 let f = Bar::Foo{ a: 0, b: 0 }; // ok!
143 b: isize, // still private
147 pub fn new() -> Foo { // we create a method to instantiate `Foo`
153 let f = Bar::Foo::new(); // ok!
159 register_diagnostics! {
160 // E0450, moved into resolve