Skip to content

Commit 8dc8151

Browse files
committed
pull out call to record for impl items
1 parent 9afcd77 commit 8dc8151

File tree

1 file changed

+103
-99
lines changed

1 file changed

+103
-99
lines changed

src/librustc_metadata/encoder.rs

Lines changed: 103 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,31 @@ impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
530530
}
531531
}
532532

533-
impl<'a, 'tcx, 'encoder> IndexBuilder<'a, 'tcx, 'encoder> {
533+
impl<'a, 'tcx, 'encoder> ItemContentBuilder<'a, 'tcx, 'encoder> {
534+
fn encode_info_for_impl_item(&mut self,
535+
impl_id: NodeId,
536+
impl_item_def_id: DefId,
537+
ast_item: Option<&hir::ImplItem>) {
538+
match self.ecx.tcx.impl_or_trait_item(impl_item_def_id) {
539+
ty::ConstTraitItem(ref associated_const) => {
540+
self.encode_info_for_associated_const(&associated_const,
541+
impl_id,
542+
ast_item)
543+
}
544+
ty::MethodTraitItem(ref method_type) => {
545+
self.encode_info_for_method(&method_type,
546+
false,
547+
impl_id,
548+
ast_item)
549+
}
550+
ty::TypeTraitItem(ref associated_type) => {
551+
self.encode_info_for_associated_type(&associated_type,
552+
impl_id,
553+
ast_item)
554+
}
555+
}
556+
}
557+
534558
fn encode_info_for_associated_const(&mut self,
535559
associated_const: &ty::AssociatedConst,
536560
parent_id: NodeId,
@@ -540,32 +564,30 @@ impl<'a, 'tcx, 'encoder> IndexBuilder<'a, 'tcx, 'encoder> {
540564
associated_const.def_id,
541565
associated_const.name);
542566

543-
self.record(associated_const.def_id, |this| {
544-
encode_def_id_and_key(ecx, this.rbml_w, associated_const.def_id);
545-
encode_name(this.rbml_w, associated_const.name);
546-
this.encode_visibility(associated_const.vis);
547-
encode_family(this.rbml_w, 'C');
567+
encode_def_id_and_key(ecx, self.rbml_w, associated_const.def_id);
568+
encode_name(self.rbml_w, associated_const.name);
569+
self.encode_visibility(associated_const.vis);
570+
encode_family(self.rbml_w, 'C');
548571

549-
this.encode_parent_item(ecx.tcx.map.local_def_id(parent_id));
550-
encode_item_sort(this.rbml_w, 'C');
551-
552-
this.encode_bounds_and_type_for_item(ecx.local_id(associated_const.def_id));
553-
554-
let stab = ecx.tcx.lookup_stability(associated_const.def_id);
555-
let depr = ecx.tcx.lookup_deprecation(associated_const.def_id);
556-
encode_stability(this.rbml_w, stab);
557-
encode_deprecation(this.rbml_w, depr);
558-
559-
if let Some(ii) = impl_item_opt {
560-
encode_attributes(this.rbml_w, &ii.attrs);
561-
encode_defaultness(this.rbml_w, ii.defaultness);
562-
encode_inlined_item(ecx,
563-
this.rbml_w,
564-
InlinedItemRef::ImplItem(ecx.tcx.map.local_def_id(parent_id),
565-
ii));
566-
this.encode_mir(ii.id);
567-
}
568-
});
572+
self.encode_parent_item(ecx.tcx.map.local_def_id(parent_id));
573+
encode_item_sort(self.rbml_w, 'C');
574+
575+
self.encode_bounds_and_type_for_item(ecx.local_id(associated_const.def_id));
576+
577+
let stab = ecx.tcx.lookup_stability(associated_const.def_id);
578+
let depr = ecx.tcx.lookup_deprecation(associated_const.def_id);
579+
encode_stability(self.rbml_w, stab);
580+
encode_deprecation(self.rbml_w, depr);
581+
582+
if let Some(ii) = impl_item_opt {
583+
encode_attributes(self.rbml_w, &ii.attrs);
584+
encode_defaultness(self.rbml_w, ii.defaultness);
585+
encode_inlined_item(ecx,
586+
self.rbml_w,
587+
InlinedItemRef::ImplItem(ecx.tcx.map.local_def_id(parent_id),
588+
ii));
589+
self.encode_mir(ii.id);
590+
}
569591
}
570592

571593
fn encode_info_for_method(&mut self,
@@ -577,40 +599,38 @@ impl<'a, 'tcx, 'encoder> IndexBuilder<'a, 'tcx, 'encoder> {
577599

578600
debug!("encode_info_for_method: {:?} {:?}", m.def_id,
579601
m.name);
580-
self.record(m.def_id, |this| {
581-
this.encode_method_ty_fields(m);
582-
this.encode_parent_item(ecx.tcx.map.local_def_id(parent_id));
583-
encode_item_sort(this.rbml_w, 'r');
584-
585-
let stab = ecx.tcx.lookup_stability(m.def_id);
586-
let depr = ecx.tcx.lookup_deprecation(m.def_id);
587-
encode_stability(this.rbml_w, stab);
588-
encode_deprecation(this.rbml_w, depr);
589-
590-
let m_node_id = ecx.local_id(m.def_id);
591-
this.encode_bounds_and_type_for_item(m_node_id);
592-
593-
if let Some(impl_item) = impl_item_opt {
594-
if let hir::ImplItemKind::Method(ref sig, _) = impl_item.node {
595-
encode_attributes(this.rbml_w, &impl_item.attrs);
596-
let generics = ecx.tcx.lookup_generics(m.def_id);
597-
let types = generics.parent_types as usize + generics.types.len();
598-
let needs_inline = types > 0 || is_default_impl ||
599-
attr::requests_inline(&impl_item.attrs);
600-
if needs_inline || sig.constness == hir::Constness::Const {
601-
encode_inlined_item(
602-
ecx,
603-
this.rbml_w,
604-
InlinedItemRef::ImplItem(ecx.tcx.map.local_def_id(parent_id),
605-
impl_item));
606-
this.encode_mir(impl_item.id);
607-
}
608-
encode_constness(this.rbml_w, sig.constness);
609-
encode_defaultness(this.rbml_w, impl_item.defaultness);
610-
this.encode_method_argument_names(&sig.decl);
602+
self.encode_method_ty_fields(m);
603+
self.encode_parent_item(ecx.tcx.map.local_def_id(parent_id));
604+
encode_item_sort(self.rbml_w, 'r');
605+
606+
let stab = ecx.tcx.lookup_stability(m.def_id);
607+
let depr = ecx.tcx.lookup_deprecation(m.def_id);
608+
encode_stability(self.rbml_w, stab);
609+
encode_deprecation(self.rbml_w, depr);
610+
611+
let m_node_id = ecx.local_id(m.def_id);
612+
self.encode_bounds_and_type_for_item(m_node_id);
613+
614+
if let Some(impl_item) = impl_item_opt {
615+
if let hir::ImplItemKind::Method(ref sig, _) = impl_item.node {
616+
encode_attributes(self.rbml_w, &impl_item.attrs);
617+
let generics = ecx.tcx.lookup_generics(m.def_id);
618+
let types = generics.parent_types as usize + generics.types.len();
619+
let needs_inline = types > 0 || is_default_impl ||
620+
attr::requests_inline(&impl_item.attrs);
621+
if needs_inline || sig.constness == hir::Constness::Const {
622+
encode_inlined_item(
623+
ecx,
624+
self.rbml_w,
625+
InlinedItemRef::ImplItem(ecx.tcx.map.local_def_id(parent_id),
626+
impl_item));
627+
self.encode_mir(impl_item.id);
611628
}
629+
encode_constness(self.rbml_w, sig.constness);
630+
encode_defaultness(self.rbml_w, impl_item.defaultness);
631+
self.encode_method_argument_names(&sig.decl);
612632
}
613-
});
633+
}
614634
}
615635

616636
fn encode_info_for_associated_type(&mut self,
@@ -622,32 +642,30 @@ impl<'a, 'tcx, 'encoder> IndexBuilder<'a, 'tcx, 'encoder> {
622642
associated_type.def_id,
623643
associated_type.name);
624644

625-
self.record(associated_type.def_id, |this| {
626-
encode_def_id_and_key(ecx, this.rbml_w, associated_type.def_id);
627-
encode_name(this.rbml_w, associated_type.name);
628-
this.encode_visibility(associated_type.vis);
629-
encode_family(this.rbml_w, 'y');
630-
this.encode_parent_item(ecx.tcx.map.local_def_id(parent_id));
631-
encode_item_sort(this.rbml_w, 't');
645+
encode_def_id_and_key(ecx, self.rbml_w, associated_type.def_id);
646+
encode_name(self.rbml_w, associated_type.name);
647+
self.encode_visibility(associated_type.vis);
648+
encode_family(self.rbml_w, 'y');
649+
self.encode_parent_item(ecx.tcx.map.local_def_id(parent_id));
650+
encode_item_sort(self.rbml_w, 't');
632651

633-
let stab = ecx.tcx.lookup_stability(associated_type.def_id);
634-
let depr = ecx.tcx.lookup_deprecation(associated_type.def_id);
635-
encode_stability(this.rbml_w, stab);
636-
encode_deprecation(this.rbml_w, depr);
652+
let stab = ecx.tcx.lookup_stability(associated_type.def_id);
653+
let depr = ecx.tcx.lookup_deprecation(associated_type.def_id);
654+
encode_stability(self.rbml_w, stab);
655+
encode_deprecation(self.rbml_w, depr);
637656

638-
if let Some(ii) = impl_item_opt {
639-
encode_attributes(this.rbml_w, &ii.attrs);
640-
encode_defaultness(this.rbml_w, ii.defaultness);
641-
} else {
642-
// TODO this looks bogus and unnecessary
643-
this.encode_predicates(&ecx.tcx.lookup_predicates(associated_type.def_id),
644-
tag_item_generics);
645-
}
657+
if let Some(ii) = impl_item_opt {
658+
encode_attributes(self.rbml_w, &ii.attrs);
659+
encode_defaultness(self.rbml_w, ii.defaultness);
660+
} else {
661+
// TODO this looks bogus and unnecessary
662+
self.encode_predicates(&ecx.tcx.lookup_predicates(associated_type.def_id),
663+
tag_item_generics);
664+
}
646665

647-
if let Some(ty) = associated_type.ty {
648-
this.encode_type(ty);
649-
}
650-
});
666+
if let Some(ty) = associated_type.ty {
667+
self.encode_type(ty);
668+
}
651669
}
652670
}
653671

@@ -1116,24 +1134,10 @@ impl<'a, 'tcx, 'encoder> IndexBuilder<'a, 'tcx, 'encoder> {
11161134
None
11171135
};
11181136

1119-
match self.ecx.tcx.impl_or_trait_item(trait_item_def_id.def_id()) {
1120-
ty::ConstTraitItem(ref associated_const) => {
1121-
self.encode_info_for_associated_const(&associated_const,
1122-
impl_id,
1123-
ast_item)
1124-
}
1125-
ty::MethodTraitItem(ref method_type) => {
1126-
self.encode_info_for_method(&method_type,
1127-
false,
1128-
impl_id,
1129-
ast_item)
1130-
}
1131-
ty::TypeTraitItem(ref associated_type) => {
1132-
self.encode_info_for_associated_type(&associated_type,
1133-
impl_id,
1134-
ast_item)
1135-
}
1136-
}
1137+
let trait_item_def_id = trait_item_def_id.def_id();
1138+
self.record(trait_item_def_id, |this| {
1139+
this.encode_info_for_impl_item(impl_id, trait_item_def_id, ast_item)
1140+
});
11371141
}
11381142
}
11391143

0 commit comments

Comments
 (0)