]> git.lizzy.rs Git - rust.git/commitdiff
use the struct's ctor-id as its variant def-id
authorAriel Ben-Yehuda <arielb1@mail.tau.ac.il>
Wed, 7 Oct 2015 17:30:48 +0000 (20:30 +0300)
committerAriel Ben-Yehuda <arielb1@mail.tau.ac.il>
Wed, 7 Oct 2015 17:31:23 +0000 (20:31 +0300)
this makes the code cleaner, and is a complement to the cleanup on the
HIR side.

src/librustc/metadata/decoder.rs
src/librustc/middle/astencode.rs
src/librustc/middle/ty/mod.rs
src/librustc_typeck/collect.rs

index f51fb068219c917e3f294891f11f1bb1949c5cd0..0780252fc887b8b3c83b1bcbc8a221fd524dad20 100644 (file)
@@ -388,7 +388,6 @@ fn get_enum_variants<'tcx>(intr: &IdentInterner,
                 did: did,
                 name: item_name(intr, item),
                 fields: get_variant_fields(intr, cdata, item, tcx),
-                ctor_id: did,
                 disr_val: disr
             }
         }).collect()
@@ -417,13 +416,11 @@ fn get_struct_variant<'tcx>(intr: &IdentInterner,
                                 cdata: Cmd,
                                 doc: rbml::Doc,
                                 did: DefId,
-                                ctor_id: DefId,
                                 tcx: &ty::ctxt<'tcx>) -> ty::VariantDefData<'tcx, 'tcx> {
         ty::VariantDefData {
             did: did,
             name: item_name(intr, doc),
             fields: get_variant_fields(intr, cdata, doc, tcx),
-            ctor_id: ctor_id,
             disr_val: 0
         }
     }
@@ -440,7 +437,7 @@ fn get_struct_variant<'tcx>(intr: &IdentInterner,
                 reader::maybe_get_doc(doc, tag_items_data_item_struct_ctor).
                 map_or(did, |ctor_doc| translated_def_id(cdata, ctor_doc));
             (ty::AdtKind::Struct,
-             vec![get_struct_variant(intr, cdata, doc, did, ctor_did, tcx)])
+             vec![get_struct_variant(intr, cdata, doc, ctor_did, tcx)])
         }
         _ => tcx.sess.bug(
             &format!("get_adt_def called on a non-ADT {:?} - {:?}",
index 6c23307c67776570279eecaf7d967e81a161f34b..160be3fa7ff458587b2c68335d7295b772576f07 100644 (file)
@@ -1312,14 +1312,17 @@ fn copy_item_type(dcx: &DecodeContext,
                 for (i_variant, orig_variant) in
                     def.variants.iter().zip(orig_def.variants.iter())
                 {
+                    debug!("astencode: copying variant {:?} => {:?}",
+                           orig_variant.did, i_variant.node.id);
                     copy_item_type(dcx, i_variant.node.id, orig_variant.did);
                 }
             }
             hir::ItemStruct(ref def, _) => {
                 if let Some(ctor_id) = def.ctor_id {
                     let ctor_did = dcx.tcx.lookup_adt_def(orig_did)
-                        .struct_variant().ctor_id;
-                    debug!("copying ctor {:?}", ctor_did);
+                        .struct_variant().did;
+                    debug!("astencode: copying ctor {:?} => {:?}", ctor_did,
+                           ctor_id);
                     copy_item_type(dcx, ctor_id, ctor_did);
                 }
             }
index fddfb7b583eb364559b8362747f93b0b0c89f0e8..4ffb519900356ab0687aeb73907c9407c9fb8afd 100644 (file)
@@ -1470,13 +1470,12 @@ pub fn for_each_relevant_impl<F: FnMut(DefId)>(&self,
 pub type FieldDefMaster<'tcx> = &'tcx FieldDefData<'tcx, 'tcx>;
 
 pub struct VariantDefData<'tcx, 'container: 'tcx> {
+    /// The variant's DefId. If this is a tuple-like struct,
+    /// this is the DefId of the struct's ctor.
     pub did: DefId,
     pub name: Name, // struct's name if this is a struct
     pub disr_val: Disr,
     pub fields: Vec<FieldDefData<'tcx, 'container>>,
-    /// The DefId of the variant's ctor (unless the variant is a
-    /// tuple-like struct variant, this is just the variant's def-id).
-    pub ctor_id: DefId
 }
 
 pub struct FieldDefData<'tcx, 'container: 'tcx> {
index 25a61414ab51429e3ad310b1cb717c54004bb6cf..a875deeb395efac7094ddc59b1315dbd02377252 100644 (file)
@@ -1102,8 +1102,7 @@ fn convert_struct_variant<'tcx>(tcx: &ty::ctxt<'tcx>,
                                 did: DefId,
                                 name: ast::Name,
                                 disr_val: ty::Disr,
-                                def: &hir::StructDef,
-                                ctor_id: DefId) -> ty::VariantDefData<'tcx, 'tcx> {
+                                def: &hir::StructDef) -> 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);
@@ -1130,8 +1129,7 @@ fn convert_struct_variant<'tcx>(tcx: &ty::ctxt<'tcx>,
         did: did,
         name: name,
         disr_val: disr_val,
-        fields: fields,
-        ctor_id: ctor_id
+        fields: fields
     }
 }
 
@@ -1147,7 +1145,7 @@ fn convert_struct_def<'tcx>(tcx: &ty::ctxt<'tcx>,
     tcx.intern_adt_def(
         did,
         ty::AdtKind::Struct,
-        vec![convert_struct_variant(tcx, did, it.name, 0, def, ctor_id)]
+        vec![convert_struct_variant(tcx, ctor_id, it.name, 0, def)]
     )
 }
 
@@ -1237,12 +1235,11 @@ fn convert_enum_variant<'tcx>(tcx: &ty::ctxt<'tcx>,
                             special_idents::unnamed_field.name,
                             hir::Visibility::Public
                         )
-                    }).collect(),
-                    ctor_id: did
+                    }).collect()
                 }
             }
             hir::StructVariantKind(ref def) => {
-                convert_struct_variant(tcx, did, name, disr, &def, did)
+                convert_struct_variant(tcx, did, name, disr, &def)
             }
         }
     }