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.
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.
11 #![allow(non_snake_case)]
13 register_long_diagnostics! {
16 A private trait was used on a public type parameter bound. Erroneous code
24 pub trait Bar : Foo {} // error: private trait in exported type parameter bound
25 pub struct Bar<T: Foo>(pub T); // same error
26 pub fn foo<T: Foo> (t: T) {} // same error
29 To solve this error, please ensure that the trait is also public and accessible
30 at the same level of the public functions or types which are bound on it.
34 pub trait Foo { // we set the Foo trait public
38 pub trait Bar : Foo {} // ok!
39 pub struct Bar<T: Foo>(pub T); // ok!
40 pub fn foo<T: Foo> (t: T) {} // ok!
45 A private type was used in an exported type signature. Erroneous code example:
51 pub fn bar() -> Bar { // error: private type in exported type signature
57 To solve this error, please ensure that the type is also public and accessible
58 at the same level of the public functions or types which use it. Example:
62 pub struct Bar(u32); // we set the Bar type public
64 pub fn bar() -> Bar { // ok!
72 The `pub` keyword was used inside a function. Erroneous code example:
76 pub struct Bar; // error: visibility has no effect inside functions
80 Since we cannot access items defined inside a function, the visibility of its
81 items does not impact outer code. So using the `pub` keyword in this context
86 The `pub` keyword was used inside a public enum. Erroneous code example:
90 pub Bar, // error: unnecessary `pub` visibility
94 Since the enum is already public, adding `pub` on one its elements is
111 A visibility qualifier was used when it was unnecessary. Erroneous code
121 pub impl Bar {} // error: unnecessary visibility qualifier
123 pub impl Foo for Bar { // error: unnecessary visibility qualifier
124 pub fn foo() {} // error: unnecessary visibility qualifier
128 To fix this error, please remove the visibility qualifier when it is not
138 // Directly implemented methods share the visibility of the type itself,
139 // so `pub` is unnecessary here
142 // Trait methods share the visibility of the trait, so `pub` is
143 // unnecessary in either case
144 pub impl Foo for Bar {
151 A tuple constructor was invoked while some of its fields are private. Erroneous
156 pub struct Foo(isize);
159 let f = Bar::Foo(0); // error: cannot invoke tuple struct constructor with
163 To solve this issue, please ensure that all of the fields of the tuple struct
164 are public. Alternatively, provide a new() method to the tuple struct to
165 construct it from a given inner value. Example:
169 pub struct Foo(pub isize); // we set its field to public
172 let f = Bar::Foo(0); // ok!
176 pub struct Foo(isize);
179 pub fn new(x: isize) {
185 let f = bar::Foo::new(1);
190 A struct constructor with private fields was invoked. Erroneous code example:
200 let f = Bar::Foo{ a: 0, b: 0 }; // error: field `b` of struct `Bar::Foo`
204 To fix this error, please ensure that all the fields of the struct, or
205 implement a function for easy instantiation. Examples:
211 pub b: isize, // we set `b` field public
215 let f = Bar::Foo{ a: 0, b: 0 }; // ok!
221 b: isize, // still private
225 pub fn new() -> Foo { // we create a method to instantiate `Foo`
231 let f = Bar::Foo::new(); // ok!