}
}
-pub fn get_type<'tcx>(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt<'tcx>)
- -> ty::TypeScheme<'tcx> {
-
- let item = lookup_item(id, cdata.data());
+pub fn get_predicates<'tcx>(cdata: Cmd,
+ item_id: ast::NodeId,
+ tcx: &ty::ctxt<'tcx>)
+ -> ty::GenericPredicates<'tcx>
+{
+ let item_doc = lookup_item(item_id, cdata.data());
+ doc_predicates(item_doc, tcx, cdata, tag_item_generics)
+}
- let t = item_type(ast::DefId { krate: cdata.cnum, node: id }, item, tcx,
+pub fn get_type<'tcx>(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt<'tcx>)
+ -> ty::TypeScheme<'tcx>
+{
+ let item_doc = lookup_item(id, cdata.data());
+ let t = item_type(ast::DefId { krate: cdata.cnum, node: id }, item_doc, tcx,
cdata);
-
- let generics = doc_generics(item, tcx, cdata, tag_item_generics);
-
+ let generics = doc_generics(item_doc, tcx, cdata, tag_item_generics);
ty::TypeScheme {
generics: generics,
ty: t
match item_sort(method_doc) {
'r' | 'p' => {
- let generics = doc_generics(method_doc, tcx, cdata,
- tag_method_ty_generics);
+ let generics = doc_generics(method_doc, tcx, cdata, tag_method_ty_generics);
+ let predicates = doc_predicates(method_doc, tcx, cdata, tag_method_ty_generics);
let fty = doc_method_fty(method_doc, tcx, cdata);
let explicit_self = get_explicit_self(method_doc);
let provided_source = get_provided_source(method_doc, cdata);
ty::MethodTraitItem(Rc::new(ty::Method::new(name,
generics,
+ predicates,
fty,
explicit_self,
vis,
true
});
+ ty::Generics { types: types, regions: regions }
+}
+
+fn doc_predicates<'tcx>(base_doc: rbml::Doc,
+ tcx: &ty::ctxt<'tcx>,
+ cdata: Cmd,
+ tag: uint)
+ -> ty::GenericPredicates<'tcx>
+{
+ let doc = reader::get_doc(base_doc, tag);
+
let mut predicates = subst::VecPerParamSpace::empty();
reader::tagged_docs(doc, tag_predicate, |predicate_doc| {
let space_doc = reader::get_doc(predicate_doc, tag_predicate_space);
true
});
- ty::Generics { types: types, regions: regions, predicates: predicates }
+ ty::GenericPredicates { predicates: predicates }
}
pub fn is_associated_type(cdata: Cmd, id: ast::NodeId) -> bool {
rbml_w.end_tag();
}
+fn encode_bounds_and_type_for_item<'a, 'tcx>(rbml_w: &mut Encoder,
+ ecx: &EncodeContext<'a, 'tcx>,
+ id: ast::NodeId) {
+ encode_bounds_and_type(rbml_w,
+ ecx,
+ &ty::lookup_item_type(ecx.tcx, local_def(id)),
+ &ty::lookup_predicates(ecx.tcx, local_def(id)));
+}
+
fn encode_bounds_and_type<'a, 'tcx>(rbml_w: &mut Encoder,
ecx: &EncodeContext<'a, 'tcx>,
- pty: &ty::TypeScheme<'tcx>) {
- encode_generics(rbml_w, ecx, &pty.generics, tag_item_generics);
- encode_type(ecx, rbml_w, pty.ty);
+ scheme: &ty::TypeScheme<'tcx>,
+ predicates: &ty::GenericPredicates<'tcx>) {
+ encode_generics(rbml_w, ecx, &scheme.generics, &predicates, tag_item_generics);
+ encode_type(ecx, rbml_w, scheme.ty);
}
fn encode_variant_id(rbml_w: &mut Encoder, vid: DefId) {
encode_disr_val(ecx, rbml_w, (*vi)[i].disr_val);
disr_val = (*vi)[i].disr_val;
}
- encode_bounds_and_type(rbml_w, ecx,
- &lookup_item_type(ecx.tcx, def_id));
+ encode_bounds_and_type_for_item(rbml_w, ecx, def_id.local_id());
ecx.tcx.map.with_path(variant.node.id, |path| encode_path(rbml_w, path));
rbml_w.end_tag();
token::get_name(nm), id);
encode_struct_field_family(rbml_w, field.vis);
encode_name(rbml_w, nm);
- encode_bounds_and_type(rbml_w, ecx,
- &lookup_item_type(ecx.tcx, local_def(id)));
+ encode_bounds_and_type_for_item(rbml_w, ecx, id);
encode_def_id(rbml_w, local_def(id));
let stab = stability::lookup(ecx.tcx, field.id);
rbml_w.start_tag(tag_items_data_item);
encode_def_id(rbml_w, local_def(ctor_id));
encode_family(rbml_w, 'o');
- encode_bounds_and_type(rbml_w, ecx,
- &lookup_item_type(ecx.tcx, local_def(ctor_id)));
+ encode_bounds_and_type_for_item(rbml_w, ecx, ctor_id);
encode_name(rbml_w, name.name);
ecx.tcx.map.with_path(ctor_id, |path| encode_path(rbml_w, path));
encode_parent_item(rbml_w, local_def(struct_id));
fn encode_generics<'a, 'tcx>(rbml_w: &mut Encoder,
ecx: &EncodeContext<'a, 'tcx>,
generics: &ty::Generics<'tcx>,
+ predicates: &ty::GenericPredicates<'tcx>,
tag: uint)
{
rbml_w.start_tag(tag);
rbml_w.end_tag();
}
- for (space, _, predicate) in generics.predicates.iter_enumerated() {
+ for (space, _, predicate) in predicates.predicates.iter_enumerated() {
rbml_w.start_tag(tag_predicate);
rbml_w.wr_tagged_u8(tag_predicate_space, space as u8);
method_ty: &ty::Method<'tcx>) {
encode_def_id(rbml_w, method_ty.def_id);
encode_name(rbml_w, method_ty.name);
- encode_generics(rbml_w, ecx, &method_ty.generics,
+ encode_generics(rbml_w, ecx, &method_ty.generics, &method_ty.predicates,
tag_method_ty_generics);
encode_method_fty(ecx, rbml_w, &method_ty.fty);
encode_visibility(rbml_w, method_ty.vis);
encode_stability(rbml_w, stab);
// The type for methods gets encoded twice, which is unfortunate.
- let pty = lookup_item_type(ecx.tcx, m.def_id);
- encode_bounds_and_type(rbml_w, ecx, &pty);
+ encode_bounds_and_type_for_item(rbml_w, ecx, m.def_id.local_id());
let elem = ast_map::PathName(m.name);
encode_path(rbml_w, impl_path.chain(Some(elem).into_iter()));
match ast_item_opt {
Some(&ast::MethodImplItem(ref ast_method)) => {
encode_attributes(rbml_w, &ast_method.attrs[]);
- let any_types = !pty.generics.types.is_empty();
+ let scheme = ty::lookup_item_type(ecx.tcx, m.def_id);
+ let any_types = !scheme.generics.types.is_empty();
if any_types || is_default_impl || should_inline(&ast_method.attrs[]) {
encode_inlined_item(ecx, rbml_w, IIImplItemRef(local_def(parent_id),
ast_item_opt.unwrap()));
encode_parent_item(rbml_w, local_def(parent_id));
encode_item_sort(rbml_w, 't');
- let type_scheme = ty::lookup_item_type(ecx.tcx, associated_type.def_id);
- encode_bounds_and_type(rbml_w, ecx, &type_scheme);
+ encode_bounds_and_type_for_item(rbml_w, ecx, associated_type.def_id.local_id());
let stab = stability::lookup(ecx.tcx, associated_type.def_id);
encode_stability(rbml_w, stab);
} else {
encode_family(rbml_w, 'c');
}
- encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id));
+ encode_bounds_and_type_for_item(rbml_w, ecx, item.id);
encode_symbol(ecx, rbml_w, item.id);
encode_name(rbml_w, item.ident.name);
encode_path(rbml_w, path);
rbml_w.start_tag(tag_items_data_item);
encode_def_id(rbml_w, def_id);
encode_family(rbml_w, 'C');
- encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id));
+ encode_bounds_and_type_for_item(rbml_w, ecx, item.id);
encode_name(rbml_w, item.ident.name);
encode_path(rbml_w, path);
encode_attributes(rbml_w, &item.attrs);
encode_def_id(rbml_w, def_id);
encode_family(rbml_w, FN_FAMILY);
let tps_len = generics.ty_params.len();
- encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id));
+ encode_bounds_and_type_for_item(rbml_w, ecx, item.id);
encode_name(rbml_w, item.ident.name);
encode_path(rbml_w, path);
encode_attributes(rbml_w, &item.attrs[]);
rbml_w.start_tag(tag_items_data_item);
encode_def_id(rbml_w, def_id);
encode_family(rbml_w, 'y');
- encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id));
+ encode_bounds_and_type_for_item(rbml_w, ecx, item.id);
encode_name(rbml_w, item.ident.name);
encode_path(rbml_w, path);
encode_visibility(rbml_w, vis);
encode_def_id(rbml_w, def_id);
encode_family(rbml_w, 't');
encode_item_variances(rbml_w, ecx, item.id);
- encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id));
+ encode_bounds_and_type_for_item(rbml_w, ecx, item.id);
encode_name(rbml_w, item.ident.name);
encode_attributes(rbml_w, &item.attrs[]);
encode_repr_attrs(rbml_w, ecx, &item.attrs[]);
rbml_w.start_tag(tag_items_data_item);
encode_def_id(rbml_w, def_id);
encode_family(rbml_w, 'S');
- encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id));
+ encode_bounds_and_type_for_item(rbml_w, ecx, item.id);
encode_item_variances(rbml_w, ecx, item.id);
encode_name(rbml_w, item.ident.name);
rbml_w.start_tag(tag_items_data_item);
encode_def_id(rbml_w, def_id);
encode_family(rbml_w, 'i');
- encode_bounds_and_type(rbml_w, ecx, &lookup_item_type(tcx, def_id));
+ encode_bounds_and_type_for_item(rbml_w, ecx, item.id);
encode_name(rbml_w, item.ident.name);
encode_attributes(rbml_w, &item.attrs[]);
encode_unsafety(rbml_w, unsafety);
encode_family(rbml_w, 'I');
encode_item_variances(rbml_w, ecx, item.id);
let trait_def = ty::lookup_trait_def(tcx, def_id);
+ let trait_predicates = ty::lookup_predicates(tcx, def_id);
encode_unsafety(rbml_w, trait_def.unsafety);
encode_paren_sugar(rbml_w, trait_def.paren_sugar);
encode_associated_type_names(rbml_w, &trait_def.associated_type_names);
- encode_generics(rbml_w, ecx, &trait_def.generics, tag_item_generics);
+ encode_generics(rbml_w, ecx, &trait_def.generics, &trait_predicates, tag_item_generics);
encode_trait_ref(rbml_w, ecx, &*trait_def.trait_ref, tag_item_trait_ref);
encode_name(rbml_w, item.ident.name);
encode_attributes(rbml_w, &item.attrs[]);
METHOD_FAMILY);
}
}
- let pty = ty::lookup_item_type(tcx,
- method_def_id);
- encode_bounds_and_type(rbml_w, ecx, &pty);
+ encode_bounds_and_type_for_item(rbml_w, ecx, method_def_id.local_id());
is_nonstatic_method = method_ty.explicit_self !=
ty::StaticExplicitSelfCategory;
if is_nonstatic_method {
// FIXME: I feel like there is something funny
// going on.
- let pty = ty::lookup_item_type(tcx, item_def_id.def_id());
- encode_bounds_and_type(rbml_w, ecx, &pty);
+ encode_bounds_and_type_for_item(rbml_w, ecx, item_def_id.def_id().local_id());
}
};
match trait_item {
match nitem.node {
ast::ForeignItemFn(ref fndecl, _) => {
encode_family(rbml_w, FN_FAMILY);
- encode_bounds_and_type(rbml_w, ecx,
- &lookup_item_type(ecx.tcx,local_def(nitem.id)));
+ encode_bounds_and_type_for_item(rbml_w, ecx, nitem.id);
encode_name(rbml_w, nitem.ident.name);
if abi == abi::RustIntrinsic {
encode_inlined_item(ecx, rbml_w, IIForeignRef(nitem));
} else {
encode_family(rbml_w, 'c');
}
- encode_bounds_and_type(rbml_w, ecx,
- &lookup_item_type(ecx.tcx,local_def(nitem.id)));
+ encode_bounds_and_type_for_item(rbml_w, ecx, nitem.id);
encode_attributes(rbml_w, &*nitem.attrs);
let stab = stability::lookup(ecx.tcx, ast_util::local_def(nitem.id));
encode_stability(rbml_w, stab);