diff options
| author | bors <bors@rust-lang.org> | 2013-10-19 14:01:10 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-10-19 14:01:10 -0700 |
| commit | 69e46f3aa922fa651fe53b36a295011c590f09e4 (patch) | |
| tree | 062d45c2883b19bf46fafa871ff42b39b654d5fd | |
| parent | 9d047cdead764ae33e19a7149286302560b000f2 (diff) | |
| parent | c18afcd83a810db6921841a30aa874f98fe18f12 (diff) | |
| download | rust-69e46f3aa922fa651fe53b36a295011c590f09e4.tar.gz rust-69e46f3aa922fa651fe53b36a295011c590f09e4.zip | |
auto merge of #9956 : sfackler/rust/more-more-visibility, r=alexcrichton
| -rw-r--r-- | src/librustc/middle/privacy.rs | 32 | ||||
| -rw-r--r-- | src/test/compile-fail/struct-variant-privacy.rs | 20 |
2 files changed, 39 insertions, 13 deletions
diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index b8c432c3f26..c502dac7db0 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -563,6 +563,20 @@ impl<'self> PrivacyVisitor<'self> { } } }; + let check_struct = |def: &@ast::struct_def| { + for f in def.fields.iter() { + match f.node.kind { + ast::named_field(_, ast::public) => { + tcx.sess.span_err(f.span, "unnecessary `pub` \ + visibility"); + } + ast::named_field(_, ast::private) => { + // Fields should really be private by default... + } + ast::named_field(*) | ast::unnamed_field => {} + } + } + }; match item.node { // implementations of traits don't need visibility qualifiers because // that's controlled by having the trait in scope. @@ -610,24 +624,16 @@ impl<'self> PrivacyVisitor<'self> { } ast::inherited => {} } - } - } - ast::item_struct(ref def, _) => { - for f in def.fields.iter() { - match f.node.kind { - ast::named_field(_, ast::public) => { - tcx.sess.span_err(f.span, "unnecessary `pub` \ - visibility"); - } - ast::named_field(_, ast::private) => { - // Fields should really be private by default... - } - ast::named_field(*) | ast::unnamed_field => {} + match v.node.kind { + ast::struct_variant_kind(ref s) => check_struct(s), + ast::tuple_variant_kind(*) => {} } } } + ast::item_struct(ref def, _) => check_struct(def), + ast::item_trait(_, _, ref methods) => { for m in methods.iter() { match *m { diff --git a/src/test/compile-fail/struct-variant-privacy.rs b/src/test/compile-fail/struct-variant-privacy.rs new file mode 100644 index 00000000000..f37e02be12c --- /dev/null +++ b/src/test/compile-fail/struct-variant-privacy.rs @@ -0,0 +1,20 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +#[feature(struct_variant)]; + +pub enum Foo { + Bar { + pub x: int, //~ ERROR unnecessary `pub` visibility + y: int, + priv z: int + } +} + +fn main() {} |
