]> git.lizzy.rs Git - rust.git/blob - src/librustc_privacy/error_codes.rs
Update to use new librustc_error_codes library
[rust.git] / src / librustc_privacy / error_codes.rs
1 syntax::register_diagnostics! {
2
3 E0445: r##"
4 A private trait was used on a public type parameter bound.
5
6 Erroneous code examples:
7
8 ```compile_fail,E0445
9 #![deny(private_in_public)]
10
11 trait Foo {
12     fn dummy(&self) { }
13 }
14
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
18 ```
19
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:
23
24 ```
25 pub trait Foo { // we set the Foo trait public
26     fn dummy(&self) { }
27 }
28
29 pub trait Bar : Foo {} // ok!
30 pub struct Bar2<T: Foo>(pub T); // ok!
31 pub fn foo<T: Foo> (t: T) {} // ok!
32 ```
33 "##,
34
35 E0446: r##"
36 A private type was used in a public type signature.
37
38 Erroneous code example:
39
40 ```compile_fail,E0446
41 #![deny(private_in_public)]
42
43 mod Foo {
44     struct Bar(u32);
45
46     pub fn bar() -> Bar { // error: private type in public interface
47         Bar(0)
48     }
49 }
50 ```
51
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`.
55 Example:
56
57 ```
58 mod Foo {
59     pub struct Bar(u32); // we set the Bar type public
60
61     pub fn bar() -> Bar { // ok!
62         Bar(0)
63     }
64 }
65 ```
66 "##,
67
68 E0447: r##"
69 #### Note: this error code is no longer emitted by the compiler.
70
71 The `pub` keyword was used inside a function.
72
73 Erroneous code example:
74
75 ```
76 fn foo() {
77     pub struct Bar; // error: visibility has no effect inside functions
78 }
79 ```
80
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
83 is invalid.
84 "##,
85
86 E0448: r##"
87 #### Note: this error code is no longer emitted by the compiler.
88
89 The `pub` keyword was used inside a public enum.
90
91 Erroneous code example:
92
93 ```compile_fail
94 pub enum Foo {
95     pub Bar, // error: unnecessary `pub` visibility
96 }
97 ```
98
99 Since the enum is already public, adding `pub` on one its elements is
100 unnecessary. Example:
101
102 ```compile_fail
103 enum Foo {
104     pub Bar, // not ok!
105 }
106 ```
107
108 This is the correct syntax:
109
110 ```
111 pub enum Foo {
112     Bar, // ok!
113 }
114 ```
115 "##,
116
117 E0451: r##"
118 A struct constructor with private fields was invoked.
119
120 Erroneous code example:
121
122 ```compile_fail,E0451
123 mod Bar {
124     pub struct Foo {
125         pub a: isize,
126         b: isize,
127     }
128 }
129
130 let f = Bar::Foo{ a: 0, b: 0 }; // error: field `b` of struct `Bar::Foo`
131                                 //        is private
132 ```
133
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:
136
137 ```
138 mod Bar {
139     pub struct Foo {
140         pub a: isize,
141         pub b: isize, // we set `b` field public
142     }
143 }
144
145 let f = Bar::Foo{ a: 0, b: 0 }; // ok!
146 ```
147
148 Or:
149
150 ```
151 mod Bar {
152     pub struct Foo {
153         pub a: isize,
154         b: isize, // still private
155     }
156
157     impl Foo {
158         pub fn new() -> Foo { // we create a method to instantiate `Foo`
159             Foo { a: 0, b: 0 }
160         }
161     }
162 }
163
164 let f = Bar::Foo::new(); // ok!
165 ```
166 "##,
167
168 //  E0450, moved into resolve
169 }