Skip to content

Commit 8c4a224

Browse files
committed
extract encode_info_for_trait_item into method
1 parent 8dc8151 commit 8c4a224

File tree

1 file changed

+109
-100
lines changed

1 file changed

+109
-100
lines changed

src/librustc_metadata/encoder.rs

Lines changed: 109 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use def_key;
2121
use tyencode;
2222
use index::{self, IndexData};
2323

24-
use middle::cstore::{LOCAL_CRATE, InlinedItemRef, LinkMeta, tls};
24+
use middle::cstore::{InlinedItemRef, LinkMeta, tls};
2525
use rustc::hir::def;
2626
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
2727
use middle::dependency_format::Linkage;
@@ -531,6 +531,109 @@ impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
531531
}
532532

533533
impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
534+
fn encode_info_for_trait_item(&mut self,
535+
trait_def_id: DefId,
536+
item_def_id: DefId,
537+
trait_item: &hir::TraitItem) {
538+
let ecx = self.ecx;
539+
let tcx = ecx.tcx;
540+
541+
self.encode_parent_item(trait_def_id);
542+
543+
let stab = tcx.lookup_stability(item_def_id);
544+
let depr = tcx.lookup_deprecation(item_def_id);
545+
encode_stability(self.rbml_w, stab);
546+
encode_deprecation(self.rbml_w, depr);
547+
548+
let trait_item_type =
549+
tcx.impl_or_trait_item(item_def_id);
550+
let is_nonstatic_method;
551+
match trait_item_type {
552+
ty::ConstTraitItem(associated_const) => {
553+
encode_name(self.rbml_w, associated_const.name);
554+
encode_def_id_and_key(ecx, self.rbml_w, associated_const.def_id);
555+
self.encode_visibility(associated_const.vis);
556+
557+
encode_family(self.rbml_w, 'C');
558+
559+
self.encode_bounds_and_type_for_item(
560+
ecx.local_id(associated_const.def_id));
561+
562+
is_nonstatic_method = false;
563+
}
564+
ty::MethodTraitItem(method_ty) => {
565+
let method_def_id = item_def_id;
566+
567+
self.encode_method_ty_fields(&method_ty);
568+
569+
match method_ty.explicit_self {
570+
ty::ExplicitSelfCategory::Static => {
571+
encode_family(self.rbml_w,
572+
STATIC_METHOD_FAMILY);
573+
}
574+
_ => {
575+
encode_family(self.rbml_w,
576+
METHOD_FAMILY);
577+
}
578+
}
579+
self.encode_bounds_and_type_for_item(ecx.local_id(method_def_id));
580+
581+
is_nonstatic_method = method_ty.explicit_self !=
582+
ty::ExplicitSelfCategory::Static;
583+
}
584+
ty::TypeTraitItem(associated_type) => {
585+
encode_name(self.rbml_w, associated_type.name);
586+
encode_def_id_and_key(ecx, self.rbml_w, associated_type.def_id);
587+
encode_item_sort(self.rbml_w, 't');
588+
encode_family(self.rbml_w, 'y');
589+
590+
if let Some(ty) = associated_type.ty {
591+
self.encode_type(ty);
592+
}
593+
594+
is_nonstatic_method = false;
595+
}
596+
}
597+
598+
encode_attributes(self.rbml_w, &trait_item.attrs);
599+
match trait_item.node {
600+
hir::ConstTraitItem(_, ref default) => {
601+
if default.is_some() {
602+
encode_item_sort(self.rbml_w, 'C');
603+
} else {
604+
encode_item_sort(self.rbml_w, 'c');
605+
}
606+
607+
encode_inlined_item(ecx, self.rbml_w,
608+
InlinedItemRef::TraitItem(trait_def_id, trait_item));
609+
self.encode_mir(trait_item.id);
610+
}
611+
hir::MethodTraitItem(ref sig, ref body) => {
612+
// If this is a static method, we've already
613+
// encoded self.
614+
if is_nonstatic_method {
615+
self.encode_bounds_and_type_for_item(
616+
ecx.local_id(item_def_id));
617+
}
618+
619+
if body.is_some() {
620+
encode_item_sort(self.rbml_w, 'p');
621+
encode_inlined_item(ecx,
622+
self.rbml_w,
623+
InlinedItemRef::TraitItem(
624+
trait_def_id,
625+
trait_item));
626+
self.encode_mir(trait_item.id);
627+
} else {
628+
encode_item_sort(self.rbml_w, 'r');
629+
}
630+
self.encode_method_argument_names(&sig.decl);
631+
}
632+
633+
hir::TypeTraitItem(..) => {}
634+
}
635+
}
636+
534637
fn encode_info_for_impl_item(&mut self,
535638
impl_id: NodeId,
536639
impl_item_def_id: DefId,
@@ -1145,107 +1248,13 @@ impl<'a, 'tcx, 'encoder> IndexBuilder<'a, 'tcx, 'encoder> {
11451248
def_id: DefId,
11461249
trait_items: &[hir::TraitItem]) {
11471250
// Now output the trait item info for each trait item.
1148-
let ecx = self.ecx;
11491251
let tcx = self.ecx.tcx;
11501252
let r = tcx.trait_item_def_ids(def_id);
1151-
for (&item_def_id, trait_item) in r.iter().zip(trait_items) {
1152-
assert_eq!(item_def_id.def_id().krate, LOCAL_CRATE);
1153-
1154-
self.record(item_def_id.def_id(), |this| {
1155-
this.encode_parent_item(def_id);
1156-
1157-
let stab = tcx.lookup_stability(item_def_id.def_id());
1158-
let depr = tcx.lookup_deprecation(item_def_id.def_id());
1159-
encode_stability(this.rbml_w, stab);
1160-
encode_deprecation(this.rbml_w, depr);
1161-
1162-
let trait_item_type =
1163-
tcx.impl_or_trait_item(item_def_id.def_id());
1164-
let is_nonstatic_method;
1165-
match trait_item_type {
1166-
ty::ConstTraitItem(associated_const) => {
1167-
encode_name(this.rbml_w, associated_const.name);
1168-
encode_def_id_and_key(ecx, this.rbml_w, associated_const.def_id);
1169-
this.encode_visibility(associated_const.vis);
1170-
1171-
encode_family(this.rbml_w, 'C');
1172-
1173-
this.encode_bounds_and_type_for_item(
1174-
ecx.local_id(associated_const.def_id));
1175-
1176-
is_nonstatic_method = false;
1177-
}
1178-
ty::MethodTraitItem(method_ty) => {
1179-
let method_def_id = item_def_id.def_id();
1180-
1181-
this.encode_method_ty_fields(&method_ty);
1182-
1183-
match method_ty.explicit_self {
1184-
ty::ExplicitSelfCategory::Static => {
1185-
encode_family(this.rbml_w,
1186-
STATIC_METHOD_FAMILY);
1187-
}
1188-
_ => {
1189-
encode_family(this.rbml_w,
1190-
METHOD_FAMILY);
1191-
}
1192-
}
1193-
this.encode_bounds_and_type_for_item(ecx.local_id(method_def_id));
1194-
1195-
is_nonstatic_method = method_ty.explicit_self !=
1196-
ty::ExplicitSelfCategory::Static;
1197-
}
1198-
ty::TypeTraitItem(associated_type) => {
1199-
encode_name(this.rbml_w, associated_type.name);
1200-
encode_def_id_and_key(ecx, this.rbml_w, associated_type.def_id);
1201-
encode_item_sort(this.rbml_w, 't');
1202-
encode_family(this.rbml_w, 'y');
1203-
1204-
if let Some(ty) = associated_type.ty {
1205-
this.encode_type(ty);
1206-
}
1207-
1208-
is_nonstatic_method = false;
1209-
}
1210-
}
1211-
1212-
encode_attributes(this.rbml_w, &trait_item.attrs);
1213-
match trait_item.node {
1214-
hir::ConstTraitItem(_, ref default) => {
1215-
if default.is_some() {
1216-
encode_item_sort(this.rbml_w, 'C');
1217-
} else {
1218-
encode_item_sort(this.rbml_w, 'c');
1219-
}
1220-
1221-
encode_inlined_item(ecx, this.rbml_w,
1222-
InlinedItemRef::TraitItem(def_id, trait_item));
1223-
this.encode_mir(trait_item.id);
1224-
}
1225-
hir::MethodTraitItem(ref sig, ref body) => {
1226-
// If this is a static method, we've already
1227-
// encoded this.
1228-
if is_nonstatic_method {
1229-
this.encode_bounds_and_type_for_item(
1230-
ecx.local_id(item_def_id.def_id()));
1231-
}
1232-
1233-
if body.is_some() {
1234-
encode_item_sort(this.rbml_w, 'p');
1235-
encode_inlined_item(ecx,
1236-
this.rbml_w,
1237-
InlinedItemRef::TraitItem(
1238-
def_id,
1239-
trait_item));
1240-
this.encode_mir(trait_item.id);
1241-
} else {
1242-
encode_item_sort(this.rbml_w, 'r');
1243-
}
1244-
this.encode_method_argument_names(&sig.decl);
1245-
}
1246-
1247-
hir::TypeTraitItem(..) => {}
1248-
}
1253+
for (item_def_id, trait_item) in r.iter().zip(trait_items) {
1254+
let item_def_id = item_def_id.def_id();
1255+
assert!(item_def_id.is_local());
1256+
self.record(item_def_id, |this| {
1257+
this.encode_info_for_trait_item(def_id, item_def_id, trait_item)
12491258
});
12501259
}
12511260
}

0 commit comments

Comments
 (0)