]> git.lizzy.rs Git - rust.git/commitdiff
remove ty::{VariantInfo, FieldTy}
authorAriel Ben-Yehuda <arielb1@mail.tau.ac.il>
Wed, 5 Aug 2015 22:55:13 +0000 (01:55 +0300)
committerAriel Ben-Yehuda <ariel.byd@gmail.com>
Thu, 6 Aug 2015 14:02:23 +0000 (17:02 +0300)
src/librustc/metadata/csearch.rs
src/librustc/metadata/decoder.rs
src/librustc/middle/ty.rs
src/librustc/middle/ty_fold.rs
src/librustc_resolve/build_reduced_graph.rs

index f97ffebaebb19586c5bb182acea50a07d0728da6..f0607010bf3f07d29d29907886e31bd0fb4e8c06 100644 (file)
@@ -113,13 +113,6 @@ pub fn maybe_get_item_ast<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId,
     decoder::maybe_get_item_ast(&*cdata, tcx, def.node, decode_inlined_item)
 }
 
-pub fn get_enum_variants<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId)
-                               -> Vec<Rc<ty::VariantInfo<'tcx>>> {
-    let cstore = &tcx.sess.cstore;
-    let cdata = cstore.get_crate_data(def.krate);
-    decoder::get_enum_variants(cstore.intr.clone(), &*cdata, def.node, tcx)
-}
-
 /// Returns information about the given implementation.
 pub fn get_impl_items(cstore: &cstore::CStore, impl_def_id: ast::DefId)
                       -> Vec<ty::ImplOrTraitItemId> {
@@ -195,11 +188,9 @@ pub fn get_item_attrs(cstore: &cstore::CStore,
     decoder::get_item_attrs(&*cdata, def_id.node)
 }
 
-pub fn get_struct_fields(cstore: &cstore::CStore,
-                         def: ast::DefId)
-                      -> Vec<ty::FieldTy> {
+pub fn get_struct_field_names(cstore: &cstore::CStore, def: ast::DefId) -> Vec<ast::Name> {
     let cdata = cstore.get_crate_data(def.krate);
-    decoder::get_struct_fields(cstore.intr.clone(), &*cdata, def.node)
+    decoder::get_struct_field_names(&cstore.intr, &*cdata, def.node)
 }
 
 pub fn get_struct_field_attrs(cstore: &cstore::CStore, def: ast::DefId) -> HashMap<ast::NodeId,
index 7a899218512f7d9e0da7fd7811cbb86819a3b960..38f90e682be06654e38d27397fb60baf72ce71a7 100644 (file)
@@ -794,55 +794,6 @@ pub fn maybe_get_item_ast<'tcx>(cdata: Cmd, tcx: &ty::ctxt<'tcx>, id: ast::NodeI
     }
 }
 
