Skip to content

Commit 53f01e4

Browse files
author
Ariel Ben-Yehuda
committed
remove ty::{VariantInfo, FieldTy}
1 parent aea6614 commit 53f01e4

File tree

5 files changed

+10
-212
lines changed

5 files changed

+10
-212
lines changed

src/librustc/metadata/csearch.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,6 @@ pub fn maybe_get_item_ast<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId,
113113
decoder::maybe_get_item_ast(&*cdata, tcx, def.node, decode_inlined_item)
114114
}
115115

116-
pub fn get_enum_variants<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId)
117-
-> Vec<Rc<ty::VariantInfo<'tcx>>> {
118-
let cstore = &tcx.sess.cstore;
119-
let cdata = cstore.get_crate_data(def.krate);
120-
decoder::get_enum_variants(cstore.intr.clone(), &*cdata, def.node, tcx)
121-
}
122-
123116
/// Returns information about the given implementation.
124117
pub fn get_impl_items(cstore: &cstore::CStore, impl_def_id: ast::DefId)
125118
-> Vec<ty::ImplOrTraitItemId> {
@@ -195,11 +188,9 @@ pub fn get_item_attrs(cstore: &cstore::CStore,
195188
decoder::get_item_attrs(&*cdata, def_id.node)
196189
}
197190

198-
pub fn get_struct_fields(cstore: &cstore::CStore,
199-
def: ast::DefId)
200-
-> Vec<ty::FieldTy> {
191+
pub fn get_struct_field_names(cstore: &cstore::CStore, def: ast::DefId) -> Vec<ast::Name> {
201192
let cdata = cstore.get_crate_data(def.krate);
202-
decoder::get_struct_fields(cstore.intr.clone(), &*cdata, def.node)
193+
decoder::get_struct_field_names(&cstore.intr, &*cdata, def.node)
203194
}
204195

205196
pub fn get_struct_field_attrs(cstore: &cstore::CStore, def: ast::DefId) -> HashMap<ast::NodeId,

src/librustc/metadata/decoder.rs

+6-78
Original file line numberDiff line numberDiff line change
@@ -794,55 +794,6 @@ pub fn maybe_get_item_ast<'tcx>(cdata: Cmd, tcx: &ty::ctxt<'tcx>, id: ast::NodeI
794794
}
795795
}
796796

