Skip to content

Commit bda7ec0

Browse files
Add error code for enum item visibility error
1 parent 42e1622 commit bda7ec0

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/librustc_privacy/diagnostics.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,29 @@ elements does not impact outer code. So using the `pub` keyword in this context
7878
is invalid.
7979
"##,
8080

81+
E0448: r##"
82+
The `pub` keyword was used inside a public enum. Erroneous code example:
83+
84+
```
85+
pub enum Foo {
86+
pub Bar, // error: unnecessary `pub` visibility
87+
}
88+
```
89+
90+
Since the enum is already public, adding `pub` on one its elements is
91+
unnecessary. Example:
92+
93+
```
94+
enum Foo {
95+
pub Bar, // ok!
96+
}
97+
98+
// or:
99+
100+
pub enum Foo {
101+
Bar, // ok!
102+
}
103+
```
104+
"##,
105+
81106
}

src/librustc_privacy/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ use rustc::front::map as ast_map;
5050
use syntax::ast;
5151
use syntax::codemap::Span;
5252

53+
pub mod diagnostics;
54+
5355
type Context<'a, 'tcx> = (&'a ty::MethodMap<'tcx>, &'a def::ExportMap);
5456

5557
/// Result of a checking operation - None => no errors were found. Some => an
@@ -1076,8 +1078,8 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
10761078
match v.node.vis {
10771079
hir::Public => {
10781080
if item.vis == hir::Public {
1079-
tcx.sess.span_err(v.span, "unnecessary `pub` \
1080-
visibility");
1081+
span_err!(tcx.sess, v.span, E0448,
1082+
"unnecessary `pub` visibility");
10811083
}
10821084
}
10831085
hir::Inherited => {}

0 commit comments

Comments
 (0)