提交 c83994e0 编写于 作者: B bors

auto merge of #13145 : alexcrichton/rust/flip-some-defaults, r=brson

This change prepares `rustc` to accept private fields by default. These changes will have to go through a snapshot before the rest of the changes can happen.
......@@ -1019,10 +1019,11 @@ pub fn get_struct_fields(intr: @IdentInterner, cdata: Cmd, id: ast::NodeId)
});
reader::tagged_docs(item, tag_item_unnamed_field, |an_item| {
let did = item_def_id(an_item, cdata);
let f = item_family(an_item);
result.push(ty::field_ty {
name: special_idents::unnamed_field.name,
id: did,
vis: ast::Inherited,
vis: struct_field_family_to_visibility(f),
});
true
});
......
......@@ -310,8 +310,9 @@ fn encode_struct_fields(ebml_w: &mut writer::Encoder,
encode_def_id(ebml_w, local_def(f.node.id));
ebml_w.end_tag();
}
UnnamedField => {
UnnamedField(vis) => {
ebml_w.start_tag(tag_item_unnamed_field);
encode_struct_field_family(ebml_w, vis);
encode_def_id(ebml_w, local_def(f.node.id));
ebml_w.end_tag();
}
......@@ -513,8 +514,7 @@ fn each_auxiliary_node_id(item: @Item, callback: |NodeId| -> bool) -> bool {
// If this is a newtype struct, return the constructor.
match struct_def.ctor_id {
Some(ctor_id) if struct_def.fields.len() > 0 &&
struct_def.fields.get(0).node.kind ==
ast::UnnamedField => {
struct_def.fields.get(0).node.kind.is_unnamed() => {
continue_ = callback(ctor_id);
}
_ => {}
......@@ -690,7 +690,7 @@ fn encode_info_for_struct(ecx: &EncodeContext,
for field in fields.iter() {
let (nm, vis) = match field.node.kind {
NamedField(nm, vis) => (nm, vis),
UnnamedField => (special_idents::unnamed_field, Inherited)
UnnamedField(vis) => (special_idents::unnamed_field, vis)
};
let id = field.node.id;
......
......@@ -1001,15 +1001,11 @@ fn check_sane_privacy(&self, item: &ast::Item) {
};
for f in def.fields.iter() {
match f.node.kind {
ast::NamedField(_, ast::Public) if public_def => {
tcx.sess.span_err(f.span, "unnecessary `pub` \
visibility");
}
ast::NamedField(_, ast::Private) if !public_def => {
tcx.sess.span_err(f.span, "unnecessary `priv` \
visibility");
}
ast::NamedField(..) | ast::UnnamedField => {}
ast::NamedField(..) | ast::UnnamedField(..) => {}
}
}
};
......@@ -1106,7 +1102,7 @@ fn check_all_inherited(&self, item: &ast::Item) {
for f in def.fields.iter() {
match f.node.kind {
ast::NamedField(_, p) => check_inherited(f.span, p),
ast::UnnamedField => {}
ast::UnnamedField(..) => {}
}
}
};
......
......@@ -3900,7 +3900,7 @@ pub fn from_ast_variant(cx: &ctxt,
let arg_names = fields.iter().map(|field| {
match field.node.kind {
NamedField(ident, _) => ident,
UnnamedField => cx.sess.bug(
UnnamedField(..) => cx.sess.bug(
"enum_variants: all fields in struct must have a name")
}
}).collect();
......@@ -4264,11 +4264,11 @@ fn struct_field_tys(fields: &[StructField]) -> Vec<field_ty> {
vis: visibility,
}
}
UnnamedField => {
UnnamedField(visibility) => {
field_ty {
name: syntax::parse::token::special_idents::unnamed_field.name,
id: ast_util::local_def(field.node.id),
vis: ast::Public,
vis: visibility,
}
}
}
......
......@@ -695,8 +695,7 @@ pub fn convert_struct(ccx: &CrateCtxt,
write_ty_to_tcx(tcx, ctor_id, selfty);
tcx.tcache.borrow_mut().insert(local_def(ctor_id), tpt);
} else if struct_def.fields.get(0).node.kind ==
ast::UnnamedField {
} else if struct_def.fields.get(0).node.kind.is_unnamed() {
// Tuple-like.
let inputs = struct_def.fields.map(
|field| tcx.tcache.borrow().get(
......
......@@ -1080,7 +1080,16 @@ pub struct StructField_ {
#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)]
pub enum StructFieldKind {
NamedField(Ident, Visibility),
UnnamedField // element of a tuple-like struct
UnnamedField(Visibility), // element of a tuple-like struct
}
impl StructFieldKind {
pub fn is_unnamed(&self) -> bool {
match *self {
UnnamedField(..) => true,
NamedField(..) => false,
}
}
}
#[deriving(Eq, TotalEq, Encodable, Decodable, Hash)]
......
......@@ -290,8 +290,7 @@ pub fn split_trait_methods(trait_methods: &[TraitMethod])
pub fn struct_field_visibility(field: ast::StructField) -> Visibility {
match field.node.kind {
ast::NamedField(_, visibility) => visibility,
ast::UnnamedField => ast::Public
ast::NamedField(_, v) | ast::UnnamedField(v) => v
}
}
......
......@@ -1007,7 +1007,7 @@ fn summarise_struct(&self,
let sp = self.set_expn_info(cx, field.span);
match field.node.kind {
ast::NamedField(ident, _) => named_idents.push((ident, sp)),
ast::UnnamedField => just_spans.push(sp),
ast::UnnamedField(..) => just_spans.push(sp),
}
}
......@@ -1061,8 +1061,8 @@ fn create_struct_pattern(&self,
struct_type = Record;
Some(ident)
}
ast::UnnamedField if (struct_type == Unknown ||
struct_type == Tuple) => {
ast::UnnamedField(..) if (struct_type == Unknown ||
struct_type == Tuple) => {
struct_type = Tuple;
None
}
......
......@@ -3985,7 +3985,7 @@ fn parse_item_struct(&mut self) -> ItemInfo {
let attrs = p.parse_outer_attributes();
let lo = p.span.lo;
let struct_field_ = ast::StructField_ {
kind: UnnamedField,
kind: UnnamedField(p.parse_visibility()),
id: ast::DUMMY_NODE_ID,
ty: p.parse_ty(false),
attrs: attrs,
......
......@@ -743,7 +743,8 @@ pub fn print_struct(&mut self,
|s, field| {
match field.node.kind {
ast::NamedField(..) => fail!("unexpected named field"),
ast::UnnamedField => {
ast::UnnamedField(vis) => {
try!(s.print_visibility(vis));
try!(s.maybe_print_comment(field.span.lo));
s.print_type(field.node.ty)
}
......@@ -762,7 +763,7 @@ pub fn print_struct(&mut self,
for field in struct_def.fields.iter() {
match field.node.kind {
ast::UnnamedField => fail!("unexpected unnamed field"),
ast::UnnamedField(..) => fail!("unexpected unnamed field"),
ast::NamedField(ident, visibility) => {
try!(self.hardbreak_if_not_bol());
try!(self.maybe_print_comment(field.span.lo));
......
......@@ -25,7 +25,7 @@ struct A {
pub struct B {
a: int,
priv b: int,
pub c: int, //~ ERROR: unnecessary `pub` visibility
pub c: int,
}
}
......
// 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() {}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册