Skip to content

Commit 46750d0

Browse files
committed
Merge VariantData and VariantData_
1 parent a5225cb commit 46750d0

File tree

28 files changed

+141
-161
lines changed

28 files changed

+141
-161
lines changed

src/librustc/front/map/collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
134134
ItemEnum(ref enum_definition, _) => {
135135
for v in &enum_definition.variants {
136136
let variant_def_index =
137-
self.insert_def(v.node.data.id,
137+
self.insert_def(v.node.data.id(),
138138
NodeVariant(&**v),
139139
DefPathData::EnumVariant(v.node.name));
140140

@@ -151,7 +151,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
151151
ItemStruct(ref struct_def, _) => {
152152
// If this is a tuple-like struct, register the constructor.
153153
if !struct_def.is_struct() {
154-
self.insert_def(struct_def.id,
154+
self.insert_def(struct_def.id(),
155155
NodeStructCtor(&**struct_def),
156156
DefPathData::StructCtor);
157157
}

src/librustc/metadata/encoder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ fn each_auxiliary_node_id<F>(item: &hir::Item, callback: F) -> bool where
382382
hir::ItemStruct(ref struct_def, _) => {
383383
// If this is a newtype struct, return the constructor.
384384
if struct_def.is_tuple() {
385-
continue_ = callback(struct_def.id);
385+
continue_ = callback(struct_def.id());
386386
}
387387
}
388388
_ => {}
@@ -1019,7 +1019,7 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
10191019
encode_attributes(rbml_w, &item.attrs);
10201020
encode_repr_attrs(rbml_w, ecx, &item.attrs);
10211021
for v in &enum_definition.variants {
1022-
encode_variant_id(rbml_w, ecx.tcx.map.local_def_id(v.node.data.id));
1022+
encode_variant_id(rbml_w, ecx.tcx.map.local_def_id(v.node.data.id()));
10231023
}
10241024
encode_inlined_item(ecx, rbml_w, InlinedItemRef::Item(item));
10251025
encode_path(rbml_w, path);
@@ -1069,7 +1069,7 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
10691069
encode_inherent_implementations(ecx, rbml_w, def_id);
10701070

10711071
if !struct_def.is_struct() {
1072-
let ctor_did = ecx.tcx.map.local_def_id(struct_def.id);
1072+
let ctor_did = ecx.tcx.map.local_def_id(struct_def.id());
10731073
rbml_w.wr_tagged_u64(tag_items_data_item_struct_ctor,
10741074
def_to_u64(ctor_did));
10751075
}
@@ -1082,7 +1082,7 @@ fn encode_info_for_item<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
10821082

10831083
// If this is a tuple-like struct, encode the type of the constructor.
10841084
if !struct_def.is_struct() {
1085-
encode_info_for_struct_ctor(ecx, rbml_w, item.name, struct_def.id, index, item.id);
1085+
encode_info_for_struct_ctor(ecx, rbml_w, item.name, struct_def.id(), index, item.id);
10861086
}
10871087
}
10881088
hir::ItemDefaultImpl(unsafety, _) => {

src/librustc/middle/astencode.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,17 +1315,17 @@ fn copy_item_types(dcx: &DecodeContext, ii: &InlinedItem, orig_did: DefId) {
13151315
def.variants.iter().zip(orig_def.variants.iter())
13161316
{
13171317
debug!("astencode: copying variant {:?} => {:?}",
1318-
orig_variant.did, i_variant.node.data.id);
1319-
copy_item_type(dcx, i_variant.node.data.id, orig_variant.did);
1318+
orig_variant.did, i_variant.node.data.id());
1319+
copy_item_type(dcx, i_variant.node.data.id(), orig_variant.did);
13201320
}
13211321
}
13221322
hir::ItemStruct(ref def, _) => {
13231323
if !def.is_struct() {
13241324
let ctor_did = dcx.tcx.lookup_adt_def(orig_did)
13251325
.struct_variant().did;
13261326
debug!("astencode: copying ctor {:?} => {:?}", ctor_did,
1327-
def.id);
1328-
copy_item_type(dcx, def.id, ctor_did);
1327+
def.id());
1328+
copy_item_type(dcx, def.id(), ctor_did);
13291329
}
13301330
}
13311331
_ => {}

src/librustc/middle/check_static_recursion.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
168168
let mut discriminant_map = self.discriminant_map.borrow_mut();
169169
match enum_definition.variants.first() {
170170
None => { return; }
171-
Some(variant) if discriminant_map.contains_key(&variant.node.data.id) => {
171+
Some(variant) if discriminant_map.contains_key(&variant.node.data.id()) => {
172172
return;
173173
}
174174
_ => {}
@@ -177,7 +177,7 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
177177
// Go through all the variants.
178178
let mut variant_stack: Vec<ast::NodeId> = Vec::new();
179179
for variant in enum_definition.variants.iter().rev() {
180-
variant_stack.push(variant.node.data.id);
180+
variant_stack.push(variant.node.data.id());
181181
// When we find an expression, every variant currently on the stack
182182
// is affected by that expression.
183183
if let Some(ref expr) = variant.node.disr_expr {
@@ -208,7 +208,7 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
208208

209209
fn visit_variant(&mut self, variant: &'ast hir::Variant,
210210
_: &'ast hir::Generics, _: ast::NodeId) {
211-
let variant_id = variant.node.data.id;
211+
let variant_id = variant.node.data.id();
212212
let maybe_expr;
213213
if let Some(get_expr) = self.discriminant_map.borrow().get(&variant_id) {
214214
// This is necessary because we need to let the `discriminant_map`

src/librustc/middle/const_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn lookup_variant_by_id<'a>(tcx: &'a ty::ctxt,
6363
fn variant_expr<'a>(variants: &'a [P<hir::Variant>], id: ast::NodeId)
6464
-> Option<&'a Expr> {
6565
for variant in variants {
66-
if variant.node.data.id == id {
66+
if variant.node.data.id() == id {
6767
return variant.node.disr_expr.as_ref().map(|e| &**e);
6868
}
6969
}

src/librustc/middle/dead.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ impl<'v> Visitor<'v> for LifeSeeder {
339339
}
340340
match item.node {
341341
hir::ItemEnum(ref enum_def, _) if allow_dead_code => {
342-
self.worklist.extend(enum_def.variants.iter().map(|variant| variant.node.data.id));
342+
self.worklist.extend(enum_def.variants.iter()
343+
.map(|variant| variant.node.data.id()));
343344
}
344345
hir::ItemTrait(_, _, _, ref trait_items) => {
345346
for trait_item in trait_items {
@@ -427,7 +428,7 @@ fn find_live(tcx: &ty::ctxt,
427428
fn get_struct_ctor_id(item: &hir::Item) -> Option<ast::NodeId> {
428429
match item.node {
429430
hir::ItemStruct(ref struct_def, _) if !struct_def.is_struct() => {
430-
Some(struct_def.id)
431+
Some(struct_def.id())
431432
}
432433
_ => None
433434
}
@@ -466,7 +467,7 @@ impl<'a, 'tcx> DeadVisitor<'a, 'tcx> {
466467
}
467468

468469
fn should_warn_about_variant(&mut self, variant: &hir::Variant_) -> bool {
469-
!self.symbol_is_live(variant.data.id, None)
470+
!self.symbol_is_live(variant.data.id(), None)
470471
&& !has_allow_dead_code_or_lang_attr(&variant.attrs)
471472
}
472473

@@ -542,7 +543,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for DeadVisitor<'a, 'tcx> {
542543
hir::ItemEnum(ref enum_def, _) => {
543544
for variant in &enum_def.variants {
544545
if self.should_warn_about_variant(&variant.node) {
545-
self.warn_dead_code(variant.node.data.id, variant.span,
546+
self.warn_dead_code(variant.node.data.id(), variant.span,
546547
variant.node.name, "variant");
547548
}
548549
}

src/librustc/middle/stability.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
186186

187187
if let hir::ItemStruct(ref sd, _) = i.node {
188188
if !sd.is_struct() {
189-
self.annotate(sd.id, true, &i.attrs, i.span, |_| {}, true)
189+
self.annotate(sd.id(), true, &i.attrs, i.span, |_| {}, true)
190190
}
191191
}
192192
}
@@ -208,7 +208,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Annotator<'a, 'tcx> {
208208
}
209209

210210
fn visit_variant(&mut self, var: &Variant, g: &'v Generics, item_id: NodeId) {
211-
self.annotate(var.node.data.id, true, &var.node.attrs, var.span,
211+
self.annotate(var.node.data.id(), true, &var.node.attrs, var.span,
212212
|v| visit::walk_variant(v, var, g, item_id), true)
213213
}
214214

src/librustc_front/fold.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -694,18 +694,15 @@ pub fn noop_fold_where_predicate<T: Folder>(pred: WherePredicate, fld: &mut T) -
694694
}
695695

696696
pub fn noop_fold_struct_def<T: Folder>(struct_def: P<VariantData>, fld: &mut T) -> P<VariantData> {
697-
struct_def.map(|VariantData { data_, id }| {
698-
VariantData {
699-
data_: match data_ {
700-
VariantData_::Struct(fields) => {
701-
VariantData_::Struct(fields.move_map(|f| fld.fold_struct_field(f)))
702-
}
703-
VariantData_::Tuple(fields) => {
704-
VariantData_::Tuple(fields.move_map(|f| fld.fold_struct_field(f)))
705-
}
706-
VariantData_::Unit => VariantData_::Unit
707-
},
708-
id: fld.new_id(id),
697+
struct_def.map(|vdata| {
698+
match vdata {
699+
VariantData::Struct(fields, id) => {
700+
VariantData::Struct(fields.move_map(|f| fld.fold_struct_field(f)), fld.new_id(id))
701+
}
702+
VariantData::Tuple(fields, id) => {
703+
VariantData::Tuple(fields.move_map(|f| fld.fold_struct_field(f)), fld.new_id(id))
704+
}
705+
VariantData::Unit(id) => VariantData::Unit(fld.new_id(id))
709706
}
710707
})
711708
}

src/librustc_front/hir.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,18 +1162,10 @@ impl StructFieldKind {
11621162
}
11631163

11641164
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1165-
pub enum VariantData_ {
1166-
Struct(Vec<StructField>),
1167-
Tuple(Vec<StructField>),
1168-
Unit,
1169-
}
1170-
1171-
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
1172-
pub struct VariantData {
1173-
pub data_: VariantData_,
1174-
/// ID of the constructor. This is only used for tuple- or enum-like
1175-
/// structs.
1176-
pub id: NodeId,
1165+
pub enum VariantData {
1166+
Struct(Vec<StructField>, NodeId),
1167+
Tuple(Vec<StructField>, NodeId),
1168+
Unit(NodeId),
11771169
}
11781170

11791171
pub type FieldIter<'a> = iter::FlatMap<option::IntoIter<&'a Vec<StructField>>,
@@ -1183,19 +1175,24 @@ pub type FieldIter<'a> = iter::FlatMap<option::IntoIter<&'a Vec<StructField>>,
11831175
impl VariantData {
11841176
pub fn fields(&self) -> FieldIter {
11851177
fn vec_iter<T>(v: &Vec<T>) -> slice::Iter<T> { v.iter() }
1186-
match self.data_ {
1187-
VariantData_::Struct(ref fields) | VariantData_::Tuple(ref fields) => Some(fields),
1178+
match *self {
1179+
VariantData::Struct(ref fields, _) | VariantData::Tuple(ref fields, _) => Some(fields),
11881180
_ => None,
11891181
}.into_iter().flat_map(vec_iter)
11901182
}
1183+
pub fn id(&self) -> NodeId {
1184+
match *self {
1185+
VariantData::Struct(_, id) | VariantData::Tuple(_, id) | VariantData::Unit(id) => id
1186+
}
1187+
}
11911188
pub fn is_struct(&self) -> bool {
1192-
if let VariantData_::Struct(..) = self.data_ { true } else { false }
1189+
if let VariantData::Struct(..) = *self { true } else { false }
11931190
}
11941191
pub fn is_tuple(&self) -> bool {
1195-
if let VariantData_::Tuple(..) = self.data_ { true } else { false }
1192+
if let VariantData::Tuple(..) = *self { true } else { false }
11961193
}
11971194
pub fn is_unit(&self) -> bool {
1198-
if let VariantData_::Unit = self.data_ { true } else { false }
1195+
if let VariantData::Unit(..) = *self { true } else { false }
11991196
}
12001197
}
12011198

src/librustc_front/lowering.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -499,19 +499,16 @@ pub fn lower_where_predicate(_lctx: &LoweringContext,
499499
}
500500

501501
pub fn lower_struct_def(_lctx: &LoweringContext, sd: &VariantData) -> P<hir::VariantData> {
502-
P(hir::VariantData {
503-
id: sd.id,
504-
data_: match sd.data_ {
505-
VariantData_::Struct(ref fields) => {
506-
hir::VariantData_::Struct(fields.iter()
507-
.map(|f| lower_struct_field(_lctx, f)).collect())
508-
}
509-
VariantData_::Tuple(ref fields) => {
510-
hir::VariantData_::Tuple(fields.iter()
511-
.map(|f| lower_struct_field(_lctx, f)).collect())
512-
}
513-
VariantData_::Unit => hir::VariantData_::Unit
502+
P(match *sd {
503+
VariantData::Struct(ref fields, id) => {
504+
hir::VariantData::Struct(fields.iter()
505+
.map(|f| lower_struct_field(_lctx, f)).collect(), id)
506+
}
507+
VariantData::Tuple(ref fields, id) => {
508+
hir::VariantData::Tuple(fields.iter()
509+
.map(|f| lower_struct_field(_lctx, f)).collect(), id)
514510
}
511+
VariantData::Unit(id) => hir::VariantData::Unit(id)
515512
})
516513
}
517514

src/librustc_front/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl<'a, 'v, O: ast_util::IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O>
287287
_: &hir::Generics,
288288
_: NodeId,
289289
_: Span) {
290-
self.operation.visit_id(struct_def.id);
290+
self.operation.visit_id(struct_def.id());
291291
visit::walk_struct_def(self, struct_def);
292292
}
293293

src/librustc_lint/builtin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,8 @@ impl LateLintPass for MissingDoc {
527527
}
528528

529529
fn check_variant(&mut self, cx: &LateContext, v: &hir::Variant, _: &hir::Generics) {
530-
self.check_missing_docs_attrs(cx, Some(v.node.data.id), &v.node.attrs, v.span, "a variant");
530+
self.check_missing_docs_attrs(cx, Some(v.node.data.id()),
531+
&v.node.attrs, v.span, "a variant");
531532
assert!(!self.in_variant);
532533
self.in_variant = true;
533534
}

src/librustc_privacy/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'v> Visitor<'v> for ParentVisitor {
8282
// The parent is considered the enclosing enum because the
8383
// enum will dictate the privacy visibility of this variant
8484
// instead.
85-
self.parents.insert(variant.node.data.id, item.id);
85+
self.parents.insert(variant.node.data.id(), item.id);
8686
}
8787
}
8888

@@ -133,7 +133,7 @@ impl<'v> Visitor<'v> for ParentVisitor {
133133
// Struct constructors are parented to their struct definitions because
134134
// they essentially are the struct definitions.
135135
if !s.is_struct() {
136-
self.parents.insert(s.id, item_id);
136+
self.parents.insert(s.id(), item_id);
137137
}
138138

139139
// While we have the id of the struct definition, go ahead and parent
@@ -233,8 +233,8 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
233233
// public all variants are public unless they're explicitly priv
234234
hir::ItemEnum(ref def, _) if public_first => {
235235
for variant in &def.variants {
236-
self.exported_items.insert(variant.node.data.id);
237-
self.public_items.insert(variant.node.data.id);
236+
self.exported_items.insert(variant.node.data.id());
237+
self.public_items.insert(variant.node.data.id());
238238
}
239239
}
240240

@@ -320,7 +320,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
320320
// Struct constructors are public if the struct is all public.
321321
hir::ItemStruct(ref def, _) if public_first => {
322322
if !def.is_struct() {
323-
self.exported_items.insert(def.id);
323+
self.exported_items.insert(def.id());
324324
}
325325
// fields can be public or private, so lets check
326326
for field in def.fields() {
@@ -1431,7 +1431,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
14311431
}
14321432

14331433
fn visit_variant(&mut self, v: &hir::Variant, g: &hir::Generics, item_id: ast::NodeId) {
1434-
if self.exported_items.contains(&v.node.data.id) {
1434+
if self.exported_items.contains(&v.node.data.id()) {
14351435
self.in_variant = true;
14361436
visit::walk_variant(self, v, g, item_id);
14371437
self.in_variant = false;

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
495495
let (forbid, ctor_id) = if struct_def.is_struct() {
496496
(ForbidDuplicateTypesAndModules, None)
497497
} else {
498-
(ForbidDuplicateTypesAndValues, Some(struct_def.id))
498+
(ForbidDuplicateTypesAndValues, Some(struct_def.id()))
499499
};
500500

501501
let name_bindings = self.add_child(name, parent, forbid, sp);
@@ -590,7 +590,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
590590
let name = variant.node.name;
591591
let is_exported = if variant.node.data.is_struct() {
592592
// Not adding fields for variants as they are not accessed with a self receiver
593-
let variant_def_id = self.ast_map.local_def_id(variant.node.data.id);
593+
let variant_def_id = self.ast_map.local_def_id(variant.node.data.id());
594594
self.structs.insert(variant_def_id, Vec::new());
595595
true
596596
} else {
@@ -603,10 +603,12 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
603603
// variants are always treated as importable to allow them to be glob
604604
// used
605605
child.define_value(DefVariant(item_id,
606-
self.ast_map.local_def_id(variant.node.data.id), is_exported),
606+
self.ast_map.local_def_id(variant.node.data.id()),
607+
is_exported),
607608
variant.span, DefModifiers::PUBLIC | DefModifiers::IMPORTABLE);
608609
child.define_type(DefVariant(item_id,
609-
self.ast_map.local_def_id(variant.node.data.id), is_exported),
610+
self.ast_map.local_def_id(variant.node.data.id()),
611+
is_exported),
610612
variant.span, DefModifiers::PUBLIC | DefModifiers::IMPORTABLE);
611613
}
612614

0 commit comments

Comments
 (0)