-pub fn get_enum_variants<'tcx>(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
-                               tcx: &ty::ctxt<'tcx>) -> Vec<Rc<ty::VariantInfo<'tcx>>> {
-    let data = cdata.data();
-    let items = reader::get_doc(rbml::Doc::new(data), tag_items);
-    let item = find_item(id, items);
-    let mut disr_val = 0;
-    reader::tagged_docs(item, tag_items_data_item_variant).map(|p| {
-        let did = translated_def_id(cdata, p);
-        let item = find_item(did.node, items);
-        let ctor_ty = item_type(ast::DefId { krate: cdata.cnum, node: id},
-                                item, tcx, cdata);
-        let name = item_name(&*intr, item);
-        let (ctor_ty, arg_tys, arg_names) = match ctor_ty.sty {
-            ty::TyBareFn(_, ref f) =>
-                (Some(ctor_ty), f.sig.0.inputs.clone(), None),
-            _ => { // Nullary or struct enum variant.
-                let mut arg_names = Vec::new();
-                let arg_tys = get_struct_fields(intr.clone(), cdata, did.node)
-                    .iter()
-                    .map(|field_ty| {
-                        arg_names.push(field_ty.name);
-                        get_type(cdata, field_ty.id.node, tcx).ty
-                    })
-                    .collect();
-                let arg_names = if arg_names.is_empty() { None } else { Some(arg_names) };
-
-                (None, arg_tys, arg_names)
-            }
-        };
-        match variant_disr_val(item) {
-            Some(val) => { disr_val = val; }
-            _         => { /* empty */ }
-        }
-        let old_disr_val = disr_val;
-        disr_val = disr_val.wrapping_add(1);
-        Rc::new(ty::VariantInfo {
-            args: arg_tys,
-            arg_names: arg_names,
-            ctor_ty: ctor_ty,
-            name: name,
-            // I'm not even sure if we encode visibility
-            // for variants -- TEST -- tjc
-            id: did,
-            disr_val: old_disr_val,
-            vis: ast::Inherited
-        })
-    }).collect()
-}
-
 fn get_explicit_self(item: rbml::Doc) -> ty::ExplicitSelfCategory {
     fn get_mutability(ch: u8) -> ast::Mutability {
         match ch as char {
@@ -1136,37 +1087,14 @@ fn struct_field_family_to_visibility(family: Family) -> ast::Visibility {
     }
 }
 
-pub fn get_struct_fields(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId)
-    -> Vec<ty::FieldTy> {
+pub fn get_struct_field_names(intr: &IdentInterner, cdata: Cmd, id: ast::NodeId)
+    -> Vec<ast::Name> {
     let data = cdata.data();
     let item = lookup_item(id, data);
-    reader::tagged_docs(item, tag_item_field).filter_map(|an_item| {
-        let f = item_family(an_item);
-        if f == PublicField || f == InheritedField {
-            let name = item_name(&*intr, an_item);
-            let did = item_def_id(an_item, cdata);
-            let tagdoc = reader::get_doc(an_item, tag_item_field_origin);
-            let origin_id =  translated_def_id(cdata, tagdoc);
-            Some(ty::FieldTy {
-                name: name,
-                id: did,
-                vis: struct_field_family_to_visibility(f),
-                origin: origin_id,
-            })
-        } else {
-            None
-        }
-    }).chain(reader::tagged_docs(item, tag_item_unnamed_field).map(|an_item| {
-        let did = item_def_id(an_item, cdata);
-        let tagdoc = reader::get_doc(an_item, tag_item_field_origin);
-        let f = item_family(an_item);
-        let origin_id =  translated_def_id(cdata, tagdoc);
-        ty::FieldTy {
-            name: special_idents::unnamed_field.name,
-            id: did,
-            vis: struct_field_family_to_visibility(f),
-            origin: origin_id,
-        }
+    reader::tagged_docs(item, tag_item_field).map(|an_item| {
+        item_name(intr, an_item)
+    }).chain(reader::tagged_docs(item, tag_item_unnamed_field).map(|_| {
+        special_idents::unnamed_field.name
     })).collect()
 }
 
index 9d339aef250e1bd739cd56adde2bb7124d4ff99c..733fa0e71b4eefa660435f81b4d601dcc1559430 100644 (file)
@@ -87,8 +87,7 @@
 use rustc_data_structures::ivar;
 use syntax::abi;
 use syntax::ast::{CrateNum, DefId, ItemImpl, ItemTrait, LOCAL_CRATE};
-use syntax::ast::{MutImmutable, MutMutable, Name, NamedField, NodeId};
-use syntax::ast::{StructField, UnnamedField, Visibility};
+use syntax::ast::{MutImmutable, MutMutable, Name, NodeId, Visibility};
 use syntax::ast_util::{self, is_local, local_def};
 use syntax::attr::{self, AttrMetaMethods, SignedInt, UnsignedInt};
 use syntax::codemap::Span;
@@ -112,83 +111,6 @@ pub struct CrateAnalysis {
     pub glob_map: Option<GlobMap>,
 }
 
-#[derive(Copy, Clone, PartialEq, Eq, Hash)]
-pub struct Field<'tcx> {
-    pub name: ast::Name,
-    pub mt: TypeAndMut<'tcx>
-}
-
-// Enum information
-#[derive(Clone)]
-pub struct VariantInfo<'tcx> {
-    pub args: Vec<Ty<'tcx>>,
-    pub arg_names: Option<Vec<ast::Name>>,
-    pub ctor_ty: Option<Ty<'tcx>>,
-    pub name: ast::Name,
-    pub id: ast::DefId,
-    pub disr_val: Disr,
-    pub vis: Visibility
-}
-
-impl<'tcx> VariantInfo<'tcx> {
-
-    /// Creates a new VariantInfo from the corresponding ast representation.
-    ///
-    /// Does not do any caching of the value in the type context.
-    pub fn from_ast_variant(cx: &ctxt<'tcx>,
-                            ast_variant: &ast::Variant,
-                            discriminant: Disr) -> VariantInfo<'tcx> {
-        let ctor_ty = cx.node_id_to_type(ast_variant.node.id);
-
-        match ast_variant.node.kind {
-            ast::TupleVariantKind(ref args) => {
-                let arg_tys = if !args.is_empty() {
-                    // the regions in the argument types come from the
-                    // enum def'n, and hence will all be early bound
-                    cx.no_late_bound_regions(&ctor_ty.fn_args()).unwrap()
-                } else {
-                    Vec::new()
-                };
-
-                return VariantInfo {
-                    args: arg_tys,
-                    arg_names: None,
-                    ctor_ty: Some(ctor_ty),
-                    name: ast_variant.node.name.name,
-                    id: ast_util::local_def(ast_variant.node.id),
-                    disr_val: discriminant,
-                    vis: ast_variant.node.vis
-                };
-            },
-            ast::StructVariantKind(ref struct_def) => {
-                let fields: &[StructField] = &struct_def.fields;
-
-                assert!(!fields.is_empty());
-
-                let arg_tys = struct_def.fields.iter()
-                    .map(|field| cx.node_id_to_type(field.node.id)).collect();
-                let arg_names = fields.iter().map(|field| {
-                    match field.node.kind {
-                        NamedField(ident, _) => ident.name,
-                        UnnamedField(..) => cx.sess.bug(
-                            "enum_variants: all fields in struct must have a name")
-                    }
-                }).collect();
-
-                return VariantInfo {
-                    args: arg_tys,
-                    arg_names: Some(arg_names),
-                    ctor_ty: None,
-                    name: ast_variant.node.name.name,
-                    id: ast_util::local_def(ast_variant.node.id),
-                    disr_val: discriminant,
-                    vis: ast_variant.node.vis
-                };
-            }
-        }
-    }
-}
-
 #[derive(Copy, Clone)]
 pub enum DtorKind {
     NoDtor,
@@ -495,14 +417,6 @@ pub struct TypeAndMut<'tcx> {
     pub mutbl: ast::Mutability,
 }
 
-#[derive(Clone, Copy, Debug)]
-pub struct FieldTy {
-    pub name: Name,
-    pub id: DefId,
-    pub vis: ast::Visibility,
-    pub origin: ast::DefId,  // The DefId of the struct in which the field is declared.
-}
-
 #[derive(Clone, PartialEq, RustcDecodable, RustcEncodable)]
 pub struct ItemVariances {
     pub types: VecPerParamSpace<Variance>,
@@ -5667,18 +5581,6 @@ pub fn expr_is_lval(&self, expr: &ast::Expr) -> bool {
         }
     }
 
-    pub fn field_idx_strict(&self, name: ast::Name, fields: &[Field<'tcx>])
-                            -> usize {
-        let mut i = 0;
-        for f in fields { if f.name == name { return i; } i += 1; }
-        self.sess.bug(&format!(
-            "no field named `{}` found in the list of fields `{:?}`",
-            name,
-            fields.iter()
-                  .map(|f| f.name.to_string())
-                  .collect::<Vec<String>>()));
-    }
-
     pub fn note_and_explain_type_err(&self, err: &TypeError<'tcx>, sp: Span) {
         use self::TypeError::*;
 
@@ -7341,12 +7243,6 @@ fn has_type_flags(&self, flags: TypeFlags) -> bool {
     }
 }
 
-impl<'tcx> HasTypeFlags for Field<'tcx> {
-    fn has_type_flags(&self, flags: TypeFlags) -> bool {
-        self.mt.ty.has_type_flags(flags)
-    }
-}
-
 impl<'tcx> HasTypeFlags for BareFnTy<'tcx> {
     fn has_type_flags(&self, flags: TypeFlags) -> bool {
         self.sig.has_type_flags(flags)
@@ -7377,12 +7273,6 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
-impl<'tcx> fmt::Debug for Field<'tcx> {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f, "field({},{})", self.name, self.mt)
-    }
-}
-
 impl<'a, 'tcx> fmt::Debug for ParameterEnvironment<'a, 'tcx> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         write!(f, "ParameterEnvironment(\
index 0c694926ba4b5a829e2c775fadaac7be73924e8e..cc1efeaea080f39e1e633bb4bad2e684b56b1381 100644 (file)
@@ -275,15 +275,6 @@ fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::TraitRef<'tcx> {
     }
 }
 
-impl<'tcx> TypeFoldable<'tcx> for ty::Field<'tcx> {
-    fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::Field<'tcx> {
-        ty::Field {
-            name: self.name,
-            mt: self.mt.fold_with(folder),
-        }
-    }
-}
-
 impl<'tcx> TypeFoldable<'tcx> for ty::Region {
     fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::Region {
         folder.fold_region(*self)
index 656d6a36614706d3d2eb4375b21be2cb6723398d..190e217aac15dc2be9269d098748325be7f64886 100644 (file)
@@ -791,9 +791,7 @@ fn handle_external_def(&mut self,
                     crate) building type and value for {}",
                    final_ident);
             child_name_bindings.define_type(def, DUMMY_SP, modifiers);
-            let fields = csearch::get_struct_fields(&self.session.cstore, def_id).iter().map(|f| {
-                f.name
-            }).collect::<Vec<_>>();
+            let fields = csearch::get_struct_field_names(&self.session.cstore, def_id);
 
             if fields.is_empty() {
                 child_name_bindings.define_value(def, DUMMY_SP, modifiers);