]> git.proxmox.com Git - rustc.git/blame - compiler/rustc_error_codes/src/error_codes/E0624.md
New upstream version 1.68.2+dfsg1
[rustc.git] / compiler / rustc_error_codes / src / error_codes / E0624.md
CommitLineData
60c5eb7d
XL
1A private item was used outside of its scope.
2
3Erroneous code example:
4
5```compile_fail,E0624
6mod inner {
7 pub struct Foo;
8
9 impl Foo {
10 fn method(&self) {}
11 }
12}
13
14let foo = inner::Foo;
15foo.method(); // error: method `method` is private
16```
17
18Two possibilities are available to solve this issue:
19
201. Only use the item in the scope it has been defined:
21
22```
23mod inner {
24 pub struct Foo;
25
26 impl Foo {
27 fn method(&self) {}
28 }
29
30 pub fn call_method(foo: &Foo) { // We create a public function.
31 foo.method(); // Which calls the item.
32 }
33}
34
35let foo = inner::Foo;
36inner::call_method(&foo); // And since the function is public, we can call the
37 // method through it.
38```
39
402. Make the item public:
41
42```
43mod inner {
44 pub struct Foo;
45
46 impl Foo {
47 pub fn method(&self) {} // It's now public.
48 }
49}
50
51let foo = inner::Foo;
52foo.method(); // Ok!
53```