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
20 #![deny(private_in_public)]
26 pub trait Bar : Foo {} // error: private trait in public interface
27 pub struct Bar2<T: Foo>(pub T); // same error
28 pub fn foo<T: Foo> (t: T) {} // same error
31 To solve this error, please ensure that the trait is also public. The trait
32 can be made inaccessible if necessary by placing it into a private inner
33 module, but it still has to be marked with `pub`. Example:
36 pub trait Foo { // we set the Foo trait public
40 pub trait Bar : Foo {} // ok!
41 pub struct Bar2<T: Foo>(pub T); // ok!
42 pub fn foo<T: Foo> (t: T) {} // ok!
47 A private type was used in a public type signature. Erroneous code example:
50 #![deny(private_in_public)]
55 pub fn bar() -> Bar { // error: private type in public interface
61 To solve this error, please ensure that the type is also public. The type
62 can be made inaccessible if necessary by placing it into a private inner
63 module, but it still has to be marked with `pub`.
68 pub struct Bar(u32); // we set the Bar type public
70 pub fn bar() -> Bar { // ok!
78 The `pub` keyword was used inside a function. Erroneous code example:
82 pub struct Bar; // error: visibility has no effect inside functions
86 Since we cannot access items defined inside a function, the visibility of its
87 items does not impact outer code. So using the `pub` keyword in this context
92 The `pub` keyword was used inside a public enum. Erroneous code example:
96 pub Bar, // error: unnecessary `pub` visibility
100 Since the enum is already public, adding `pub` on one its elements is
101 unnecessary. Example:
109 This is the correct syntax:
119 A struct constructor with private fields was invoked. Erroneous code example:
121 ```compile_fail,E0451
129 let f = Bar::Foo{ a: 0, b: 0 }; // error: field `b` of struct `Bar::Foo`
133 To fix this error, please ensure that all the fields of the struct are public,
134 or implement a function for easy instantiation. Examples:
140 pub b: isize, // we set `b` field public
144 let f = Bar::Foo{ a: 0, b: 0 }; // ok!
153 b: isize, // still private
157 pub fn new() -> Foo { // we create a method to instantiate `Foo`
163 let f = Bar::Foo::new(); // ok!
169 register_diagnostics! {
170 // E0450, moved into resolve