Add new error code for visibility inside a function

This commit is contained in:
Guillaume Gomez 2015-09-09 11:15:33 +02:00
parent c4a3936327
commit 42e16223cf
2 changed files with 23 additions and 6 deletions

View file

@ -13,7 +13,8 @@
register_long_diagnostics! {
E0445: r##"
A private trait was used on a "public" type. Erroneous code example:
A private trait was used on a public type parameter bound. Erroneous code
examples:
```
trait Foo {
@ -23,8 +24,9 @@ trait Foo {
pub trait Bar : Foo {} // error: private trait in exported type parameter bound
```
To solve this error, please ensure the trait is accessible at the same level of
the type(s) on which it's implemented. Example:
To solve this error, please ensure that the trait is also public and accessible
at the same level of the public functions or types which are bound on it.
Example:
```
pub trait Foo { // we set the Foo trait public
@ -48,8 +50,8 @@ mod Foo {
}
```
To solve this error, please ensure the type is accessible at the same level of
the exported type signature. Example:
To solve this error, please ensure that the type is also public and accessible
at the same level of the public functions or types which use it. Example:
```
mod Foo {
@ -62,4 +64,18 @@ mod Foo {
```
"##,
E0447: r##"
The `pub` keyword was used inside a function. Erroneous code example:
```
fn foo() {
pub struct Bar; // error: visibility has no effect inside functions
}
```
Since we cannot access inside function's elements, the visibility of its
elements does not impact outer code. So using the `pub` keyword in this context
is invalid.
"##,
}

View file

@ -1098,7 +1098,8 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
let tcx = self.tcx;
fn check_inherited(tcx: &ty::ctxt, sp: Span, vis: hir::Visibility) {
if vis != hir::Inherited {
tcx.sess.span_err(sp, "visibility has no effect inside functions");
span_err!(tcx.sess, sp, E0447,
"visibility has no effect inside functions");
}
}
let check_struct = |def: &hir::StructDef| {