Skip to content

Commit c18afcd

Browse files
committed
Check unnecessary visibility for struct variants
1 parent 3a7337f commit c18afcd

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

src/librustc/middle/privacy.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,20 @@ impl<'self> PrivacyVisitor<'self> {
563563
}
564564
}
565565
};
566+
let check_struct = |def: &@ast::struct_def| {
567+
for f in def.fields.iter() {
568+
match f.node.kind {
569+
ast::named_field(_, ast::public) => {
570+
tcx.sess.span_err(f.span, "unnecessary `pub` \
571+
visibility");
572+
}
573+
ast::named_field(_, ast::private) => {
574+
// Fields should really be private by default...
575+
}
576+
ast::named_field(*) | ast::unnamed_field => {}
577+
}
578+
}
579+
};
566580
match item.node {
567581
// implementations of traits don't need visibility qualifiers because
568582
// that's controlled by having the trait in scope.
@@ -610,24 +624,16 @@ impl<'self> PrivacyVisitor<'self> {
610624
}
611625
ast::inherited => {}
612626
}
613-
}
614-
}
615627

616-
ast::item_struct(ref def, _) => {
617-
for f in def.fields.iter() {
618-
match f.node.kind {
619-
ast::named_field(_, ast::public) => {
620-
tcx.sess.span_err(f.span, "unnecessary `pub` \
621-
visibility");
622-
}
623-
ast::named_field(_, ast::private) => {
624-
// Fields should really be private by default...
625-
}
626-
ast::named_field(*) | ast::unnamed_field => {}
628+
match v.node.kind {
629+
ast::struct_variant_kind(ref s) => check_struct(s),
630+
ast::tuple_variant_kind(*) => {}
627631
}
628632
}
629633
}
630634

635+
ast::item_struct(ref def, _) => check_struct(def),
636+
631637
ast::item_trait(_, _, ref methods) => {
632638
for m in methods.iter() {
633639
match *m {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
#[feature(struct_variant)];
11+
12+
pub enum Foo {
13+
Bar {
14+
pub x: int, //~ ERROR unnecessary `pub` visibility
15+
y: int,
16+
priv z: int
17+
}
18+
}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)