]> git.lizzy.rs Git - rust.git/blob - src/librustc_privacy/diagnostics.rs
Add error code for enum item visibility error
[rust.git] / src / librustc_privacy / diagnostics.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![allow(non_snake_case)]
12
13 register_long_diagnostics! {
14
15 E0445: r##"
16 A private trait was used on a public type parameter bound. Erroneous code
17 examples:
18
19 ```
20 trait Foo {
21     fn dummy(&self) { }
22 }
23
24 pub trait Bar : Foo {} // error: private trait in exported type parameter bound
25 ```
26
27 To solve this error, please ensure that the trait is also public and accessible
28 at the same level of the public functions or types which are bound on it.
29 Example:
30
31 ```
32 pub trait Foo { // we set the Foo trait public
33     fn dummy(&self) { }
34 }
35
36 pub trait Bar : Foo {} // ok!
37 ```
38 "##,
39
40 E0446: r##"
41 A private type was used in an exported type signature. Erroneous code example:
42
43 ```
44 mod Foo {
45     struct Bar(u32);
46
47     pub fn bar() -> Bar { // error: private type in exported type signature
48         Bar(0)
49     }
50 }
51 ```
52
53 To solve this error, please ensure that the type is also public and accessible
54 at the same level of the public functions or types which use it. 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 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 inside function's elements, the visibility of its
77 elements 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 ```
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 ```
94 enum Foo {
95     pub Bar, // ok!
96 }
97
98 // or:
99
100 pub enum Foo {
101     Bar, // ok!
102 }
103 ```
104 "##,
105
106 }