797-
pub fn get_enum_variants<'tcx>(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
798-
tcx: &ty::ctxt<'tcx>) -> Vec<Rc<ty::VariantInfo<'tcx>>> {
799-
let data = cdata.data();
800-
let items = reader::get_doc(rbml::Doc::new(data), tag_items);
801-
let item = find_item(id, items);
802-
let mut disr_val = 0;
803-
reader::tagged_docs(item, tag_items_data_item_variant).map(|p| {
804-
let did = translated_def_id(cdata, p);
805-
let item = find_item(did.node, items);
806-
let ctor_ty = item_type(ast::DefId { krate: cdata.cnum, node: id},
807-
item, tcx, cdata);
808-
let name = item_name(&*intr, item);
809-
let (ctor_ty, arg_tys, arg_names) = match ctor_ty.sty {
810-
ty::TyBareFn(_, ref f) =>
811-
(Some(ctor_ty), f.sig.0.inputs.clone(), None),
812-
_ => { // Nullary or struct enum variant.
813-
let mut arg_names = Vec::new();
814-
let arg_tys = get_struct_fields(intr.clone(), cdata, did.node)
815-
.iter()
816-
.map(|field_ty| {
817-
arg_names.push(field_ty.name);
818-
get_type(cdata, field_ty.id.node, tcx).ty
819-
})
820-
.collect();
821-
let arg_names = if arg_names.is_empty() { None } else { Some(arg_names) };
822-
823-
(None, arg_tys, arg_names)
824-
}
825-
};
826-
match variant_disr_val(item) {
827-
Some(val) => { disr_val = val; }
828-
_ => { /* empty */ }
829-
}
830-
let old_disr_val = disr_val;
831-
disr_val = disr_val.wrapping_add(1);
832-
Rc::new(ty::VariantInfo {
833-
args: arg_tys,
834-
arg_names: arg_names,
835-
ctor_ty: ctor_ty,
836-
name: name,
837-
// I'm not even sure if we encode visibility
838-
// for variants -- TEST -- tjc
839-
id: did,
840-
disr_val: old_disr_val,
841-
vis: ast::Inherited
842-
})
843-
}).collect()
844-
}
845-
846797
fn get_explicit_self(item: rbml::Doc) -> ty::ExplicitSelfCategory {
847798
fn get_mutability(ch: u8) -> ast::Mutability {
848799
match ch as char {
@@ -1136,37 +1087,14 @@ fn struct_field_family_to_visibility(family: Family) -> ast::Visibility {
11361087
}
11371088
}
11381089

1139-
pub fn get_struct_fields(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId)
1140-
-> Vec<ty::FieldTy> {
1090+
pub fn get_struct_field_names(intr: &IdentInterner, cdata: Cmd, id: ast::NodeId)
1091+
-> Vec<ast::Name> {
11411092
let data = cdata.data();
11421093
let item = lookup_item(id, data);
1143-
reader::tagged_docs(item, tag_item_field).filter_map(|an_item| {
1144-
let f = item_family(an_item);
1145-
if f == PublicField || f == InheritedField {
1146-
let name = item_name(&*intr, an_item);
1147-
let did = item_def_id(an_item, cdata);
1148-
let tagdoc = reader::get_doc(an_item, tag_item_field_origin);
1149-
let origin_id = translated_def_id(cdata, tagdoc);
1150-
Some(ty::FieldTy {
1151-
name: name,
1152-
id: did,
1153-
vis: struct_field_family_to_visibility(f),
1154-
origin: origin_id,
1155-
})
1156-
} else {
1157-
None
1158-
}
1159-
}).chain(reader::tagged_docs(item, tag_item_unnamed_field).map(|an_item| {
1160-
let did = item_def_id(an_item, cdata);
1161-
let tagdoc = reader::get_doc(an_item, tag_item_field_origin);
1162-
let f = item_family(an_item);
1163-
let origin_id = translated_def_id(cdata, tagdoc);
1164-
ty::FieldTy {
1165-
name: special_idents::unnamed_field.name,
1166-
id: did,
1167-
vis: struct_field_family_to_visibility(f),
1168-
origin: origin_id,
1169-
}
1094+
reader::tagged_docs(item, tag_item_field).map(|an_item| {
1095+
item_name(intr, an_item)
1096+
}).chain(reader::tagged_docs(item, tag_item_unnamed_field).map(|_| {
1097+
special_idents::unnamed_field.name
11701098
})).collect()
11711099
}
11721100

src/librustc/middle/ty.rs

+1-111
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ use std::collections::{HashMap, HashSet};
8787
use rustc_data_structures::ivar;
8888
use syntax::abi;
8989
use syntax::ast::{CrateNum, DefId, ItemImpl, ItemTrait, LOCAL_CRATE};
90-
use syntax::ast::{MutImmutable, MutMutable, Name, NamedField, NodeId};
91-
use syntax::ast::{StructField, UnnamedField, Visibility};
90+
use syntax::ast::{MutImmutable, MutMutable, Name, NodeId, Visibility};
9291
use syntax::ast_util::{self, is_local, local_def};
9392
use syntax::attr::{self, AttrMetaMethods, SignedInt, UnsignedInt};
9493
use syntax::codemap::Span;
@@ -112,83 +111,6 @@ pub struct CrateAnalysis {
112111
pub glob_map: Option<GlobMap>,
113112
}
114113

115-
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
116-
pub struct Field<'tcx> {
117-
pub name: ast::Name,
118-
pub mt: TypeAndMut<'tcx>
119-
}
120-
121-
// Enum information
122-
#[derive(Clone)]
123-
pub struct VariantInfo<'tcx> {
124-
pub args: Vec<Ty<'tcx>>,
125-
pub arg_names: Option<Vec<ast::Name>>,
126-
pub ctor_ty: Option<Ty<'tcx>>,
127-
pub name: ast::Name,
128-
pub id: ast::DefId,
129-
pub disr_val: Disr,
130-
pub vis: Visibility
131-
}
132-
133-
impl<'tcx> VariantInfo<'tcx> {
134-
135-
/// Creates a new VariantInfo from the corresponding ast representation.
136-
///
137-
/// Does not do any caching of the value in the type context.
138-
pub fn from_ast_variant(cx: &ctxt<'tcx>,
139-
ast_variant: &ast::Variant,
140-
discriminant: Disr) -> VariantInfo<'tcx> {
141-
let ctor_ty = cx.node_id_to_type(ast_variant.node.id);
142-
143-
match ast_variant.node.kind {
144-
ast::TupleVariantKind(ref args) => {
145-
let arg_tys = if !args.is_empty() {
146-
// the regions in the argument types come from the
147-
// enum def'n, and hence will all be early bound
148-
cx.no_late_bound_regions(&ctor_ty.fn_args()).unwrap()
149-
} else {
150-
Vec::new()
151-
};
152-
153-
return VariantInfo {
154-
args: arg_tys,
155-
arg_names: None,
156-
ctor_ty: Some(ctor_ty),
157-
name: ast_variant.node.name.name,
158-
id: ast_util::local_def(ast_variant.node.id),
159-
disr_val: discriminant,
160-
vis: ast_variant.node.vis
161-
};
162-
},
163-
ast::StructVariantKind(ref struct_def) => {
164-
let fields: &[StructField] = &struct_def.fields;
165-
166-
assert!(!fields.is_empty());
167-
168-
let arg_tys = struct_def.fields.iter()
169-
.map(|field| cx.node_id_to_type(field.node.id)).collect();
170-
let arg_names = fields.iter().map(|field| {
171-
match field.node.kind {
172-
NamedField(ident, _) => ident.name,
173-
UnnamedField(..) => cx.sess.bug(
174-
"enum_variants: all fields in struct must have a name")
175-
}
176-
}).collect();
177-
178-
return VariantInfo {
179-
args: arg_tys,
180-
arg_names: Some(arg_names),
181-
ctor_ty: None,
182-
name: ast_variant.node.name.name,
183-
id: ast_util::local_def(ast_variant.node.id),
184-
disr_val: discriminant,
185-
vis: ast_variant.node.vis
186-
};
187-
}
188-
}
189-
}
190-
}
191-
192114
#[derive(Copy, Clone)]
193115
pub enum DtorKind {
194116
NoDtor,
@@ -495,14 +417,6 @@ pub struct TypeAndMut<'tcx> {
495417
pub mutbl: ast::Mutability,
496418
}
497419

498-
#[derive(Clone, Copy, Debug)]
499-
pub struct FieldTy {
500-
pub name: Name,
501-
pub id: DefId,
502-
pub vis: ast::Visibility,
503-
pub origin: ast::DefId, // The DefId of the struct in which the field is declared.
504-
}
505-
506420
#[derive(Clone, PartialEq, RustcDecodable, RustcEncodable)]
507421
pub struct ItemVariances {
508422
pub types: VecPerParamSpace<Variance>,
@@ -5668,18 +5582,6 @@ impl<'tcx> ctxt<'tcx> {
56685582
}
56695583
}
56705584

5671-
pub fn field_idx_strict(&self, name: ast::Name, fields: &[Field<'tcx>])
5672-
-> usize {
5673-
let mut i = 0;
5674-
for f in fields { if f.name == name { return i; } i += 1; }
5675-
self.sess.bug(&format!(
5676-
"no field named `{}` found in the list of fields `{:?}`",
5677-
name,
5678-
fields.iter()
5679-
.map(|f| f.name.to_string())
5680-
.collect::<Vec<String>>()));
5681-
}
5682-
56835585
pub fn note_and_explain_type_err(&self, err: &TypeError<'tcx>, sp: Span) {
56845586
use self::TypeError::*;
56855587

@@ -7342,12 +7244,6 @@ impl<'tcx> HasTypeFlags for FnSig<'tcx> {
73427244
}
73437245
}
73447246

7345-
impl<'tcx> HasTypeFlags for Field<'tcx> {
7346-
fn has_type_flags(&self, flags: TypeFlags) -> bool {
7347-
self.mt.ty.has_type_flags(flags)
7348-
}
7349-
}
7350-
73517247
impl<'tcx> HasTypeFlags for BareFnTy<'tcx> {
73527248
fn has_type_flags(&self, flags: TypeFlags) -> bool {
73537249
self.sig.has_type_flags(flags)
@@ -7378,12 +7274,6 @@ impl<'tcx> fmt::Debug for ClosureUpvar<'tcx> {
73787274
}
73797275
}
73807276

7381-
impl<'tcx> fmt::Debug for Field<'tcx> {
7382-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
7383-
write!(f, "field({},{})", self.name, self.mt)
7384-
}
7385-
}
7386-
73877277
impl<'a, 'tcx> fmt::Debug for ParameterEnvironment<'a, 'tcx> {
73887278
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
73897279
write!(f, "ParameterEnvironment(\

src/librustc/middle/ty_fold.rs

-9
Original file line numberDiff line numberDiff line change
@@ -275,15 +275,6 @@ impl<'tcx> TypeFoldable<'tcx> for ty::TraitRef<'tcx> {
275275
}
276276
}
277277

278-
impl<'tcx> TypeFoldable<'tcx> for ty::Field<'tcx> {
279-
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::Field<'tcx> {
280-
ty::Field {
281-
name: self.name,
282-
mt: self.mt.fold_with(folder),
283-
}
284-
}
285-
}
286-
287278
impl<'tcx> TypeFoldable<'tcx> for ty::Region {
288279
fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::Region {
289280
folder.fold_region(*self)

src/librustc_resolve/build_reduced_graph.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -791,9 +791,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
791791
crate) building type and value for {}",
792792
final_ident);
793793
child_name_bindings.define_type(def, DUMMY_SP, modifiers);
794-
let fields = csearch::get_struct_fields(&self.session.cstore, def_id).iter().map(|f| {
795-
f.name
796-
}).collect::<Vec<_>>();
794+
let fields = csearch::get_struct_field_names(&self.session.cstore, def_id);
797795

798796
if fields.is_empty() {
799797
child_name_bindings.define_value(def, DUMMY_SP, modifiers);

0 commit comments

Comments
 (0)