about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2015-09-09 11:15:33 +0200
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2015-09-09 11:25:32 +0200
commit42e16223cfbe9fc1ee22cde8e698914eaf8dab55 (patch)
treed028e8cecc32041ad47413d3bde2171560bd2837
parentc4a3936327f2f1082e3ac52e3dc7b250e3a04506 (diff)
downloadrust-42e16223cfbe9fc1ee22cde8e698914eaf8dab55.tar.gz
rust-42e16223cfbe9fc1ee22cde8e698914eaf8dab55.zip
Add new error code for visibility inside a function
-rw-r--r--src/librustc_privacy/diagnostics.rs26
-rw-r--r--src/librustc_privacy/lib.rs3
2 files changed, 23 insertions, 6 deletions
diff --git a/src/librustc_privacy/diagnostics.rs b/src/librustc_privacy/diagnostics.rs
index cdd6af2d13d..2c6931fafde 100644
--- a/src/librustc_privacy/diagnostics.rs
+++ b/src/librustc_privacy/diagnostics.rs
@@ -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.
+"##,
+
 }
\ No newline at end of file
diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs
index 7b14ef134eb..584fe21fae1 100644
--- a/src/librustc_privacy/lib.rs
+++ b/src/librustc_privacy/lib.rs
@@ -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| {