Dict -> Struct, StructDef -> VariantData, def -> data
This commit is contained in:
parent
f4e3851aa7
commit
30af54dede
@ -134,11 +134,11 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
|
||||
ItemEnum(ref enum_definition, _) => {
|
||||
for v in &enum_definition.variants {
|
||||
let variant_def_index =
|
||||
self.insert_def(v.node.def.id,
|
||||
self.insert_def(v.node.data.id,
|
||||
NodeVariant(&**v),
|
||||
DefPathData::EnumVariant(v.node.name));
|
||||
|
||||
for field in &v.node.def.fields {
|
||||
for field in &v.node.data.fields {
|
||||
self.create_def_with_parent(
|
||||
Some(variant_def_index),
|
||||
field.node.id,
|
||||
@ -150,7 +150,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
|
||||
}
|
||||
ItemStruct(ref struct_def, _) => {
|
||||
// If this is a tuple-like struct, register the constructor.
|
||||
if struct_def.kind != VariantKind::Dict {
|
||||
if struct_def.kind != VariantKind::Struct {
|
||||
self.insert_def(struct_def.id,
|
||||
NodeStructCtor(&**struct_def),
|
||||
DefPathData::StructCtor);
|
||||
|
@ -124,7 +124,7 @@ pub enum Node<'ast> {
|
||||
NodeBlock(&'ast Block),
|
||||
|
||||
/// NodeStructCtor represents a tuple struct.
|
||||
NodeStructCtor(&'ast StructDef),
|
||||
NodeStructCtor(&'ast VariantData),
|
||||
|
||||
NodeLifetime(&'ast Lifetime),
|
||||
NodeTyParam(&'ast TyParam)
|
||||
@ -149,7 +149,7 @@ pub enum MapEntry<'ast> {
|
||||
EntryLocal(NodeId, &'ast Pat),
|
||||
EntryPat(NodeId, &'ast Pat),
|
||||
EntryBlock(NodeId, &'ast Block),
|
||||
EntryStructCtor(NodeId, &'ast StructDef),
|
||||
EntryStructCtor(NodeId, &'ast VariantData),
|
||||
EntryLifetime(NodeId, &'ast Lifetime),
|
||||
EntryTyParam(NodeId, &'ast TyParam),
|
||||
|
||||
@ -471,7 +471,7 @@ impl<'ast> Map<'ast> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_struct(&self, id: NodeId) -> &'ast StructDef {
|
||||
pub fn expect_struct(&self, id: NodeId) -> &'ast VariantData {
|
||||
match self.find(id) {
|
||||
Some(NodeItem(i)) => {
|
||||
match i.node {
|
||||
@ -480,8 +480,8 @@ impl<'ast> Map<'ast> {
|
||||
}
|
||||
}
|
||||
Some(NodeVariant(variant)) => {
|
||||
match variant.node.def.kind {
|
||||
VariantKind::Dict => &variant.node.def,
|
||||
match variant.node.data.kind {
|
||||
VariantKind::Struct => &variant.node.data,
|
||||
_ => panic!("struct ID bound to enum variant that isn't struct-like"),
|
||||
}
|
||||
}
|
||||
|
@ -661,8 +661,8 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> {
|
||||
hir_visit::walk_fn(self, fk, decl, body, span);
|
||||
}
|
||||
|
||||
fn visit_struct_def(&mut self,
|
||||
s: &hir::StructDef,
|
||||
fn visit_variant_data(&mut self,
|
||||
s: &hir::VariantData,
|
||||
name: ast::Name,
|
||||
g: &hir::Generics,
|
||||
item_id: ast::NodeId,
|
||||
@ -811,8 +811,8 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
|
||||
ast_visit::walk_fn(self, fk, decl, body, span);
|
||||
}
|
||||
|
||||
fn visit_struct_def(&mut self,
|
||||
s: &ast::StructDef,
|
||||
fn visit_variant_data(&mut self,
|
||||
s: &ast::VariantData,
|
||||
ident: ast::Ident,
|
||||
g: &ast::Generics,
|
||||
item_id: ast::NodeId,
|
||||
|
@ -150,9 +150,9 @@ pub trait LateLintPass: LintPass {
|
||||
fn check_trait_item(&mut self, _: &LateContext, _: &hir::TraitItem) { }
|
||||
fn check_impl_item(&mut self, _: &LateContext, _: &hir::ImplItem) { }
|
||||
fn check_struct_def(&mut self, _: &LateContext,
|
||||
_: &hir::StructDef, _: ast::Name, _: &hir::Generics, _: ast::NodeId) { }
|
||||
_: &hir::VariantData, _: ast::Name, _: &hir::Generics, _: ast::NodeId) { }
|
||||
fn check_struct_def_post(&mut self, _: &LateContext,
|
||||
_: &hir::StructDef, _: ast::Name, _: &hir::Generics, _: ast::NodeId) { }
|
||||
_: &hir::VariantData, _: ast::Name, _: &hir::Generics, _: ast::NodeId) { }
|
||||
fn check_struct_field(&mut self, _: &LateContext, _: &hir::StructField) { }
|
||||
fn check_variant(&mut self, _: &LateContext, _: &hir::Variant, _: &hir::Generics) { }
|
||||
fn check_variant_post(&mut self, _: &LateContext, _: &hir::Variant, _: &hir::Generics) { }
|
||||
@ -192,9 +192,9 @@ pub trait EarlyLintPass: LintPass {
|
||||
fn check_trait_item(&mut self, _: &EarlyContext, _: &ast::TraitItem) { }
|
||||
fn check_impl_item(&mut self, _: &EarlyContext, _: &ast::ImplItem) { }
|
||||
fn check_struct_def(&mut self, _: &EarlyContext,
|
||||
_: &ast::StructDef, _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { }
|
||||
_: &ast::VariantData, _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { }
|
||||
fn check_struct_def_post(&mut self, _: &EarlyContext,
|
||||
_: &ast::StructDef, _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { }
|
||||
_: &ast::VariantData, _: ast::Ident, _: &ast::Generics, _: ast::NodeId) { }
|
||||
fn check_struct_field(&mut self, _: &EarlyContext, _: &ast::StructField) { }
|
||||
fn check_variant(&mut self, _: &EarlyContext, _: &ast::Variant, _: &ast::Generics) { }
|
||||
fn check_variant_post(&mut self, _: &EarlyContext, _: &ast::Variant, _: &ast::Generics) { }
|
||||
|
@ -315,7 +315,7 @@ fn encode_enum_variant_info<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
let vid = variant.did;
|
||||
let variant_node_id = ecx.local_id(vid);
|
||||
|
||||
if let ty::VariantKind::Dict = variant.kind() {
|
||||
if let ty::VariantKind::Struct = variant.kind() {
|
||||
// tuple-like enum variant fields aren't really items so
|
||||
// don't try to encode them.
|
||||
for field in &variant.fields {
|
||||
@ -328,7 +328,7 @@ fn encode_enum_variant_info<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
encode_def_id_and_key(ecx, rbml_w, vid);
|
||||
encode_family(rbml_w, match variant.kind() {
|
||||
ty::VariantKind::Unit | ty::VariantKind::Tuple => 'v',
|
||||
ty::VariantKind::Dict => 'V'
|
||||
ty::VariantKind::Struct => 'V'
|
||||
});
|
||||
encode_name(rbml_w, variant.name);
|
||||
encode_parent_item(rbml_w, ecx.tcx.map.local_def_id(id));
|
||||
@ -1019,7 +1019,7 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
encode_attributes(rbml_w, &item.attrs);
|
||||
encode_repr_attrs(rbml_w, ecx, &item.attrs);
|
||||
for v in &enum_definition.variants {
|
||||
encode_variant_id(rbml_w, ecx.tcx.map.local_def_id(v.node.def.id));
|
||||
encode_variant_id(rbml_w, ecx.tcx.map.local_def_id(v.node.data.id));
|
||||
}
|
||||
encode_inlined_item(ecx, rbml_w, InlinedItemRef::Item(item));
|
||||
encode_path(rbml_w, path);
|
||||
@ -1068,7 +1068,7 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
// Encode inherent implementations for this structure.
|
||||
encode_inherent_implementations(ecx, rbml_w, def_id);
|
||||
|
||||
if struct_def.kind != hir::VariantKind::Dict {
|
||||
if struct_def.kind != hir::VariantKind::Struct {
|
||||
let ctor_did = ecx.tcx.map.local_def_id(struct_def.id);
|
||||
rbml_w.wr_tagged_u64(tag_items_data_item_struct_ctor,
|
||||
def_to_u64(ctor_did));
|
||||
@ -1081,7 +1081,7 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
}
|
||||
|
||||
// If this is a tuple-like struct, encode the type of the constructor.
|
||||
if struct_def.kind != hir::VariantKind::Dict {
|
||||
if struct_def.kind != hir::VariantKind::Struct {
|
||||
encode_info_for_struct_ctor(ecx, rbml_w, item.name, struct_def.id, index, item.id);
|
||||
}
|
||||
}
|
||||
|
@ -1316,11 +1316,11 @@ fn copy_item_types(dcx: &DecodeContext, ii: &InlinedItem, orig_did: DefId) {
|
||||
{
|
||||
debug!("astencode: copying variant {:?} => {:?}",
|
||||
orig_variant.did, i_variant.node.id);
|
||||
copy_item_type(dcx, i_variant.node.def.id, orig_variant.did);
|
||||
copy_item_type(dcx, i_variant.node.data.id, orig_variant.did);
|
||||
}
|
||||
}
|
||||
hir::ItemStruct(ref def, _) => {
|
||||
if def.kind != hir::VariantKind::Dict {
|
||||
if def.kind != hir::VariantKind::Struct {
|
||||
let ctor_did = dcx.tcx.lookup_adt_def(orig_did)
|
||||
.struct_variant().did;
|
||||
debug!("astencode: copying ctor {:?} => {:?}", ctor_did,
|
||||
|
@ -518,7 +518,7 @@ fn construct_witness<'a,'tcx>(cx: &MatchCheckCtxt<'a,'tcx>, ctor: &Constructor,
|
||||
|
||||
ty::TyEnum(adt, _) | ty::TyStruct(adt, _) => {
|
||||
let v = adt.variant_of_ctor(ctor);
|
||||
if let VariantKind::Dict = v.kind() {
|
||||
if let VariantKind::Struct = v.kind() {
|
||||
let field_pats: Vec<_> = v.fields.iter()
|
||||
.zip(pats)
|
||||
.filter(|&(_, ref pat)| pat.node != hir::PatWild(hir::PatWildSingle))
|
||||
|
@ -168,7 +168,7 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
|
||||
let mut discriminant_map = self.discriminant_map.borrow_mut();
|
||||
match enum_definition.variants.first() {
|
||||
None => { return; }
|
||||
Some(variant) if discriminant_map.contains_key(&variant.node.def.id) => {
|
||||
Some(variant) if discriminant_map.contains_key(&variant.node.data.id) => {
|
||||
return;
|
||||
}
|
||||
_ => {}
|
||||
@ -177,7 +177,7 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
|
||||
// Go through all the variants.
|
||||
let mut variant_stack: Vec<ast::NodeId> = Vec::new();
|
||||
for variant in enum_definition.variants.iter().rev() {
|
||||
variant_stack.push(variant.node.def.id);
|
||||
variant_stack.push(variant.node.data.id);
|
||||
// When we find an expression, every variant currently on the stack
|
||||
// is affected by that expression.
|
||||
if let Some(ref expr) = variant.node.disr_expr {
|
||||
@ -208,7 +208,7 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
|
||||
|
||||
fn visit_variant(&mut self, variant: &'ast hir::Variant,
|
||||
_: &'ast hir::Generics, _: ast::NodeId) {
|
||||
let variant_id = variant.node.def.id;
|
||||
let variant_id = variant.node.data.id;
|
||||
let maybe_expr;
|
||||
if let Some(get_expr) = self.discriminant_map.borrow().get(&variant_id) {
|
||||
// This is necessary because we need to let the `discriminant_map`
|
||||
|
@ -63,7 +63,7 @@ fn lookup_variant_by_id<'a>(tcx: &'a ty::ctxt,
|
||||
fn variant_expr<'a>(variants: &'a [P<hir::Variant>], id: ast::NodeId)
|
||||
-> Option<&'a Expr> {
|
||||
for variant in variants {
|
||||
if variant.node.def.id == id {
|
||||
if variant.node.data.id == id {
|
||||
return variant.node.disr_expr.as_ref().map(|e| &**e);
|
||||
}
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
|
||||
|
||||
impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
|
||||
|
||||
fn visit_struct_def(&mut self, def: &hir::StructDef, _: ast::Name,
|
||||
fn visit_variant_data(&mut self, def: &hir::VariantData, _: ast::Name,
|
||||
_: &hir::Generics, _: ast::NodeId, _: codemap::Span) {
|
||||
let has_extern_repr = self.struct_has_extern_repr;
|
||||
let inherited_pub_visibility = self.inherited_pub_visibility;
|
||||
@ -339,7 +339,7 @@ impl<'v> Visitor<'v> for LifeSeeder {
|
||||
}
|
||||
match item.node {
|
||||
hir::ItemEnum(ref enum_def, _) if allow_dead_code => {
|
||||
self.worklist.extend(enum_def.variants.iter().map(|variant| variant.node.def.id));
|
||||
self.worklist.extend(enum_def.variants.iter().map(|variant| variant.node.data.id));
|
||||
}
|
||||
hir::ItemTrait(_, _, _, ref trait_items) => {
|
||||
for trait_item in trait_items {
|
||||
@ -426,7 +426,7 @@ fn find_live(tcx: &ty::ctxt,
|
||||
|
||||
fn get_struct_ctor_id(item: &hir::Item) -> Option<ast::NodeId> {
|
||||
match item.node {
|
||||
hir::ItemStruct(ref struct_def, _) if struct_def.kind != hir::VariantKind::Dict => {
|
||||
hir::ItemStruct(ref struct_def, _) if struct_def.kind != hir::VariantKind::Struct => {
|
||||
Some(struct_def.id)
|
||||
}
|
||||
_ => None
|
||||
@ -466,7 +466,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn should_warn_about_variant(&mut self, variant: &hir::Variant_) -> bool {
|
||||
!self.symbol_is_live(variant.def.id, None)
|
||||
!self.symbol_is_live(variant.data.id, None)
|
||||
&& !has_allow_dead_code_or_lang_attr(&variant.attrs)
|
||||
}
|
||||
|
||||
@ -542,7 +542,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
|
||||
hir::ItemEnum(ref enum_def, _) => {
|
||||
for variant in &enum_def.variants {
|
||||
if self.should_warn_about_variant(&variant.node) {
|
||||
self.warn_dead_code(variant.node.def.id, variant.span,
|
||||
self.warn_dead_code(variant.node.data.id, variant.span,
|
||||
variant.node.name, "variant");
|
||||
}
|
||||
}
|
||||
|
@ -44,13 +44,13 @@ pub enum Def {
|
||||
ast::NodeId), // expr node that creates the closure
|
||||
|
||||
/// Note that if it's a tuple struct's definition, the node id of the DefId
|
||||
/// may either refer to the item definition's id or the StructDef.ctor_id.
|
||||
/// may either refer to the item definition's id or the VariantData.ctor_id.
|
||||
///
|
||||
/// The cases that I have encountered so far are (this is not exhaustive):
|
||||
/// - If it's a ty_path referring to some tuple struct, then DefMap maps
|
||||
/// it to a def whose id is the item definition's id.
|
||||
/// - If it's an ExprPath referring to some tuple struct, then DefMap maps
|
||||
/// it to a def whose id is the StructDef.ctor_id.
|
||||
/// it to a def whose id is the VariantData.ctor_id.
|
||||
DefStruct(DefId),
|
||||
DefLabel(ast::NodeId),
|
||||
DefMethod(DefId),
|
||||
|
@ -185,7 +185,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
|
||||
|v| visit::walk_item(v, i), required);
|
||||
|
||||
if let hir::ItemStruct(ref sd, _) = i.node {
|
||||
if sd.kind != hir::VariantKind::Dict {
|
||||
if sd.kind != hir::VariantKind::Struct {
|
||||
self.annotate(sd.id, true, &i.attrs, i.span, |_| {}, true)
|
||||
}
|
||||
}
|
||||
@ -208,7 +208,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, var: &Variant, g: &'v Generics, item_id: NodeId) {
|
||||
self.annotate(var.node.def.id, true, &var.node.attrs, var.span,
|
||||
self.annotate(var.node.data.id, true, &var.node.attrs, var.span,
|
||||
|v| visit::walk_variant(v, var, g, item_id), true)
|
||||
}
|
||||
|
||||
|
@ -1533,7 +1533,7 @@ impl<'tcx, 'container> Hash for AdtDefData<'tcx, 'container> {
|
||||
pub enum AdtKind { Struct, Enum }
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum VariantKind { Dict, Tuple, Unit }
|
||||
pub enum VariantKind { Struct, Tuple, Unit }
|
||||
|
||||
impl<'tcx, 'container> AdtDefData<'tcx, 'container> {
|
||||
fn new(tcx: &ctxt<'tcx>,
|
||||
@ -1716,7 +1716,7 @@ impl<'tcx, 'container> VariantDefData<'tcx, 'container> {
|
||||
Some(&FieldDefData { name, .. }) if name == special_idents::unnamed_field.name => {
|
||||
VariantKind::Tuple
|
||||
}
|
||||
Some(_) => VariantKind::Dict
|
||||
Some(_) => VariantKind::Struct
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,7 +301,7 @@ mod svh_visitor {
|
||||
}
|
||||
|
||||
impl<'a, 'v> Visitor<'v> for StrictVersionHashVisitor<'a> {
|
||||
fn visit_struct_def(&mut self, s: &StructDef, name: Name,
|
||||
fn visit_variant_data(&mut self, s: &VariantData, name: Name,
|
||||
g: &Generics, _: NodeId, _: Span) {
|
||||
SawStructDef(name.as_str()).hash(self.st);
|
||||
visit::walk_generics(self, g);
|
||||
|
@ -223,7 +223,7 @@ pub trait Folder : Sized {
|
||||
noop_fold_poly_trait_ref(p, self)
|
||||
}
|
||||
|
||||
fn fold_struct_def(&mut self, struct_def: P<StructDef>) -> P<StructDef> {
|
||||
fn fold_variant_data(&mut self, struct_def: P<VariantData>) -> P<VariantData> {
|
||||
noop_fold_struct_def(struct_def, self)
|
||||
}
|
||||
|
||||
@ -431,11 +431,11 @@ 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_ {name, attrs, def, disr_expr}, span}| Spanned {
|
||||
v.map(|Spanned {node: Variant_ {name, attrs, data, disr_expr}, span}| Spanned {
|
||||
node: Variant_ {
|
||||
name: name,
|
||||
attrs: fold_attrs(attrs, fld),
|
||||
def: fld.fold_struct_def(def),
|
||||
data: fld.fold_variant_data(data),
|
||||
disr_expr: disr_expr.map(|e| fld.fold_expr(e)),
|
||||
},
|
||||
span: fld.new_span(span),
|
||||
@ -693,9 +693,9 @@ pub fn noop_fold_where_predicate<T: Folder>(pred: WherePredicate, fld: &mut T) -
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_struct_def<T: Folder>(struct_def: P<StructDef>, fld: &mut T) -> P<StructDef> {
|
||||
struct_def.map(|StructDef { fields, id, kind }| {
|
||||
StructDef {
|
||||
pub fn noop_fold_struct_def<T: Folder>(struct_def: P<VariantData>, fld: &mut T) -> P<VariantData> {
|
||||
struct_def.map(|VariantData { fields, id, kind }| {
|
||||
VariantData {
|
||||
fields: fields.move_map(|f| fld.fold_struct_field(f)),
|
||||
id: fld.new_id(id),
|
||||
kind: kind,
|
||||
@ -806,7 +806,7 @@ pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ {
|
||||
folder.fold_generics(generics))
|
||||
}
|
||||
ItemStruct(struct_def, generics) => {
|
||||
let struct_def = folder.fold_struct_def(struct_def);
|
||||
let struct_def = folder.fold_variant_data(struct_def);
|
||||
ItemStruct(struct_def, folder.fold_generics(generics))
|
||||
}
|
||||
ItemDefaultImpl(unsafety, ref trait_ref) => {
|
||||
|
@ -1023,7 +1023,7 @@ pub struct EnumDef {
|
||||
pub struct Variant_ {
|
||||
pub name: Name,
|
||||
pub attrs: Vec<Attribute>,
|
||||
pub def: P<StructDef>,
|
||||
pub data: P<VariantData>,
|
||||
/// Explicit discriminant, eg `Foo = 1`
|
||||
pub disr_expr: Option<P<Expr>>,
|
||||
}
|
||||
@ -1162,13 +1162,13 @@ impl StructFieldKind {
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub enum VariantKind {
|
||||
Dict,
|
||||
Struct,
|
||||
Tuple,
|
||||
Unit,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct StructDef {
|
||||
pub struct VariantData {
|
||||
/// Fields, not including ctor
|
||||
pub fields: Vec<StructField>,
|
||||
/// ID of the constructor. This is only used for tuple- or enum-like
|
||||
@ -1218,7 +1218,7 @@ pub enum Item_ {
|
||||
/// An enum definition, e.g. `enum Foo<A, B> {C<A>, D<B>}`
|
||||
ItemEnum(EnumDef, Generics),
|
||||
/// A struct definition, e.g. `struct Foo<A> {x: A}`
|
||||
ItemStruct(P<StructDef>, Generics),
|
||||
ItemStruct(P<VariantData>, Generics),
|
||||
/// Represents a Trait Declaration
|
||||
ItemTrait(Unsafety, Generics, TyParamBounds, Vec<P<TraitItem>>),
|
||||
|
||||
|
@ -266,7 +266,7 @@ pub fn lower_variant(_lctx: &LoweringContext, v: &Variant) -> P<hir::Variant> {
|
||||
node: hir::Variant_ {
|
||||
name: v.node.name.name,
|
||||
attrs: v.node.attrs.clone(),
|
||||
def: lower_struct_def(_lctx, &v.node.def),
|
||||
data: lower_struct_def(_lctx, &v.node.data),
|
||||
disr_expr: v.node.disr_expr.as_ref().map(|e| lower_expr(e)),
|
||||
},
|
||||
span: v.span,
|
||||
@ -498,12 +498,12 @@ pub fn lower_where_predicate(_lctx: &LoweringContext,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn lower_struct_def(_lctx: &LoweringContext, sd: &StructDef) -> P<hir::StructDef> {
|
||||
P(hir::StructDef {
|
||||
pub fn lower_struct_def(sd: &VariantData) -> P<hir::VariantData> {
|
||||
P(hir::VariantData {
|
||||
fields: sd.fields.iter().map(|f| lower_struct_field(_lctx, f)).collect(),
|
||||
id: sd.id,
|
||||
kind: match sd.kind {
|
||||
VariantKind::Dict => hir::VariantKind::Dict,
|
||||
VariantKind::Struct => hir::VariantKind::Struct,
|
||||
VariantKind::Tuple => hir::VariantKind::Tuple,
|
||||
VariantKind::Unit => hir::VariantKind::Unit,
|
||||
}
|
||||
|
@ -888,7 +888,7 @@ impl<'a> State<'a> {
|
||||
}
|
||||
|
||||
pub fn print_struct(&mut self,
|
||||
struct_def: &hir::StructDef,
|
||||
struct_def: &hir::VariantData,
|
||||
generics: &hir::Generics,
|
||||
name: ast::Name,
|
||||
span: codemap::Span,
|
||||
@ -896,7 +896,7 @@ impl<'a> State<'a> {
|
||||
-> io::Result<()> {
|
||||
try!(self.print_name(name));
|
||||
try!(self.print_generics(generics));
|
||||
if struct_def.kind != hir::VariantKind::Dict {
|
||||
if struct_def.kind != hir::VariantKind::Struct {
|
||||
if struct_def.kind == hir::VariantKind::Tuple {
|
||||
try!(self.popen());
|
||||
try!(self.commasep(Inconsistent,
|
||||
@ -948,7 +948,7 @@ impl<'a> State<'a> {
|
||||
pub fn print_variant(&mut self, v: &hir::Variant) -> io::Result<()> {
|
||||
try!(self.head(""));
|
||||
let generics = ::util::empty_generics();
|
||||
try!(self.print_struct(&v.node.def, &generics, v.node.name, v.span, false));
|
||||
try!(self.print_struct(&v.node.data, &generics, v.node.name, v.span, false));
|
||||
match v.node.disr_expr {
|
||||
Some(ref d) => {
|
||||
try!(space(&mut self.s));
|
||||
|
@ -281,8 +281,8 @@ impl<'a, 'v, O: ast_util::IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O>
|
||||
visit::walk_struct_field(self, struct_field)
|
||||
}
|
||||
|
||||
fn visit_struct_def(&mut self,
|
||||
struct_def: &StructDef,
|
||||
fn visit_variant_data(&mut self,
|
||||
struct_def: &VariantData,
|
||||
_: Name,
|
||||
_: &hir::Generics,
|
||||
_: NodeId,
|
||||
|
@ -112,7 +112,7 @@ pub trait Visitor<'v> : Sized {
|
||||
fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef, m: &'v TraitBoundModifier) {
|
||||
walk_poly_trait_ref(self, t, m)
|
||||
}
|
||||
fn visit_struct_def(&mut self, s: &'v StructDef, _: Name,
|
||||
fn visit_variant_data(&mut self, s: &'v VariantData, _: Name,
|
||||
_: &'v Generics, _: NodeId, _: Span) {
|
||||
walk_struct_def(self, s)
|
||||
}
|
||||
@ -310,7 +310,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
|
||||
}
|
||||
ItemStruct(ref struct_definition, ref generics) => {
|
||||
visitor.visit_generics(generics);
|
||||
visitor.visit_struct_def(struct_definition, item.name,
|
||||
visitor.visit_variant_data(struct_definition, item.name,
|
||||
generics, item.id, item.span);
|
||||
}
|
||||
ItemTrait(_, ref generics, ref bounds, ref methods) => {
|
||||
@ -336,7 +336,7 @@ pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||
generics: &'v Generics,
|
||||
item_id: NodeId) {
|
||||
visitor.visit_name(variant.span, variant.node.name);
|
||||
visitor.visit_struct_def(&variant.node.def, variant.node.name,
|
||||
visitor.visit_variant_data(&variant.node.data, variant.node.name,
|
||||
generics, item_id, variant.span);
|
||||
walk_list!(visitor, visit_expr, &variant.node.disr_expr);
|
||||
walk_list!(visitor, visit_attribute, &variant.node.attrs);
|
||||
@ -628,7 +628,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
|
||||
}
|
||||
}
|
||||
|
||||
pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, struct_definition: &'v StructDef) {
|
||||
pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, struct_definition: &'v VariantData) {
|
||||
walk_list!(visitor, visit_struct_field, &struct_definition.fields);
|
||||
}
|
||||
|
||||
|
@ -280,7 +280,7 @@ impl LateLintPass for NonSnakeCase {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_struct_def(&mut self, cx: &LateContext, s: &hir::StructDef,
|
||||
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 {
|
||||
|
@ -427,12 +427,12 @@ impl LateLintPass for MissingDoc {
|
||||
self.doc_hidden_stack.pop().expect("empty doc_hidden_stack");
|
||||
}
|
||||
|
||||
fn check_struct_def(&mut self, _: &LateContext, _: &hir::StructDef,
|
||||
fn check_struct_def(&mut self, _: &LateContext, _: &hir::VariantData,
|
||||
_: ast::Name, _: &hir::Generics, item_id: ast::NodeId) {
|
||||
self.struct_def_stack.push(item_id);
|
||||
}
|
||||
|
||||
fn check_struct_def_post(&mut self, _: &LateContext, _: &hir::StructDef,
|
||||
fn check_struct_def_post(&mut self, _: &LateContext, _: &hir::VariantData,
|
||||
_: ast::Name, _: &hir::Generics, item_id: ast::NodeId) {
|
||||
let popped = self.struct_def_stack.pop().expect("empty struct_def_stack");
|
||||
assert!(popped == item_id);
|
||||
@ -527,7 +527,7 @@ impl LateLintPass for MissingDoc {
|
||||
}
|
||||
|
||||
fn check_variant(&mut self, cx: &LateContext, v: &hir::Variant, _: &hir::Generics) {
|
||||
self.check_missing_docs_attrs(cx, Some(v.node.def.id), &v.node.attrs, v.span, "a variant");
|
||||
self.check_missing_docs_attrs(cx, Some(v.node.data.id), &v.node.attrs, v.span, "a variant");
|
||||
assert!(!self.in_variant);
|
||||
self.in_variant = true;
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ impl<'v> Visitor<'v> for ParentVisitor {
|
||||
// The parent is considered the enclosing enum because the
|
||||
// enum will dictate the privacy visibility of this variant
|
||||
// instead.
|
||||
self.parents.insert(variant.node.def.id, item.id);
|
||||
self.parents.insert(variant.node.data.id, item.id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,11 +128,11 @@ impl<'v> Visitor<'v> for ParentVisitor {
|
||||
visit::walk_impl_item(self, ii);
|
||||
}
|
||||
|
||||
fn visit_struct_def(&mut self, s: &hir::StructDef, _: ast::Name,
|
||||
fn visit_variant_data(&mut self, s: &hir::VariantData, _: ast::Name,
|
||||
_: &'v hir::Generics, item_id: ast::NodeId, _: Span) {
|
||||
// Struct constructors are parented to their struct definitions because
|
||||
// they essentially are the struct definitions.
|
||||
if s.kind != hir::VariantKind::Dict {
|
||||
if s.kind != hir::VariantKind::Struct {
|
||||
self.parents.insert(s.id, item_id);
|
||||
}
|
||||
|
||||
@ -233,8 +233,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
|
||||
// public all variants are public unless they're explicitly priv
|
||||
hir::ItemEnum(ref def, _) if public_first => {
|
||||
for variant in &def.variants {
|
||||
self.exported_items.insert(variant.node.def.id);
|
||||
self.public_items.insert(variant.node.def.id);
|
||||
self.exported_items.insert(variant.node.data.id);
|
||||
self.public_items.insert(variant.node.data.id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -319,7 +319,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
|
||||
|
||||
// Struct constructors are public if the struct is all public.
|
||||
hir::ItemStruct(ref def, _) if public_first => {
|
||||
if def.kind != hir::VariantKind::Dict {
|
||||
if def.kind != hir::VariantKind::Struct {
|
||||
self.exported_items.insert(def.id);
|
||||
}
|
||||
// fields can be public or private, so lets check
|
||||
@ -1088,7 +1088,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
|
||||
"visibility has no effect inside functions");
|
||||
}
|
||||
}
|
||||
let check_struct = |def: &hir::StructDef| {
|
||||
let check_struct = |def: &hir::VariantData| {
|
||||
for f in &def.fields {
|
||||
match f.node.kind {
|
||||
hir::NamedField(_, p) => check_inherited(tcx, f.span, p),
|
||||
@ -1431,7 +1431,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn visit_variant(&mut self, v: &hir::Variant, g: &hir::Generics, item_id: ast::NodeId) {
|
||||
if self.exported_items.contains(&v.node.def.id) {
|
||||
if self.exported_items.contains(&v.node.data.id) {
|
||||
self.in_variant = true;
|
||||
visit::walk_variant(self, v, g, item_id);
|
||||
self.in_variant = false;
|
||||
|
@ -493,7 +493,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
ItemStruct(ref struct_def, _) => {
|
||||
// Adding to both Type and Value namespaces or just Type?
|
||||
let (forbid, ctor_id) = match struct_def.kind {
|
||||
hir::VariantKind::Dict => (ForbidDuplicateTypesAndModules, None),
|
||||
hir::VariantKind::Struct => (ForbidDuplicateTypesAndModules, None),
|
||||
_ => (ForbidDuplicateTypesAndValues, Some(struct_def.id)),
|
||||
};
|
||||
|
||||
@ -587,10 +587,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
item_id: DefId,
|
||||
parent: &Rc<Module>) {
|
||||
let name = variant.node.name;
|
||||
let is_exported = match variant.node.def.kind {
|
||||
hir::VariantKind::Dict => {
|
||||
let is_exported = match variant.node.data.kind {
|
||||
hir::VariantKind::Struct => {
|
||||
// Not adding fields for variants as they are not accessed with a self receiver
|
||||
let variant_def_id = self.ast_map.local_def_id(variant.node.def.id);
|
||||
let variant_def_id = self.ast_map.local_def_id(variant.node.data.id);
|
||||
self.structs.insert(variant_def_id, Vec::new());
|
||||
true
|
||||
}
|
||||
@ -603,10 +603,10 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
|
||||
// variants are always treated as importable to allow them to be glob
|
||||
// used
|
||||
child.define_value(DefVariant(item_id,
|
||||
self.ast_map.local_def_id(variant.node.def.id), is_exported),
|
||||
self.ast_map.local_def_id(variant.node.data.id), is_exported),
|
||||
variant.span, DefModifiers::PUBLIC | DefModifiers::IMPORTABLE);
|
||||
child.define_type(DefVariant(item_id,
|
||||
self.ast_map.local_def_id(variant.node.def.id), is_exported),
|
||||
self.ast_map.local_def_id(variant.node.data.id), is_exported),
|
||||
variant.span, DefModifiers::PUBLIC | DefModifiers::IMPORTABLE);
|
||||
}
|
||||
|
||||
|
@ -501,7 +501,7 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Resolver<'a, 'tcx> {
|
||||
}
|
||||
|
||||
// `visit::walk_variant` without the discriminant expression.
|
||||
self.visit_struct_def(&variant.node.def, variant.node.name,
|
||||
self.visit_variant_data(&variant.node.data, variant.node.name,
|
||||
generics, item_id, variant.span);
|
||||
}
|
||||
fn visit_foreign_item(&mut self, foreign_item: &hir::ForeignItem) {
|
||||
|
@ -458,7 +458,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
||||
|
||||
fn process_struct(&mut self,
|
||||
item: &ast::Item,
|
||||
def: &ast::StructDef,
|
||||
def: &ast::VariantData,
|
||||
ty_params: &ast::Generics) {
|
||||
let qualname = format!("::{}", self.tcx.map.path_to_string(item.id));
|
||||
|
||||
@ -503,15 +503,15 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
||||
|
||||
self.fmt.struct_variant_str(variant.span,
|
||||
self.span.span_for_first_ident(variant.span),
|
||||
variant.node.def.id,
|
||||
variant.node.def.id,
|
||||
variant.node.data.id,
|
||||
variant.node.data.id,
|
||||
&qualname,
|
||||
&enum_data.qualname,
|
||||
&val,
|
||||
enum_data.id);
|
||||
|
||||
for field in &variant.node.def.fields {
|
||||
self.process_struct_field_def(field, variant.node.def.id);
|
||||
for field in &variant.node.data.fields {
|
||||
self.process_struct_field_def(field, variant.node.data.id);
|
||||
self.visit_ty(&*field.node.ty);
|
||||
}
|
||||
}
|
||||
|
@ -2428,10 +2428,10 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
|
||||
|
||||
hir_map::NodeVariant(ref v) => {
|
||||
let llfn;
|
||||
let fields = if v.node.def.kind == hir::VariantKind::Dict {
|
||||
let fields = if v.node.data.kind == hir::VariantKind::Struct {
|
||||
ccx.sess().bug("struct variant kind unexpected in get_item_val")
|
||||
} else {
|
||||
&v.node.def.fields
|
||||
&v.node.data.fields
|
||||
};
|
||||
assert!(!fields.is_empty());
|
||||
let ty = ccx.tcx().node_id_to_type(id);
|
||||
@ -2455,7 +2455,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
|
||||
hir_map::NodeStructCtor(struct_def) => {
|
||||
// Only register the constructor if this is a tuple-like struct.
|
||||
let ctor_id = match struct_def.kind {
|
||||
hir::VariantKind::Dict => {
|
||||
hir::VariantKind::Struct => {
|
||||
ccx.sess().bug("attempt to register a constructor of \
|
||||
a non-tuple-like struct")
|
||||
}
|
||||
|
@ -418,7 +418,7 @@ pub fn trans_fn_ref_with_substs<'a, 'tcx>(
|
||||
|
||||
match map_node {
|
||||
hir_map::NodeVariant(v) => {
|
||||
v.node.def.kind == hir::VariantKind::Tuple
|
||||
v.node.data.kind == hir::VariantKind::Tuple
|
||||
}
|
||||
hir_map::NodeStructCtor(_) => true,
|
||||
_ => false
|
||||
|
@ -818,7 +818,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
ty::VariantKind::Tuple => {
|
||||
expr::trans_def_fn_unadjusted(cx, e, def, param_substs).val
|
||||
}
|
||||
ty::VariantKind::Dict => {
|
||||
ty::VariantKind::Struct => {
|
||||
cx.sess().span_bug(e.span, "path-expr refers to a dict variant!")
|
||||
}
|
||||
}
|
||||
|
@ -1365,7 +1365,7 @@ impl<'tcx> EnumMemberDescriptionFactory<'tcx> {
|
||||
let sole_struct_member_description = MemberDescription {
|
||||
name: match non_null_variant.kind() {
|
||||
ty::VariantKind::Tuple => "__0".to_string(),
|
||||
ty::VariantKind::Dict => {
|
||||
ty::VariantKind::Struct => {
|
||||
non_null_variant.fields[0].name.to_string()
|
||||
}
|
||||
ty::VariantKind::Unit => unreachable!()
|
||||
@ -1540,7 +1540,7 @@ fn describe_enum_variant<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
||||
.map(|(i, _)| format!("__{}", i))
|
||||
.collect()
|
||||
}
|
||||
ty::VariantKind::Dict => {
|
||||
ty::VariantKind::Struct => {
|
||||
variant.fields
|
||||
.iter()
|
||||
.map(|f| f.name.to_string())
|
||||
|
@ -110,13 +110,13 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: DefId)
|
||||
let ty_vs = &ccx.tcx().lookup_adt_def(parent_id).variants;
|
||||
assert_eq!(ast_vs.len(), ty_vs.len());
|
||||
for (ast_v, ty_v) in ast_vs.iter().zip(ty_vs.iter()) {
|
||||
if ty_v.did == fn_id { my_id = ast_v.node.def.id; }
|
||||
ccx.external().borrow_mut().insert(ty_v.did, Some(ast_v.node.def.id));
|
||||
if ty_v.did == fn_id { my_id = ast_v.node.data.id; }
|
||||
ccx.external().borrow_mut().insert(ty_v.did, Some(ast_v.node.data.id));
|
||||
}
|
||||
}
|
||||
hir::ItemStruct(ref struct_def, _) => {
|
||||
match struct_def.kind {
|
||||
hir::VariantKind::Dict => ccx.sess().bug("instantiate_inline: called on a \
|
||||
hir::VariantKind::Struct => ccx.sess().bug("instantiate_inline: called on a \
|
||||
non-tuple struct"),
|
||||
_ => {
|
||||
ccx.external().borrow_mut().insert(fn_id, Some(struct_def.id));
|
||||
|
@ -246,7 +246,7 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||
hir_map::NodeStructCtor(struct_def) => {
|
||||
let d = mk_lldecl(abi::Rust);
|
||||
attributes::inline(d, attributes::InlineAttr::Hint);
|
||||
if struct_def.kind == hir::VariantKind::Dict {
|
||||
if struct_def.kind == hir::VariantKind::Struct {
|
||||
panic!("ast-mapped struct didn't have a ctor id")
|
||||
}
|
||||
base::trans_tuple_struct(ccx,
|
||||
|
@ -1485,7 +1485,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
};
|
||||
|
||||
let var_kind = variant.kind();
|
||||
if var_kind == ty::VariantKind::Dict {
|
||||
if var_kind == ty::VariantKind::Struct {
|
||||
Some((adt, variant))
|
||||
} else if var_kind == ty::VariantKind::Unit {
|
||||
if !self.tcx().sess.features.borrow().braced_empty_structs {
|
||||
|
@ -624,7 +624,7 @@ struct AdtField<'tcx> {
|
||||
}
|
||||
|
||||
fn struct_variant<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
struct_def: &hir::StructDef)
|
||||
struct_def: &hir::VariantData)
|
||||
-> AdtVariant<'tcx> {
|
||||
let fields =
|
||||
struct_def.fields
|
||||
@ -647,7 +647,7 @@ fn enum_variants<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
enum_def: &hir::EnumDef)
|
||||
-> Vec<AdtVariant<'tcx>> {
|
||||
enum_def.variants.iter()
|
||||
.map(|variant| struct_variant(fcx, &variant.node.def))
|
||||
.map(|variant| struct_variant(fcx, &variant.node.data))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
@ -521,7 +521,7 @@ struct AdtField<'tcx> {
|
||||
}
|
||||
|
||||
fn struct_variant<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
struct_def: &hir::StructDef)
|
||||
struct_def: &hir::VariantData)
|
||||
-> AdtVariant<'tcx> {
|
||||
let fields =
|
||||
struct_def.fields
|
||||
@ -544,7 +544,7 @@ fn enum_variants<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
|
||||
enum_def: &hir::EnumDef)
|
||||
-> Vec<AdtVariant<'tcx>> {
|
||||
enum_def.variants.iter()
|
||||
.map(|variant| struct_variant(fcx, &variant.node.def))
|
||||
.map(|variant| struct_variant(fcx, &variant.node.data))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
@ -1014,7 +1014,7 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
|
||||
convert_field(ccx, &scheme.generics, &predicates, f, ty_f)
|
||||
}
|
||||
|
||||
if struct_def.kind != hir::VariantKind::Dict {
|
||||
if struct_def.kind != hir::VariantKind::Struct {
|
||||
convert_variant_ctor(tcx, struct_def.id, variant, scheme, predicates);
|
||||
}
|
||||
},
|
||||
@ -1039,7 +1039,7 @@ fn convert_variant_ctor<'a, 'tcx>(tcx: &ty::ctxt<'tcx>,
|
||||
scheme: ty::TypeScheme<'tcx>,
|
||||
predicates: ty::GenericPredicates<'tcx>) {
|
||||
let ctor_ty = match variant.kind() {
|
||||
VariantKind::Unit | VariantKind::Dict => scheme.ty,
|
||||
VariantKind::Unit | VariantKind::Struct => scheme.ty,
|
||||
VariantKind::Tuple => {
|
||||
let inputs: Vec<_> =
|
||||
variant.fields
|
||||
@ -1067,7 +1067,7 @@ fn convert_enum_variant_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
|
||||
variants: &[P<hir::Variant>]) {
|
||||
// fill the field types
|
||||
for (variant, ty_variant) in variants.iter().zip(def.variants.iter()) {
|
||||
for (f, ty_f) in variant.node.def.fields.iter().zip(ty_variant.fields.iter()) {
|
||||
for (f, ty_f) in variant.node.data.fields.iter().zip(ty_variant.fields.iter()) {
|
||||
convert_field(ccx, &scheme.generics, &predicates, f, ty_f)
|
||||
}
|
||||
|
||||
@ -1075,7 +1075,7 @@ fn convert_enum_variant_types<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
|
||||
// an item.
|
||||
convert_variant_ctor(
|
||||
ccx.tcx,
|
||||
variant.node.def.id,
|
||||
variant.node.data.id,
|
||||
ty_variant,
|
||||
scheme.clone(),
|
||||
predicates.clone()
|
||||
@ -1087,7 +1087,7 @@ fn convert_struct_variant<'tcx>(tcx: &ty::ctxt<'tcx>,
|
||||
did: DefId,
|
||||
name: ast::Name,
|
||||
disr_val: ty::Disr,
|
||||
def: &hir::StructDef) -> ty::VariantDefData<'tcx, 'tcx> {
|
||||
def: &hir::VariantData) -> ty::VariantDefData<'tcx, '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);
|
||||
@ -1120,12 +1120,12 @@ fn convert_struct_variant<'tcx>(tcx: &ty::ctxt<'tcx>,
|
||||
|
||||
fn convert_struct_def<'tcx>(tcx: &ty::ctxt<'tcx>,
|
||||
it: &hir::Item,
|
||||
def: &hir::StructDef)
|
||||
def: &hir::VariantData)
|
||||
-> ty::AdtDefMaster<'tcx>
|
||||
{
|
||||
|
||||
let did = tcx.map.local_def_id(it.id);
|
||||
let ctor_id = if def.kind != hir::VariantKind::Dict {
|
||||
let ctor_id = if def.kind != hir::VariantKind::Struct {
|
||||
tcx.map.local_def_id(def.id)
|
||||
} else {
|
||||
did
|
||||
@ -1209,9 +1209,9 @@ fn convert_enum_def<'tcx>(tcx: &ty::ctxt<'tcx>,
|
||||
disr: ty::Disr)
|
||||
-> ty::VariantDefData<'tcx, 'tcx>
|
||||
{
|
||||
let did = tcx.map.local_def_id(v.node.def.id);
|
||||
let did = tcx.map.local_def_id(v.node.data.id);
|
||||
let name = v.node.name;
|
||||
convert_struct_variant(tcx, did, name, disr, &v.node.def, did)
|
||||
convert_struct_variant(tcx, did, name, disr, &v.node.data, did)
|
||||
}
|
||||
let did = tcx.map.local_def_id(it.id);
|
||||
let repr_hints = tcx.lookup_repr_hints(did);
|
||||
|
@ -1805,7 +1805,7 @@ pub struct VariantStruct {
|
||||
pub fields_stripped: bool,
|
||||
}
|
||||
|
||||
impl Clean<VariantStruct> for ::rustc_front::hir::StructDef {
|
||||
impl Clean<VariantStruct> for ::rustc_front::hir::VariantData {
|
||||
fn clean(&self, cx: &DocContext) -> VariantStruct {
|
||||
VariantStruct {
|
||||
struct_type: doctree::struct_type_from_def(self),
|
||||
@ -1871,7 +1871,7 @@ impl<'tcx> Clean<Item> for ty::VariantDefData<'tcx, 'static> {
|
||||
self.fields.iter().map(|f| f.unsubst_ty().clean(cx)).collect()
|
||||
)
|
||||
}
|
||||
ty::VariantKind::Dict => {
|
||||
ty::VariantKind::Struct => {
|
||||
StructVariant(VariantStruct {
|
||||
struct_type: doctree::Plain,
|
||||
fields_stripped: false,
|
||||
@ -1917,8 +1917,8 @@ pub enum VariantKind {
|
||||
StructVariant(VariantStruct),
|
||||
}
|
||||
|
||||
fn struct_def_to_variant_kind(struct_def: &hir::StructDef, cx: &DocContext) -> VariantKind {
|
||||
if struct_def.kind == hir::VariantKind::Dict {
|
||||
fn struct_def_to_variant_kind(struct_def: &hir::VariantData, cx: &DocContext) -> VariantKind {
|
||||
if struct_def.kind == hir::VariantKind::Struct {
|
||||
StructVariant(struct_def.clean(cx))
|
||||
} else if struct_def.kind == hir::VariantKind::Unit {
|
||||
CLikeVariant
|
||||
|
@ -119,7 +119,7 @@ pub struct Enum {
|
||||
pub struct Variant {
|
||||
pub name: Name,
|
||||
pub attrs: Vec<ast::Attribute>,
|
||||
pub def: P<hir::StructDef>,
|
||||
pub def: P<hir::VariantData>,
|
||||
pub stab: Option<attr::Stability>,
|
||||
pub whence: Span,
|
||||
}
|
||||
@ -233,8 +233,8 @@ pub struct Import {
|
||||
pub whence: Span,
|
||||
}
|
||||
|
||||
pub fn struct_type_from_def(sd: &hir::StructDef) -> StructType {
|
||||
if sd.kind != hir::VariantKind::Dict {
|
||||
pub fn struct_type_from_def(sd: &hir::VariantData) -> StructType {
|
||||
if sd.kind != hir::VariantKind::Struct {
|
||||
// We are in a tuple-struct
|
||||
match sd.fields.len() {
|
||||
0 => Unit,
|
||||
|
@ -84,8 +84,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||
self.module.is_crate = true;
|
||||
}
|
||||
|
||||
pub fn visit_struct_def(&mut self, item: &hir::Item,
|
||||
name: ast::Name, sd: &hir::StructDef,
|
||||
pub fn visit_variant_data(&mut self, item: &hir::Item,
|
||||
name: ast::Name, sd: &hir::VariantData,
|
||||
generics: &hir::Generics) -> Struct {
|
||||
debug!("Visiting struct");
|
||||
let struct_type = struct_type_from_def(&*sd);
|
||||
@ -111,8 +111,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||
variants: def.variants.iter().map(|v| Variant {
|
||||
name: v.node.name,
|
||||
attrs: v.node.attrs.clone(),
|
||||
stab: self.stability(v.node.def.id),
|
||||
def: v.node.def.clone(),
|
||||
stab: self.stability(v.node.data.id),
|
||||
def: v.node.data.clone(),
|
||||
whence: v.span,
|
||||
}).collect(),
|
||||
vis: it.vis,
|
||||
@ -298,7 +298,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
||||
hir::ItemEnum(ref ed, ref gen) =>
|
||||
om.enums.push(self.visit_enum_def(item, name, ed, gen)),
|
||||
hir::ItemStruct(ref sd, ref gen) =>
|
||||
om.structs.push(self.visit_struct_def(item, name, &**sd, gen)),
|
||||
om.structs.push(self.visit_variant_data(item, name, &**sd, gen)),
|
||||
hir::ItemFn(ref fd, ref unsafety, constness, ref abi, ref gen, _) =>
|
||||
om.fns.push(self.visit_fn(item, name, &**fd, unsafety,
|
||||
constness, abi, gen)),
|
||||
|
@ -1579,7 +1579,7 @@ pub struct EnumDef {
|
||||
pub struct Variant_ {
|
||||
pub name: Ident,
|
||||
pub attrs: Vec<Attribute>,
|
||||
pub def: P<StructDef>,
|
||||
pub data: P<VariantData>,
|
||||
/// Explicit discriminant, eg `Foo = 1`
|
||||
pub disr_expr: Option<P<Expr>>,
|
||||
}
|
||||
@ -1742,13 +1742,13 @@ impl StructFieldKind {
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub enum VariantKind {
|
||||
Dict,
|
||||
Struct,
|
||||
Tuple,
|
||||
Unit,
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
||||
pub struct StructDef {
|
||||
pub struct VariantData {
|
||||
/// Fields, not including ctor
|
||||
pub fields: Vec<StructField>,
|
||||
/// ID of the constructor. This is only used for tuple- or enum-like
|
||||
@ -1798,7 +1798,7 @@ pub enum Item_ {
|
||||
/// An enum definition, e.g. `enum Foo<A, B> {C<A>, D<B>}`
|
||||
ItemEnum(EnumDef, Generics),
|
||||
/// A struct definition, e.g. `struct Foo<A> {x: A}`
|
||||
ItemStruct(P<StructDef>, Generics),
|
||||
ItemStruct(P<VariantData>, Generics),
|
||||
/// Represents a Trait Declaration
|
||||
ItemTrait(Unsafety,
|
||||
Generics,
|
||||
|
@ -452,8 +452,8 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
|
||||
visit::walk_struct_field(self, struct_field)
|
||||
}
|
||||
|
||||
fn visit_struct_def(&mut self,
|
||||
struct_def: &StructDef,
|
||||
fn visit_variant_data(&mut self,
|
||||
struct_def: &VariantData,
|
||||
_: ast::Ident,
|
||||
_: &ast::Generics,
|
||||
_: NodeId,
|
||||
|
@ -140,13 +140,13 @@ fn fold_item_underscore<F>(cx: &mut Context<F>, item: ast::Item_) -> ast::Item_
|
||||
if !(cx.in_cfg)(&v.node.attrs) {
|
||||
None
|
||||
} else {
|
||||
Some(v.map(|Spanned {node: ast::Variant_ {name, attrs, def,
|
||||
Some(v.map(|Spanned {node: ast::Variant_ {name, attrs, data,
|
||||
disr_expr}, span}| {
|
||||
Spanned {
|
||||
node: ast::Variant_ {
|
||||
name: name,
|
||||
attrs: attrs,
|
||||
def: fold_struct(cx, def),
|
||||
data: fold_struct(cx, data),
|
||||
disr_expr: disr_expr,
|
||||
},
|
||||
span: span
|
||||
@ -164,11 +164,11 @@ fn fold_item_underscore<F>(cx: &mut Context<F>, item: ast::Item_) -> ast::Item_
|
||||
fold::noop_fold_item_underscore(item, cx)
|
||||
}
|
||||
|
||||
fn fold_struct<F>(cx: &mut Context<F>, def: P<ast::StructDef>) -> P<ast::StructDef> where
|
||||
fn fold_struct<F>(cx: &mut Context<F>, def: P<ast::VariantData>) -> P<ast::VariantData> where
|
||||
F: FnMut(&[ast::Attribute]) -> bool
|
||||
{
|
||||
def.map(|ast::StructDef { fields, id, kind }| {
|
||||
ast::StructDef {
|
||||
def.map(|ast::VariantData { fields, id, kind }| {
|
||||
ast::VariantData {
|
||||
fields: fields.into_iter().filter(|m| {
|
||||
(cx.in_cfg)(&m.node.attrs)
|
||||
}).collect(),
|
||||
|
@ -247,9 +247,9 @@ pub trait AstBuilder {
|
||||
fn item_struct_poly(&self,
|
||||
span: Span,
|
||||
name: Ident,
|
||||
struct_def: ast::StructDef,
|
||||
struct_def: ast::VariantData,
|
||||
generics: Generics) -> P<ast::Item>;
|
||||
fn item_struct(&self, span: Span, name: Ident, struct_def: ast::StructDef) -> P<ast::Item>;
|
||||
fn item_struct(&self, span: Span, name: Ident, struct_def: ast::VariantData) -> P<ast::Item>;
|
||||
|
||||
fn item_mod(&self, span: Span, inner_span: Span,
|
||||
name: Ident, attrs: Vec<ast::Attribute>,
|
||||
@ -1008,7 +1008,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||
ast::Variant_ {
|
||||
name: name,
|
||||
attrs: Vec::new(),
|
||||
def: P(ast::StructDef { fields: fields,
|
||||
data: P(ast::VariantData { fields: fields,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
kind: kind }),
|
||||
disr_expr: None,
|
||||
@ -1028,7 +1028,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||
}
|
||||
|
||||
fn item_struct(&self, span: Span, name: Ident,
|
||||
struct_def: ast::StructDef) -> P<ast::Item> {
|
||||
struct_def: ast::VariantData) -> P<ast::Item> {
|
||||
self.item_struct_poly(
|
||||
span,
|
||||
name,
|
||||
@ -1038,7 +1038,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
|
||||
}
|
||||
|
||||
fn item_struct_poly(&self, span: Span, name: Ident,
|
||||
struct_def: ast::StructDef, generics: Generics) -> P<ast::Item> {
|
||||
struct_def: ast::VariantData, generics: Generics) -> P<ast::Item> {
|
||||
self.item(span, name, Vec::new(), ast::ItemStruct(P(struct_def), generics))
|
||||
}
|
||||
|
||||
|
@ -174,9 +174,9 @@
|
||||
//! A static method on the types above would result in,
|
||||
//!
|
||||
//! ```{.text}
|
||||
//! StaticStruct(<ast::StructDef of A>, Named(vec![(<ident of x>, <span of x>)]))
|
||||
//! StaticStruct(<ast::VariantData of A>, Named(vec![(<ident of x>, <span of x>)]))
|
||||
//!
|
||||
//! StaticStruct(<ast::StructDef of B>, Unnamed(vec![<span of x>]))
|
||||
//! StaticStruct(<ast::VariantData of B>, Unnamed(vec![<span of x>]))
|
||||
//!
|
||||
//! StaticEnum(<ast::EnumDef of C>,
|
||||
//! vec![(<ident of C0>, <span of C0>, Unnamed(vec![<span of i32>])),
|
||||
@ -194,7 +194,7 @@ use std::vec;
|
||||
use abi::Abi;
|
||||
use abi;
|
||||
use ast;
|
||||
use ast::{EnumDef, Expr, Ident, Generics, StructDef};
|
||||
use ast::{EnumDef, Expr, Ident, Generics, VariantData};
|
||||
use ast_util;
|
||||
use attr;
|
||||
use attr::AttrMetaMethods;
|
||||
@ -317,7 +317,7 @@ pub enum SubstructureFields<'a> {
|
||||
EnumNonMatchingCollapsed(Vec<Ident>, &'a [P<ast::Variant>], &'a [Ident]),
|
||||
|
||||
/// A static method where `Self` is a struct.
|
||||
StaticStruct(&'a ast::StructDef, StaticFields),
|
||||
StaticStruct(&'a ast::VariantData, StaticFields),
|
||||
/// A static method where `Self` is an enum.
|
||||
StaticEnum(&'a ast::EnumDef, Vec<(Ident, Span, StaticFields)>),
|
||||
}
|
||||
@ -649,7 +649,7 @@ impl<'a> TraitDef<'a> {
|
||||
|
||||
fn expand_struct_def(&self,
|
||||
cx: &mut ExtCtxt,
|
||||
struct_def: &'a StructDef,
|
||||
struct_def: &'a VariantData,
|
||||
type_ident: Ident,
|
||||
generics: &Generics) -> P<ast::Item> {
|
||||
let field_tys: Vec<P<ast::Ty>> = struct_def.fields.iter()
|
||||
@ -700,7 +700,7 @@ impl<'a> TraitDef<'a> {
|
||||
let mut field_tys = Vec::new();
|
||||
|
||||
for variant in &enum_def.variants {
|
||||
field_tys.extend(variant.node.def.fields.iter()
|
||||
field_tys.extend(variant.node.data.fields.iter()
|
||||
.map(|field| field.node.ty.clone()));
|
||||
}
|
||||
|
||||
@ -927,7 +927,7 @@ impl<'a> MethodDef<'a> {
|
||||
fn expand_struct_method_body<'b>(&self,
|
||||
cx: &mut ExtCtxt,
|
||||
trait_: &TraitDef<'b>,
|
||||
struct_def: &'b StructDef,
|
||||
struct_def: &'b VariantData,
|
||||
type_ident: Ident,
|
||||
self_args: &[P<Expr>],
|
||||
nonself_args: &[P<Expr>])
|
||||
@ -996,7 +996,7 @@ impl<'a> MethodDef<'a> {
|
||||
fn expand_static_struct_method_body(&self,
|
||||
cx: &mut ExtCtxt,
|
||||
trait_: &TraitDef,
|
||||
struct_def: &StructDef,
|
||||
struct_def: &VariantData,
|
||||
type_ident: Ident,
|
||||
self_args: &[P<Expr>],
|
||||
nonself_args: &[P<Expr>])
|
||||
@ -1405,7 +1405,7 @@ impl<'a> MethodDef<'a> {
|
||||
-> P<Expr> {
|
||||
let summary = enum_def.variants.iter().map(|v| {
|
||||
let ident = v.node.name;
|
||||
let summary = trait_.summarise_struct(cx, &v.node.def);
|
||||
let summary = trait_.summarise_struct(cx, &v.node.data);
|
||||
(ident, v.span, summary)
|
||||
}).collect();
|
||||
self.call_substructure_method(cx, trait_, type_ident,
|
||||
@ -1441,7 +1441,7 @@ impl<'a> TraitDef<'a> {
|
||||
|
||||
fn summarise_struct(&self,
|
||||
cx: &mut ExtCtxt,
|
||||
struct_def: &StructDef) -> StaticFields {
|
||||
struct_def: &VariantData) -> StaticFields {
|
||||
let mut named_idents = Vec::new();
|
||||
let mut just_spans = Vec::new();
|
||||
for field in struct_def.fields.iter(){
|
||||
@ -1477,7 +1477,7 @@ impl<'a> TraitDef<'a> {
|
||||
fn create_struct_pattern(&self,
|
||||
cx: &mut ExtCtxt,
|
||||
struct_path: ast::Path,
|
||||
struct_def: &'a StructDef,
|
||||
struct_def: &'a VariantData,
|
||||
prefix: &str,
|
||||
mutbl: ast::Mutability)
|
||||
-> (P<ast::Pat>, Vec<(Span, Option<Ident>,
|
||||
@ -1545,7 +1545,7 @@ impl<'a> TraitDef<'a> {
|
||||
-> (P<ast::Pat>, Vec<(Span, Option<Ident>, P<Expr>, &'a [ast::Attribute])>) {
|
||||
let variant_ident = variant.node.name;
|
||||
let variant_path = cx.path(variant.span, vec![enum_ident, variant_ident]);
|
||||
self.create_struct_pattern(cx, variant_path, &variant.node.def, prefix, mutbl)
|
||||
self.create_struct_pattern(cx, variant_path, &variant.node.data, prefix, mutbl)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure
|
||||
let mut arms = Vec::new();
|
||||
|
||||
for variant in &enum_def.variants {
|
||||
let def = &variant.node.def;
|
||||
let def = &variant.node.data;
|
||||
if def.kind != ast::VariantKind::Unit {
|
||||
cx.span_err(trait_span, "`FromPrimitive` cannot be derived \
|
||||
for enums with non-unit variants");
|
||||
|
@ -857,10 +857,10 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
|
||||
visit::walk_item(self, i);
|
||||
}
|
||||
|
||||
fn visit_struct_def(&mut self, s: &'v ast::StructDef, _: ast::Ident,
|
||||
fn visit_variant_data(&mut self, s: &'v ast::VariantData, _: ast::Ident,
|
||||
_: &'v ast::Generics, _: ast::NodeId, span: Span) {
|
||||
if s.fields.is_empty() {
|
||||
if s.kind == ast::VariantKind::Dict {
|
||||
if s.kind == ast::VariantKind::Struct {
|
||||
self.gate_feature("braced_empty_structs", span,
|
||||
"empty structs and enum variants with braces are unstable");
|
||||
} else if s.kind == ast::VariantKind::Tuple {
|
||||
|
@ -231,7 +231,7 @@ pub trait Folder : Sized {
|
||||
noop_fold_poly_trait_ref(p, self)
|
||||
}
|
||||
|
||||
fn fold_struct_def(&mut self, struct_def: P<StructDef>) -> P<StructDef> {
|
||||
fn fold_variant_data(&mut self, struct_def: P<VariantData>) -> P<VariantData> {
|
||||
noop_fold_struct_def(struct_def, self)
|
||||
}
|
||||
|
||||
@ -446,11 +446,11 @@ 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_ {name, attrs, def, disr_expr}, span}| Spanned {
|
||||
v.map(|Spanned {node: Variant_ {name, attrs, data, disr_expr}, span}| Spanned {
|
||||
node: Variant_ {
|
||||
name: name,
|
||||
attrs: fold_attrs(attrs, fld),
|
||||
def: fld.fold_struct_def(def),
|
||||
data: fld.fold_variant_data(data),
|
||||
disr_expr: disr_expr.map(|e| fld.fold_expr(e)),
|
||||
},
|
||||
span: fld.new_span(span),
|
||||
@ -814,8 +814,8 @@ pub fn noop_fold_where_predicate<T: Folder>(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn noop_fold_struct_def<T: Folder>(struct_def: P<StructDef>, fld: &mut T) -> P<StructDef> {
|
||||
struct_def.map(|StructDef { fields, id, kind }| StructDef {
|
||||
pub fn noop_fold_struct_def<T: Folder>(struct_def: P<VariantData>, fld: &mut T) -> P<VariantData> {
|
||||
struct_def.map(|VariantData { fields, id, kind }| VariantData {
|
||||
fields: fields.move_map(|f| fld.fold_struct_field(f)),
|
||||
id: fld.new_id(id),
|
||||
kind: kind,
|
||||
@ -925,7 +925,7 @@ pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ {
|
||||
folder.fold_generics(generics))
|
||||
}
|
||||
ItemStruct(struct_def, generics) => {
|
||||
let struct_def = folder.fold_struct_def(struct_def);
|
||||
let struct_def = folder.fold_variant_data(struct_def);
|
||||
ItemStruct(struct_def, folder.fold_generics(generics))
|
||||
}
|
||||
ItemDefaultImpl(unsafety, ref trait_ref) => {
|
||||
|
@ -45,7 +45,7 @@ use ast::{PatRegion, PatStruct, PatTup, PatVec, PatWild, PatWildMulti};
|
||||
use ast::PatWildSingle;
|
||||
use ast::{PolyTraitRef, QSelf};
|
||||
use ast::{Return, BiShl, BiShr, Stmt, StmtDecl};
|
||||
use ast::{StmtExpr, StmtSemi, StmtMac, StructDef, StructField, VariantKind};
|
||||
use ast::{StmtExpr, StmtSemi, StmtMac, VariantData, StructField, VariantKind};
|
||||
use ast::{BiSub, StrStyle};
|
||||
use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue};
|
||||
use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef};
|
||||
@ -4647,7 +4647,7 @@ impl<'a> Parser<'a> {
|
||||
(Vec::new(), VariantKind::Unit)
|
||||
} else {
|
||||
// If we see: `struct Foo<T> where T: Copy { ... }`
|
||||
(try!(self.parse_record_struct_body()), VariantKind::Dict)
|
||||
(try!(self.parse_record_struct_body()), VariantKind::Struct)
|
||||
}
|
||||
// No `where` so: `struct Foo<T>;`
|
||||
} else if try!(self.eat(&token::Semi) ){
|
||||
@ -4655,7 +4655,7 @@ impl<'a> Parser<'a> {
|
||||
// Record-style struct definition
|
||||
} else if self.token == token::OpenDelim(token::Brace) {
|
||||
let fields = try!(self.parse_record_struct_body());
|
||||
(fields, VariantKind::Dict)
|
||||
(fields, VariantKind::Struct)
|
||||
// Tuple-style struct definition with optional where-clause.
|
||||
} else if self.token == token::OpenDelim(token::Paren) {
|
||||
let fields = try!(self.parse_tuple_struct_body(&mut generics));
|
||||
@ -4667,7 +4667,7 @@ impl<'a> Parser<'a> {
|
||||
};
|
||||
|
||||
Ok((class_name,
|
||||
ItemStruct(P(ast::StructDef {
|
||||
ItemStruct(P(ast::VariantData {
|
||||
fields: fields,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
kind: kind,
|
||||
@ -5103,17 +5103,17 @@ impl<'a> Parser<'a> {
|
||||
|
||||
/// Parse a structure-like enum variant definition
|
||||
/// this should probably be renamed or refactored...
|
||||
fn parse_struct_def(&mut self) -> PResult<P<StructDef>> {
|
||||
fn parse_struct_def(&mut self) -> PResult<P<VariantData>> {
|
||||
let mut fields: Vec<StructField> = Vec::new();
|
||||
while self.token != token::CloseDelim(token::Brace) {
|
||||
fields.push(try!(self.parse_struct_decl_field(false)));
|
||||
}
|
||||
try!(self.bump());
|
||||
|
||||
Ok(P(StructDef {
|
||||
Ok(P(VariantData {
|
||||
fields: fields,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
kind: VariantKind::Dict,
|
||||
kind: VariantKind::Struct,
|
||||
}))
|
||||
}
|
||||
|
||||
@ -5150,17 +5150,17 @@ impl<'a> Parser<'a> {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
}});
|
||||
}
|
||||
struct_def = P(StructDef { fields: fields,
|
||||
struct_def = P(VariantData { fields: fields,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
kind: ast::VariantKind::Tuple });
|
||||
} else if try!(self.eat(&token::Eq) ){
|
||||
disr_expr = Some(try!(self.parse_expr_nopanic()));
|
||||
any_disr = disr_expr.as_ref().map(|expr| expr.span);
|
||||
struct_def = P(StructDef { fields: Vec::new(),
|
||||
struct_def = P(VariantData { fields: Vec::new(),
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
kind: ast::VariantKind::Unit });
|
||||
} else {
|
||||
struct_def = P(StructDef { fields: Vec::new(),
|
||||
struct_def = P(VariantData { fields: Vec::new(),
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
kind: ast::VariantKind::Unit });
|
||||
}
|
||||
@ -5168,7 +5168,7 @@ impl<'a> Parser<'a> {
|
||||
let vr = ast::Variant_ {
|
||||
name: ident,
|
||||
attrs: variant_attrs,
|
||||
def: struct_def,
|
||||
data: struct_def,
|
||||
disr_expr: disr_expr,
|
||||
};
|
||||
variants.push(P(spanned(vlo, self.last_span.hi, vr)));
|
||||
|
@ -1385,14 +1385,14 @@ impl<'a> State<'a> {
|
||||
}
|
||||
|
||||
pub fn print_struct(&mut self,
|
||||
struct_def: &ast::StructDef,
|
||||
struct_def: &ast::VariantData,
|
||||
generics: &ast::Generics,
|
||||
ident: ast::Ident,
|
||||
span: codemap::Span,
|
||||
print_finalizer: bool) -> io::Result<()> {
|
||||
try!(self.print_ident(ident));
|
||||
try!(self.print_generics(generics));
|
||||
if struct_def.kind != ast::VariantKind::Dict {
|
||||
if struct_def.kind != ast::VariantKind::Struct {
|
||||
if struct_def.kind == ast::VariantKind::Tuple {
|
||||
try!(self.popen());
|
||||
try!(self.commasep(
|
||||
@ -1510,7 +1510,7 @@ impl<'a> State<'a> {
|
||||
pub fn print_variant(&mut self, v: &ast::Variant) -> io::Result<()> {
|
||||
try!(self.head(""));
|
||||
let generics = ast_util::empty_generics();
|
||||
try!(self.print_struct(&v.node.def, &generics, v.node.name, v.span, false));
|
||||
try!(self.print_struct(&v.node.data, &generics, v.node.name, v.span, false));
|
||||
match v.node.disr_expr {
|
||||
Some(ref d) => {
|
||||
try!(space(&mut self.s));
|
||||
@ -3119,7 +3119,7 @@ mod tests {
|
||||
name: ident,
|
||||
attrs: Vec::new(),
|
||||
// making this up as I go.... ?
|
||||
def: P(ast::StructDef { fields: Vec::new(),
|
||||
data: P(ast::VariantData { fields: Vec::new(),
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
kind: ast::VariantKind::Unit }),
|
||||
disr_expr: None,
|
||||
|
@ -80,7 +80,7 @@ pub trait Visitor<'v> : Sized {
|
||||
fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef, m: &'v TraitBoundModifier) {
|
||||
walk_poly_trait_ref(self, t, m)
|
||||
}
|
||||
fn visit_struct_def(&mut self, s: &'v StructDef, _: Ident,
|
||||
fn visit_variant_data(&mut self, s: &'v VariantData, _: Ident,
|
||||
_: &'v Generics, _: NodeId, _: Span) {
|
||||
walk_struct_def(self, s)
|
||||
}
|
||||
@ -289,7 +289,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
|
||||
}
|
||||
ItemStruct(ref struct_definition, ref generics) => {
|
||||
visitor.visit_generics(generics);
|
||||
visitor.visit_struct_def(struct_definition, item.ident,
|
||||
visitor.visit_variant_data(struct_definition, item.ident,
|
||||
generics, item.id, item.span);
|
||||
}
|
||||
ItemTrait(_, ref generics, ref bounds, ref methods) => {
|
||||
@ -316,7 +316,7 @@ pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||
generics: &'v Generics,
|
||||
item_id: NodeId) {
|
||||
visitor.visit_ident(variant.span, variant.node.name);
|
||||
visitor.visit_struct_def(&variant.node.def, variant.node.name,
|
||||
visitor.visit_variant_data(&variant.node.data, variant.node.name,
|
||||
generics, item_id, variant.span);
|
||||
walk_list!(visitor, visit_expr, &variant.node.disr_expr);
|
||||
walk_list!(visitor, visit_attribute, &variant.node.attrs);
|
||||
@ -603,7 +603,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt
|
||||
}
|
||||
|
||||
pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||
struct_definition: &'v StructDef) {
|
||||
struct_definition: &'v VariantData) {
|
||||
walk_list!(visitor, visit_struct_field, &struct_definition.fields);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user