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