Get rid of hir::StructFieldKind
This commit is contained in:
parent
0400d929e8
commit
8b60b948d9
@ -151,7 +151,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
|
||||
self.create_def_with_parent(
|
||||
Some(variant_def_index),
|
||||
field.node.id,
|
||||
DefPathData::Field(field.node.kind));
|
||||
DefPathData::Field(field.node.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -166,7 +166,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
|
||||
}
|
||||
|
||||
for field in struct_def.fields() {
|
||||
self.create_def(field.node.id, DefPathData::Field(field.node.kind));
|
||||
self.create_def(field.node.id, DefPathData::Field(field.node.name));
|
||||
}
|
||||
}
|
||||
ItemTrait(_, _, ref bounds, _) => {
|
||||
|
@ -11,7 +11,6 @@
|
||||
use middle::cstore::LOCAL_CRATE;
|
||||
use middle::def_id::{DefId, DefIndex};
|
||||
use rustc_data_structures::fnv::FnvHashMap;
|
||||
use rustc_front::hir;
|
||||
use syntax::ast;
|
||||
use syntax::parse::token::InternedString;
|
||||
use util::nodemap::NodeMap;
|
||||
@ -84,8 +83,7 @@ pub enum DefPathData {
|
||||
TypeParam(ast::Name),
|
||||
LifetimeDef(ast::Name),
|
||||
EnumVariant(ast::Name),
|
||||
PositionalField,
|
||||
Field(hir::StructFieldKind),
|
||||
Field(Option<ast::Name>),
|
||||
StructCtor, // implicit ctor for a tuple-like struct
|
||||
Initializer, // initializer for a const
|
||||
Binding(ast::Name), // pattern binding
|
||||
@ -186,16 +184,12 @@ impl DefPathData {
|
||||
LifetimeDef(name) |
|
||||
EnumVariant(name) |
|
||||
DetachedCrate(name) |
|
||||
Binding(name) => {
|
||||
Binding(name) |
|
||||
Field(Some(name)) => {
|
||||
name.as_str()
|
||||
}
|
||||
|
||||
Field(hir::StructFieldKind::NamedField(name, _)) => {
|
||||
name.as_str()
|
||||
}
|
||||
|
||||
PositionalField |
|
||||
Field(hir::StructFieldKind::UnnamedField(_)) => {
|
||||
Field(None) => {
|
||||
InternedString::new("{{field}}")
|
||||
}
|
||||
|
||||
|
@ -221,10 +221,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
|
||||
let has_extern_repr = self.struct_has_extern_repr;
|
||||
let inherited_pub_visibility = self.inherited_pub_visibility;
|
||||
let live_fields = def.fields().iter().filter(|f| {
|
||||
has_extern_repr || inherited_pub_visibility || match f.node.kind {
|
||||
hir::NamedField(_, hir::Public) => true,
|
||||
_ => false
|
||||
}
|
||||
has_extern_repr || inherited_pub_visibility || f.node.vis == hir::Public
|
||||
});
|
||||
self.live_symbols.extend(live_fields.map(|f| f.node.id));
|
||||
|
||||
@ -432,7 +429,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn should_warn_about_field(&mut self, node: &hir::StructField_) -> bool {
|
||||
let is_named = node.name().is_some();
|
||||
let is_named = node.name.is_some();
|
||||
let field_type = self.tcx.node_id_to_type(node.id);
|
||||
let is_marker_field = match field_type.ty_to_def_id() {
|
||||
Some(def_id) => self.tcx.lang_items.items().iter().any(|item| *item == Some(def_id)),
|
||||
@ -549,7 +546,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
|
||||
fn visit_struct_field(&mut self, field: &hir::StructField) {
|
||||
if self.should_warn_about_field(&field.node) {
|
||||
self.warn_dead_code(field.node.id, field.span,
|
||||
field.node.name().unwrap(), "struct field");
|
||||
field.node.name.unwrap(), "struct field");
|
||||
}
|
||||
|
||||
intravisit::walk_struct_field(self, field);
|
||||
|
@ -700,11 +700,12 @@ pub fn noop_fold_poly_trait_ref<T: Folder>(p: PolyTraitRef, fld: &mut T) -> Poly
|
||||
}
|
||||
|
||||
pub fn noop_fold_struct_field<T: Folder>(f: StructField, fld: &mut T) -> StructField {
|
||||
let StructField {node: StructField_ {id, kind, ty, attrs}, span} = f;
|
||||
let StructField {node: StructField_ {id, name, vis, ty, attrs}, span} = f;
|
||||
Spanned {
|
||||
node: StructField_ {
|
||||
id: fld.new_id(id),
|
||||
kind: kind,
|
||||
name: name,
|
||||
vis: vis,
|
||||
ty: fld.fold_ty(ty),
|
||||
attrs: fold_attrs(attrs, fld),
|
||||
},
|
||||
|
@ -24,7 +24,6 @@ pub use self::Mutability::*;
|
||||
pub use self::PathListItem_::*;
|
||||
pub use self::PrimTy::*;
|
||||
pub use self::Stmt_::*;
|
||||
pub use self::StructFieldKind::*;
|
||||
pub use self::TraitItem_::*;
|
||||
pub use self::Ty_::*;
|
||||
pub use self::TyParamBound::*;
|
||||
@ -1243,44 +1242,45 @@ impl Visibility {
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct StructField_ {
|
||||
pub kind: StructFieldKind,
|
||||
pub name: Option<Name>,
|
||||
pub vis: Visibility,
|
||||
pub id: NodeId,
|
||||
pub ty: P<Ty>,
|
||||
pub attrs: HirVec<Attribute>,
|
||||
}
|
||||
|
||||
impl StructField_ {
|
||||
pub fn name(&self) -> Option<Name> {
|
||||
match self.kind {
|
||||
NamedField(name, _) => Some(name),
|
||||
UnnamedField(_) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
// impl StructField_ {
|
||||
// pub fn name(&self) -> Option<Name> {
|
||||
// match self.kind {
|
||||
// NamedField(name, _) => Some(name),
|
||||
// UnnamedField(_) => None,
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
pub type StructField = Spanned<StructField_>;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
||||
pub enum StructFieldKind {
|
||||
NamedField(Name, Visibility),
|
||||
/// Element of a tuple-like struct
|
||||
UnnamedField(Visibility),
|
||||
}
|
||||
// #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
|
||||
// pub enum StructFieldKind {
|
||||
// NamedField(Name, Visibility),
|
||||
// /// Element of a tuple-like struct
|
||||
// UnnamedField(Visibility),
|
||||
// }
|
||||
|
||||
impl StructFieldKind {
|
||||
pub fn is_unnamed(&self) -> bool {
|
||||
match *self {
|
||||
UnnamedField(..) => true,
|
||||
NamedField(..) => false,
|
||||
}
|
||||
}
|
||||
// impl StructFieldKind {
|
||||
// pub fn is_unnamed(&self) -> bool {
|
||||
// match *self {
|
||||
// UnnamedField(..) => true,
|
||||
// NamedField(..) => false,
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn visibility(&self) -> Visibility {
|
||||
match *self {
|
||||
NamedField(_, vis) | UnnamedField(vis) => vis,
|
||||
}
|
||||
}
|
||||
}
|
||||
// pub fn visibility(&self) -> Visibility {
|
||||
// match *self {
|
||||
// NamedField(_, vis) | UnnamedField(vis) => vis,
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
/// Fields and Ids of enum variants and structs
|
||||
///
|
||||
|
@ -669,7 +669,7 @@ pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, struct_definition: &
|
||||
}
|
||||
|
||||
pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, struct_field: &'v StructField) {
|
||||
walk_opt_name(visitor, struct_field.span, struct_field.node.name());
|
||||
walk_opt_name(visitor, struct_field.span, struct_field.node.name);
|
||||
visitor.visit_ty(&struct_field.node.ty);
|
||||
walk_list!(visitor, visit_attribute, &struct_field.node.attrs);
|
||||
}
|
||||
|
@ -611,7 +611,8 @@ pub fn lower_struct_field(lctx: &LoweringContext, f: &StructField) -> hir::Struc
|
||||
Spanned {
|
||||
node: hir::StructField_ {
|
||||
id: f.node.id,
|
||||
kind: lower_struct_field_kind(lctx, &f.node.kind),
|
||||
name: f.node.ident().map(|ident| ident.name),
|
||||
vis: lower_visibility(lctx, f.node.kind.visibility()),
|
||||
ty: lower_ty(lctx, &f.node.ty),
|
||||
attrs: lower_attrs(lctx, &f.node.attrs),
|
||||
},
|
||||
@ -1589,15 +1590,6 @@ pub fn lower_binding_mode(lctx: &LoweringContext, b: &BindingMode) -> hir::Bindi
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lower_struct_field_kind(lctx: &LoweringContext,
|
||||
s: &StructFieldKind)
|
||||
-> hir::StructFieldKind {
|
||||
match *s {
|
||||
NamedField(ident, vis) => hir::NamedField(ident.name, lower_visibility(lctx, vis)),
|
||||
UnnamedField(vis) => hir::UnnamedField(lower_visibility(lctx, vis)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lower_unsafe_source(_lctx: &LoweringContext, u: UnsafeSource) -> hir::UnsafeSource {
|
||||
match u {
|
||||
CompilerGenerated => hir::CompilerGenerated,
|
||||
|
@ -915,14 +915,9 @@ impl<'a> State<'a> {
|
||||
if struct_def.is_tuple() {
|
||||
try!(self.popen());
|
||||
try!(self.commasep(Inconsistent, struct_def.fields(), |s, field| {
|
||||
match field.node.kind {
|
||||
hir::NamedField(..) => panic!("unexpected named field"),
|
||||
hir::UnnamedField(vis) => {
|
||||
try!(s.print_visibility(vis));
|
||||
try!(s.maybe_print_comment(field.span.lo));
|
||||
s.print_type(&field.node.ty)
|
||||
}
|
||||
}
|
||||
try!(s.print_visibility(field.node.vis));
|
||||
try!(s.maybe_print_comment(field.span.lo));
|
||||
s.print_type(&field.node.ty)
|
||||
}));
|
||||
try!(self.pclose());
|
||||
}
|
||||
@ -939,19 +934,14 @@ impl<'a> State<'a> {
|
||||
try!(self.hardbreak_if_not_bol());
|
||||
|
||||
for field in struct_def.fields() {
|
||||
match field.node.kind {
|
||||
hir::UnnamedField(..) => panic!("unexpected unnamed field"),
|
||||
hir::NamedField(name, visibility) => {
|
||||
try!(self.hardbreak_if_not_bol());
|
||||
try!(self.maybe_print_comment(field.span.lo));
|
||||
try!(self.print_outer_attributes(&field.node.attrs));
|
||||
try!(self.print_visibility(visibility));
|
||||
try!(self.print_name(name));
|
||||
try!(self.word_nbsp(":"));
|
||||
try!(self.print_type(&field.node.ty));
|
||||
try!(word(&mut self.s, ","));
|
||||
}
|
||||
}
|
||||
try!(self.hardbreak_if_not_bol());
|
||||
try!(self.maybe_print_comment(field.span.lo));
|
||||
try!(self.print_outer_attributes(&field.node.attrs));
|
||||
try!(self.print_visibility(field.node.vis));
|
||||
try!(self.print_name(field.node.name.unwrap()));
|
||||
try!(self.word_nbsp(":"));
|
||||
try!(self.print_type(&field.node.ty));
|
||||
try!(word(&mut self.s, ","));
|
||||
}
|
||||
|
||||
self.bclose(span)
|
||||
|
@ -283,7 +283,7 @@ impl LateLintPass for NonSnakeCase {
|
||||
fn check_struct_def(&mut self, cx: &LateContext, s: &hir::VariantData,
|
||||
_: ast::Name, _: &hir::Generics, _: ast::NodeId) {
|
||||
for sf in s.fields() {
|
||||
if let hir::StructField_ { kind: hir::NamedField(name, _), .. } = sf.node {
|
||||
if let Some(name) = sf.node.name {
|
||||
self.check_snake_case(cx, "structure field", &name.as_str(),
|
||||
Some(sf.span));
|
||||
}
|
||||
|
@ -428,8 +428,8 @@ impl LateLintPass for MissingDoc {
|
||||
}
|
||||
|
||||
fn check_struct_field(&mut self, cx: &LateContext, sf: &hir::StructField) {
|
||||
if let hir::NamedField(_, vis) = sf.node.kind {
|
||||
if vis == hir::Public || self.in_variant {
|
||||
if sf.node.name.is_some() {
|
||||
if sf.node.vis == hir::Public || self.in_variant {
|
||||
let cur_struct_def = *self.struct_def_stack.last()
|
||||
.expect("empty struct_def_stack");
|
||||
self.check_missing_docs_attrs(cx, Some(cur_struct_def),
|
||||
|
@ -288,7 +288,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
|
||||
self.update(def.id(), item_level);
|
||||
}
|
||||
for field in def.fields() {
|
||||
if field.node.kind.visibility() == hir::Public {
|
||||
if field.node.vis == hir::Public {
|
||||
self.update(field.node.id, item_level);
|
||||
}
|
||||
}
|
||||
@ -1178,7 +1178,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
|
||||
hir::ItemEnum(ref def, _) => {
|
||||
for variant in &def.variants {
|
||||
for field in variant.node.data.fields() {
|
||||
check_inherited(field.span, field.node.kind.visibility(),
|
||||
check_inherited(field.span, field.vis,
|
||||
"visibility qualifiers have no effect on variant fields");
|
||||
}
|
||||
}
|
||||
@ -1514,10 +1514,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx>
|
||||
}
|
||||
|
||||
fn visit_struct_field(&mut self, s: &hir::StructField) {
|
||||
let vis = match s.node.kind {
|
||||
hir::NamedField(_, vis) | hir::UnnamedField(vis) => vis
|
||||
};
|
||||
if vis == hir::Public || self.in_variant {
|
||||
if s.node.vis == hir::Public || self.in_variant {
|
||||
intravisit::walk_struct_field(self, s);
|
||||
}
|
||||
}
|
||||
@ -1728,7 +1725,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivateItemsInPublicInterfacesVisitor<'a, 'tc
|
||||
if item.vis == hir::Public {
|
||||
check.visit_generics(generics);
|
||||
for field in struct_def.fields() {
|
||||
if field.node.kind.visibility() == hir::Public {
|
||||
if field.node.vis == hir::Public {
|
||||
check.visit_struct_field(field);
|
||||
}
|
||||
}
|
||||
|
@ -41,9 +41,7 @@ use rustc_front::hir::{ForeignItem, ForeignItemFn, ForeignItemStatic};
|
||||
use rustc_front::hir::{Item, ItemConst, ItemEnum, ItemExternCrate, ItemFn};
|
||||
use rustc_front::hir::{ItemForeignMod, ItemImpl, ItemMod, ItemStatic, ItemDefaultImpl};
|
||||
use rustc_front::hir::{ItemStruct, ItemTrait, ItemTy, ItemUse};
|
||||
use rustc_front::hir::{NamedField, PathListIdent, PathListMod};
|
||||
use rustc_front::hir::StmtDecl;
|
||||
use rustc_front::hir::UnnamedField;
|
||||
use rustc_front::hir::{PathListIdent, PathListMod, StmtDecl};
|
||||
use rustc_front::hir::{Variant, ViewPathGlob, ViewPathList, ViewPathSimple};
|
||||
use rustc_front::hir::Visibility;
|
||||
use rustc_front::intravisit::{self, Visitor};
|
||||
@ -384,12 +382,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
// Record the def ID and fields of this struct.
|
||||
let named_fields = struct_def.fields()
|
||||
.iter()
|
||||
.filter_map(|f| {
|
||||
match f.node.kind {
|
||||
NamedField(name, _) => Some(name),
|
||||
UnnamedField(_) => None,
|
||||
}
|
||||
})
|
||||
.filter_map(|f| f.node.name)
|
||||
.collect();
|
||||
let item_def_id = self.ast_map.local_def_id(item.id);
|
||||
self.structs.insert(item_def_id, named_fields);
|
||||
|
@ -978,24 +978,21 @@ fn convert_struct_variant<'tcx>(tcx: &ty::ctxt<'tcx>,
|
||||
let mut seen_fields: FnvHashMap<ast::Name, Span> = FnvHashMap();
|
||||
let fields = def.fields().iter().map(|f| {
|
||||
let fid = tcx.map.local_def_id(f.node.id);
|
||||
match f.node.kind {
|
||||
hir::NamedField(name, vis) => {
|
||||
let dup_span = seen_fields.get(&name).cloned();
|
||||
if let Some(prev_span) = dup_span {
|
||||
let mut err = struct_span_err!(tcx.sess, f.span, E0124,
|
||||
"field `{}` is already declared",
|
||||
name);
|
||||
span_note!(&mut err, prev_span, "previously declared here");
|
||||
err.emit();
|
||||
} else {
|
||||
seen_fields.insert(name, f.span);
|
||||
}
|
||||
|
||||
ty::FieldDefData::new(fid, name, vis)
|
||||
},
|
||||
hir::UnnamedField(vis) => {
|
||||
ty::FieldDefData::new(fid, special_idents::unnamed_field.name, vis)
|
||||
if let Some(name) = f.node.name {
|
||||
let dup_span = seen_fields.get(&name).cloned();
|
||||
if let Some(prev_span) = dup_span {
|
||||
let mut err = struct_span_err!(tcx.sess, f.span, E0124,
|
||||
"field `{}` is already declared",
|
||||
name);
|
||||
span_note!(&mut err, prev_span, "previously declared here");
|
||||
err.emit();
|
||||
} else {
|
||||
seen_fields.insert(name, f.span);
|
||||
}
|
||||
|
||||
ty::FieldDefData::new(fid, name, f.node.vis)
|
||||
} else {
|
||||
ty::FieldDefData::new(fid, special_idents::unnamed_field.name, f.node.vis)
|
||||
}
|
||||
}).collect();
|
||||
ty::VariantDefData {
|
||||
|
Loading…
x
Reference in New Issue
Block a user