Skip to content

Commit

Permalink
Add new error code for visibility inside a function
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Sep 9, 2015
1 parent c4a3936 commit 42e1622
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
26 changes: 21 additions & 5 deletions src/librustc_privacy/diagnostics.rs
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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.
"##,

}
3 changes: 2 additions & 1 deletion src/librustc_privacy/lib.rs
Expand Up @@ -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| {
Expand Down

0 comments on commit 42e1622

Please sign in to comment.