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 Bar2<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
31 module, but it still has to be marked with `pub`. Example:
34 pub trait Foo { // we set the Foo trait public
38 pub trait Bar : Foo {} // ok!
39 pub struct Bar2<T: Foo>(pub T); // ok!
40 pub fn foo<T: Foo> (t: T) {} // ok!
45 A private type was used in a public type signature. Erroneous code example:
51 pub fn bar() -> Bar { // error: private type in public interface
57 To solve this error, please ensure that the type is also public. The type
58 can be made inaccessible if necessary by placing it into a private inner
59 module, but it still has to be marked with `pub`.
64 pub struct Bar(u32); // we set the Bar type public
66 pub fn bar() -> Bar { // ok!
74 The `pub` keyword was used inside a function. Erroneous code example:
78 pub struct Bar; // error: visibility has no effect inside functions
82 Since we cannot access items defined inside a function, the visibility of its
83 items does not impact outer code. So using the `pub` keyword in this context
88 The `pub` keyword was used inside a public enum. Erroneous code example:
92 pub Bar, // error: unnecessary `pub` visibility
96 Since the enum is already public, adding `pub` on one its elements is
105 This is the correct syntax:
115 A visibility qualifier was used when it was unnecessary. Erroneous code
125 pub impl Bar {} // error: unnecessary visibility qualifier
127 pub impl Foo for Bar { // error: unnecessary visibility qualifier
128 pub fn foo() {} // error: unnecessary visibility qualifier
132 To fix this error, please remove the visibility qualifier when it is not
142 // Directly implemented methods share the visibility of the type itself,
143 // so `pub` is unnecessary here
146 // Trait methods share the visibility of the trait, so `pub` is
147 // unnecessary in either case
148 pub impl Foo for Bar {
155 A tuple constructor was invoked while some of its fields are private. Erroneous
160 pub struct Foo(isize);
163 let f = Bar::Foo(0); // error: cannot invoke tuple struct constructor with
167 To solve this issue, please ensure that all of the fields of the tuple struct
168 are public. Alternatively, provide a `new()` method to the tuple struct to
169 construct it from a given inner value. Example:
173 pub struct Foo(pub isize); // we set its field to public
176 let f = Bar::Foo(0); // ok!
180 pub struct Foo(isize);
183 pub fn new(x: isize) -> Foo {
189 let f = bar::Foo::new(1);
194 A struct constructor with private fields was invoked. Erroneous code example:
204 let f = Bar::Foo{ a: 0, b: 0 }; // error: field `b` of struct `Bar::Foo`
208 To fix this error, please ensure that all the fields of the struct, or
209 implement a function for easy instantiation. Examples:
215 pub b: isize, // we set `b` field public
219 let f = Bar::Foo{ a: 0, b: 0 }; // ok!
228 b: isize, // still private
232 pub fn new() -> Foo { // we create a method to instantiate `Foo`
238 let f = Bar::Foo::new(); // ok!