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 public interface
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. The trait
30 can be made inaccessible if necessary by placing it into a private inner module,
31 but it still has to be marked with `pub`.
35 pub trait Foo { // we set the Foo trait public
39 pub trait Bar : Foo {} // ok!
40 pub struct Bar<T: Foo>(pub T); // ok!
41 pub fn foo<T: Foo> (t: T) {} // ok!
46 A private type was used in a public type signature. Erroneous code example:
52 pub fn bar() -> Bar { // error: private type in public interface
58 To solve this error, please ensure that the type is also public. The type
59 can be made inaccessible if necessary by placing it into a private inner module,
60 but it still has to be marked with `pub`.
65 pub struct Bar(u32); // we set the Bar type public
67 pub fn bar() -> Bar { // ok!
75 The `pub` keyword was used inside a function. Erroneous code example:
79 pub struct Bar; // error: visibility has no effect inside functions
83 Since we cannot access items defined inside a function, the visibility of its
84 items does not impact outer code. So using the `pub` keyword in this context
89 The `pub` keyword was used inside a public enum. Erroneous code example:
93 pub Bar, // error: unnecessary `pub` visibility
97 Since the enum is already public, adding `pub` on one its elements is
114 A visibility qualifier was used when it was unnecessary. Erroneous code
124 pub impl Bar {} // error: unnecessary visibility qualifier
126 pub impl Foo for Bar { // error: unnecessary visibility qualifier
127 pub fn foo() {} // error: unnecessary visibility qualifier
131 To fix this error, please remove the visibility qualifier when it is not
141 // Directly implemented methods share the visibility of the type itself,
142 // so `pub` is unnecessary here
145 // Trait methods share the visibility of the trait, so `pub` is
146 // unnecessary in either case
147 pub impl Foo for Bar {
154 A tuple constructor was invoked while some of its fields are private. Erroneous
159 pub struct Foo(isize);
162 let f = Bar::Foo(0); // error: cannot invoke tuple struct constructor with
166 To solve this issue, please ensure that all of the fields of the tuple struct
167 are public. Alternatively, provide a new() method to the tuple struct to
168 construct it from a given inner value. Example:
172 pub struct Foo(pub isize); // we set its field to public
175 let f = Bar::Foo(0); // ok!
179 pub struct Foo(isize);
182 pub fn new(x: isize) {
188 let f = bar::Foo::new(1);
193 A struct constructor with private fields was invoked. Erroneous code example:
203 let f = Bar::Foo{ a: 0, b: 0 }; // error: field `b` of struct `Bar::Foo`
207 To fix this error, please ensure that all the fields of the struct, or
208 implement a function for easy instantiation. Examples:
214 pub b: isize, // we set `b` field public
218 let f = Bar::Foo{ a: 0, b: 0 }; // ok!
224 b: isize, // still private
228 pub fn new() -> Foo { // we create a method to instantiate `Foo`
234 let f = Bar::Foo::new(); // ok!