From bda7ec0755e7eda62ff3e5d26365f6fd0cc7e4fb Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 9 Sep 2015 11:47:00 +0200 Subject: [PATCH] Add error code for enum item visibility error --- src/librustc_privacy/diagnostics.rs | 25 +++++++++++++++++++++++++ src/librustc_privacy/lib.rs | 6 ++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/librustc_privacy/diagnostics.rs b/src/librustc_privacy/diagnostics.rs index 2c6931fafdeeb..97933f1a8b0ea 100644 --- a/src/librustc_privacy/diagnostics.rs +++ b/src/librustc_privacy/diagnostics.rs @@ -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! +} +``` +"##, + } \ No newline at end of file diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 584fe21fae105..ab04f1201400d 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -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 @@ -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 => {}