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