Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Visibility field from enum variants #28442

Merged
merged 3 commits into from
Sep 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/librustc_front/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ pub fn noop_fold_foreign_mod<T: Folder>(ForeignMod {abi, items}: ForeignMod,
}

pub fn noop_fold_variant<T: Folder>(v: P<Variant>, fld: &mut T) -> P<Variant> {
v.map(|Spanned {node: Variant_ {id, name, attrs, kind, disr_expr, vis}, span}| Spanned {
v.map(|Spanned {node: Variant_ {id, name, attrs, kind, disr_expr}, span}| Spanned {
node: Variant_ {
id: fld.new_id(id),
name: name,
Expand All @@ -430,7 +430,6 @@ pub fn noop_fold_variant<T: Folder>(v: P<Variant>, fld: &mut T) -> P<Variant> {
}
},
disr_expr: disr_expr.map(|e| fld.fold_expr(e)),
vis: vis,
},
span: fld.new_span(span),
})
Expand Down
1 change: 0 additions & 1 deletion src/librustc_front/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,6 @@ pub struct Variant_ {
pub id: NodeId,
/// Explicit discriminant, eg `Foo = 1`
pub disr_expr: Option<P<Expr>>,
pub vis: Visibility,
}

pub type Variant = Spanned<Variant_>;
Expand Down
1 change: 0 additions & 1 deletion src/librustc_front/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ pub fn lower_variant(v: &Variant) -> P<hir::Variant> {
}
},
disr_expr: v.node.disr_expr.as_ref().map(|e| lower_expr(e)),
vis: lower_visibility(v.node.vis),
},
span: v.span,
})
Expand Down
1 change: 0 additions & 1 deletion src/librustc_front/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,6 @@ impl<'a> State<'a> {
}

pub fn print_variant(&mut self, v: &hir::Variant) -> io::Result<()> {
try!(self.print_visibility(v.node.vis));
match v.node.kind {
hir::TupleVariantKind(ref args) => {
try!(self.print_ident(v.node.name));
Expand Down
21 changes: 2 additions & 19 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,20 +1075,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
instead");
}

hir::ItemEnum(ref def, _) => {
for v in &def.variants {
match v.node.vis {
hir::Public => {
if item.vis == hir::Public {
span_err!(tcx.sess, v.span, E0448,
"unnecessary `pub` visibility");
}
}
hir::Inherited => {}
}
}
}

hir::ItemEnum(..) |
hir::ItemTrait(..) | hir::ItemDefaultImpl(..) |
hir::ItemConst(..) | hir::ItemStatic(..) | hir::ItemStruct(..) |
hir::ItemFn(..) | hir::ItemMod(..) | hir::ItemTy(..) |
Expand Down Expand Up @@ -1131,14 +1118,10 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
check_inherited(tcx, i.span, i.vis);
}
}
hir::ItemEnum(ref def, _) => {
for v in &def.variants {
check_inherited(tcx, v.span, v.node.vis);
}
}

hir::ItemStruct(ref def, _) => check_struct(&**def),

