syntax: Permit visibility on tuple fields
This change is in preparation for #8122. Nothing is currently done with these visibility qualifiers, they are just parsed and accepted by the compiler. RFC: 0004-private-fields
This commit is contained in:
parent
104aaa44e8
commit
7de48419ee
10 changed files with 30 additions and 21 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -1005,7 +1005,7 @@ impl<'a> SanePrivacyVisitor<'a> {
|
|||
tcx.sess.span_err(f.span, "unnecessary `priv` \
|
||||
visibility");
|
||||
}
|
||||
ast::NamedField(..) | ast::UnnamedField => {}
|
||||
ast::NamedField(..) | ast::UnnamedField(..) => {}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -1102,7 +1102,7 @@ impl<'a> SanePrivacyVisitor<'a> {
|
|||
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 @@ impl VariantInfo {
|
|||
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 type StructField = Spanned<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 @@ impl<'a> TraitDef<'a> {
|
|||
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 @@ impl<'a> TraitDef<'a> {
|
|||
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 @@ impl<'a> Parser<'a> {
|
|||
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 @@ impl<'a> State<'a> {
|
|||
|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 @@ impl<'a> State<'a> {
|
|||
|
||||
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));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue