]> git.lizzy.rs Git - rust.git/blob - src/librustc_privacy/error_codes.rs
Simplify SaveHandler trait
[rust.git] / src / librustc_privacy / error_codes.rs
1 #![allow(non_snake_case)]
2
3 register_long_diagnostics! {
4
5 E0445: r##"
6 A private trait was used on a public type parameter bound. Erroneous code
7 examples:
8
9 ```compile_fail,E0445
10 #![deny(private_in_public)]
11
12 trait Foo {
13     fn dummy(&self) { }
14 }
15
16 pub trait Bar : Foo {} // error: private trait in public interface
17 pub struct Bar2<T: Foo>(pub T); // same error
18 pub fn foo<T: Foo> (t: T) {} // same error
19 ```
20
21 To solve this error, please ensure that the trait is also public. The trait
22 can be made inaccessible if necessary by placing it into a private inner
23 module, but it still has to be marked with `pub`. Example:
24
25 ```
26 pub trait Foo { // we set the Foo trait public
27     fn dummy(&self) { }
28 }
29
30 pub trait Bar : Foo {} // ok!
31 pub struct Bar2<T: Foo>(pub T); // ok!
32 pub fn foo<T: Foo> (t: T) {} // ok!
33 ```
34 "##,
35
36 E0446: r##"
37 A private type was used in a public type signature. Erroneous code example:
38
39 ```compile_fail,E0446
40 #![deny(private_in_public)]
41
42 mod Foo {
43     struct Bar(u32);
44
45     pub fn bar() -> Bar { // error: private type in public interface
46         Bar(0)
47     }
48 }
49 ```
50
51 To solve this error, please ensure that the type is also public. The type
52 can be made inaccessible if necessary by placing it into a private inner
53 module, but it still has to be marked with `pub`.
54 Example:
55
56 ```
57 mod Foo {
58     pub struct Bar(u32); // we set the Bar type public
59
60     pub fn bar() -> Bar { // ok!
61         Bar(0)
62     }
63 }
64 ```
65 "##,
66
67 E0447: r##"
68 #### Note: this error code is no longer emitted by the compiler.
69
70 The `pub` keyword was used inside a function. Erroneous code example:
71
72 ```
73 fn foo() {
74     pub struct Bar; // error: visibility has no effect inside functions
75 }
76 ```
77
78 Since we cannot access items defined inside a function, the visibility of its
79 items does not impact outer code. So using the `pub` keyword in this context
80 is invalid.
81 "##,
82
83 E0448: r##"
84 The `pub` keyword was used inside a public enum. Erroneous code example:
85
86 ```compile_fail
87 pub enum Foo {
88     pub Bar, // error: unnecessary `pub` visibility
89 }
90 ```
91
92 Since the enum is already public, adding `pub` on one its elements is
93 unnecessary. Example:
94
95 ```compile_fail
96 enum Foo {
97     pub Bar, // not ok!
98 }
99 ```
100
101 This is the correct syntax:
102
103 ```
104 pub enum Foo {
105     Bar, // ok!
106 }
107 ```
108 "##,
109
110 E0451: r##"
111 A struct constructor with private fields was invoked. Erroneous code example:
112
113 ```compile_fail,E0451
114 mod Bar {
115     pub struct Foo {
116         pub a: isize,
117         b: isize,
118     }
119 }
120
121 let f = Bar::Foo{ a: 0, b: 0 }; // error: field `b` of struct `Bar::Foo`
122                                 //        is private
123 ```
124
125 To fix this error, please ensure that all the fields of the struct are public,
126 or implement a function for easy instantiation. Examples:
127
128 ```
129 mod Bar {
130     pub struct Foo {
131         pub a: isize,
132         pub b: isize, // we set `b` field public
133     }
134 }
135
136 let f = Bar::Foo{ a: 0, b: 0 }; // ok!
137 ```
138
139 Or:
140
141 ```
142 mod Bar {
143     pub struct Foo {
144         pub a: isize,
145         b: isize, // still private
146     }
147
148     impl Foo {
149         pub fn new() -> Foo { // we create a method to instantiate `Foo`
150             Foo { a: 0, b: 0 }
151         }
152     }
153 }
154
155 let f = Bar::Foo::new(); // ok!
156 ```
157 "##,
158
159 }
160
161 register_diagnostics! {
162 //  E0450, moved into resolve
163 }