hir::ItemEnum(..) |
hir::ItemExternCrate(_) | hir::ItemUse(_) |
hir::ItemTrait(..) | hir::ItemDefaultImpl(..) |
hir::ItemStatic(..) | hir::ItemConst(..) |
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1850,7 +1850,7 @@ impl Clean<Item> for doctree::Variant {
name: Some(self.name.clean(cx)),
attrs: self.attrs.clean(cx),
source: self.whence.clean(cx),
visibility: self.vis.clean(cx),
visibility: None,
stability: self.stab.clean(cx),
def_id: DefId::local(self.id),
inner: VariantItem(Variant {
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/doctree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ pub struct Variant {
pub attrs: Vec<ast::Attribute>,
pub kind: hir::VariantKind,
pub id: ast::NodeId,
pub vis: hir::Visibility,
pub stab: Option<attr::Stability>,
pub whence: Span,
}
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
variants: def.variants.iter().map(|v| Variant {
name: v.node.name,
attrs: v.node.attrs.clone(),
vis: v.node.vis,
stab: self.stability(v.node.id),
id: v.node.id,
kind: v.node.kind.clone(),
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,6 @@ pub struct Variant_ {
pub id: NodeId,
/// Explicit discriminant, eg `Foo = 1`
pub disr_expr: Option<P<Expr>>,
pub vis: Visibility,
}

pub type Variant = Spanned<Variant_>;
Expand Down
3 changes: 1 addition & 2 deletions src/libsyntax/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn fold_item_underscore<F>(cx: &mut Context<F>, item: ast::Item_) -> ast::Item_
None
} else {
Some(v.map(|Spanned {node: ast::Variant_ {id, name, attrs, kind,
disr_expr, vis}, span}| {
disr_expr}, span}| {
Spanned {
node: ast::Variant_ {
id: id,
Expand All @@ -154,7 +154,6 @@ fn fold_item_underscore<F>(cx: &mut Context<F>, item: ast::Item_) -> ast::Item_
}
},
disr_expr: disr_expr,
vis: vis
},
span: span
}
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,6 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
kind: ast::TupleVariantKind(args),
id: ast::DUMMY_NODE_ID,
disr_expr: None,
vis: ast::Public
})
}

Expand Down
3 changes: 1 addition & 2 deletions src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ pub fn noop_fold_foreign_mod<T: Folder>(ForeignMod {abi, items}: ForeignMod,
}

pub fn noop_fold_variant<T: Folder>(v: P<Variant>, fld: &mut T) -> P<Variant> {
v.map(|Spanned {node: Variant_ {id, name, attrs, kind, disr_expr, vis}, span}| Spanned {
v.map(|Spanned {node: Variant_ {id, name, attrs, kind, disr_expr}, span}| Spanned {
node: Variant_ {
id: fld.new_id(id),
name: name,
Expand All @@ -465,7 +465,6 @@ pub fn noop_fold_variant<T: Folder>(v: P<Variant>, fld: &mut T) -> P<Variant> {
}
},
disr_expr: disr_expr.map(|e| fld.fold_expr(e)),
vis: vis,
},
span: fld.new_span(span),
})
Expand Down
6 changes: 1 addition & 5 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5200,13 +5200,10 @@ impl<'a> Parser<'a> {
let variant_attrs = self.parse_outer_attributes();
let vlo = self.span.lo;

let vis = try!(self.parse_visibility());

let ident;
let kind;
let mut args = Vec::new();
let mut disr_expr = None;
ident = try!(self.parse_ident());
let ident = try!(self.parse_ident());
if try!(self.eat(&token::OpenDelim(token::Brace)) ){
// Parse a struct variant.
all_nullary = false;
Expand Down Expand Up @@ -5248,7 +5245,6 @@ impl<'a> Parser<'a> {
kind: kind,
id: ast::DUMMY_NODE_ID,
disr_expr: disr_expr,
vis: vis,
};
variants.push(P(spanned(vlo, self.last_span.hi, vr)));

Expand Down
4 changes: 1 addition & 3 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,6 @@ impl<'a> State<'a> {
}

pub fn print_variant(&mut self, v: &ast::Variant) -> io::Result<()> {
try!(self.print_visibility(v.node.vis));
match v.node.kind {
ast::TupleVariantKind(ref args) => {
try!(self.print_ident(v.node.name));
Expand Down Expand Up @@ -3139,11 +3138,10 @@ mod tests {
kind: ast::TupleVariantKind(Vec::new()),
id: 0,
disr_expr: None,
vis: ast::Public,
});

let varstr = variant_to_string(&var);
assert_eq!(varstr, "pub principal_skinner");
assert_eq!(varstr, "principal_skinner");
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -8,16 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use zoo::bird::{duck, goose};

mod zoo {
pub enum bird {
pub duck, //~ ERROR: unnecessary `pub` visibility
goose
}
enum bird {
pub duck,
//~^ ERROR: expected identifier, found keyword `pub`
//~^^ ERROR: expected
goose
}


fn main() {
let y = goose;
let y = bird::goose;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

struct A { pub i: isize }
pub enum C { pub Variant } //~ ERROR: unnecessary `pub`

pub trait E {
fn foo(&self);
Expand Down