Skip to content

Commit

Permalink
Add error code for enum item visibility error
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Sep 9, 2015
1 parent 42e1622 commit bda7ec0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/librustc_privacy/diagnostics.rs
Expand Up @@ -78,4 +78,29 @@ elements does not impact outer code. So using the `pub` keyword in this context
is invalid.
"##,

E0448: r##"
The `pub` keyword was used inside a public enum. Erroneous code example:
```
pub enum Foo {
pub Bar, // error: unnecessary `pub` visibility
}
```
Since the enum is already public, adding `pub` on one its elements is
unnecessary. Example:
```
enum Foo {
pub Bar, // ok!
}
// or:
pub enum Foo {
Bar, // ok!
}
```
"##,

}
6 changes: 4 additions & 2 deletions src/librustc_privacy/lib.rs
Expand Up @@ -50,6 +50,8 @@ use rustc::front::map as ast_map;
use syntax::ast;
use syntax::codemap::Span;

pub mod diagnostics;

type Context<'a, 'tcx> = (&'a ty::MethodMap<'tcx>, &'a def::ExportMap);

/// Result of a checking operation - None => no errors were found. Some => an
Expand Down Expand Up @@ -1076,8 +1078,8 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
match v.node.vis {
hir::Public => {
if item.vis == hir::Public {
tcx.sess.span_err(v.span, "unnecessary `pub` \
visibility");
span_err!(tcx.sess, v.span, E0448,
"unnecessary `pub` visibility");
}
}
hir::Inherited => {}
Expand Down

0 comments on commit bda7ec0

Please sign in to comment.