Skip to content

Commit ae8cb22

Browse files
committed
factor out collection of impl-items into a distinct fn
1 parent 7918299 commit ae8cb22

File tree

2 files changed

+45
-36
lines changed

2 files changed

+45
-36
lines changed

src/librustc_trans/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
605605
// Create a fn pointer with the substituted signature.
606606
tcx.mk_fn_ptr(fty)
607607
}
608-
_ => bug!("expected fn item type, found {}", fn_ty)
608+
_ => bug!("expected fn item type for {:?}, found {}", def_id, fn_ty)
609609
};
610610
let llptrty = type_of::type_of(ccx, fn_ptr_ty);
611611

src/librustc_typeck/collect.rs

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CollectItemTypesVisitor<'a, 'tcx> {
150150
intravisit::walk_ty(self, ty);
151151
}
152152

153-
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem) {
153+
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem) {
154154
// handled in `visit_item` above; we may want to break this out later
155+
intravisit::walk_impl_item(self, impl_item);
155156
}
156157
}
157158

@@ -782,43 +783,10 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
782783
entry.insert(impl_item.span);
783784
}
784785
}
785-
786-
if let hir::ImplItemKind::Const(ref ty, _) = impl_item.node {
787-
let const_def_id = ccx.tcx.map.local_def_id(impl_item.id);
788-
generics_of_def_id(ccx, const_def_id);
789-
let ty = ccx.icx(&ty_predicates)
790-
.to_ty(&ExplicitRscope, &ty);
791-
tcx.item_types.borrow_mut().insert(const_def_id, ty);
792-
convert_associated_const(ccx, ImplContainer(def_id),
793-
impl_item.id, ty);
794-
}
795-
}
796-
797-
// Convert all the associated types.
798-
for &impl_item_id in impl_item_ids {
799-
let impl_item = tcx.map.impl_item(impl_item_id);
800-
if let hir::ImplItemKind::Type(ref ty) = impl_item.node {
801-
let type_def_id = ccx.tcx.map.local_def_id(impl_item.id);
802-
generics_of_def_id(ccx, type_def_id);
803-
804-
if opt_trait_ref.is_none() {
805-
span_err!(tcx.sess, impl_item.span, E0202,
806-
"associated types are not allowed in inherent impls");
807-
}
808-
809-
let typ = ccx.icx(&ty_predicates).to_ty(&ExplicitRscope, ty);
810-
811-
convert_associated_type(ccx, ImplContainer(def_id), impl_item.id, Some(typ));
812-
}
813786
}
814787

815788
for &impl_item_id in impl_item_ids {
816-
let impl_item = tcx.map.impl_item(impl_item_id);
817-
if let hir::ImplItemKind::Method(ref sig, _) = impl_item.node {
818-
convert_method(ccx, ImplContainer(def_id),
819-
impl_item.id, sig, selfty,
820-
&ty_predicates);
821-
}
789+
convert_impl_item(ccx, impl_item_id);
822790
}
823791

824792
enforce_impl_lifetimes_are_constrained(ccx, generics, def_id, impl_item_ids);
@@ -907,6 +875,47 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
907875
}
908876
}
909877

878+
fn convert_impl_item(ccx: &CrateCtxt, impl_item_id: hir::ImplItemId) {
879+
let tcx = ccx.tcx;
880+
let impl_item = tcx.map.impl_item(impl_item_id);
881+
let impl_def_id = tcx.map.get_parent_did(impl_item_id.id);
882+
let impl_predicates = tcx.item_predicates(impl_def_id);
883+
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id);
884+
let impl_self_ty = tcx.item_type(impl_def_id);
885+
886+
match impl_item.node {
887+
hir::ImplItemKind::Const(ref ty, _) => {
888+
let const_def_id = ccx.tcx.map.local_def_id(impl_item.id);
889+
generics_of_def_id(ccx, const_def_id);
890+
let ty = ccx.icx(&impl_predicates)
891+
.to_ty(&ExplicitRscope, &ty);
892+
tcx.item_types.borrow_mut().insert(const_def_id, ty);
893+
convert_associated_const(ccx, ImplContainer(impl_def_id),
894+
impl_item.id, ty);
895+
}
896+
897+
hir::ImplItemKind::Type(ref ty) => {
898+
let type_def_id = ccx.tcx.map.local_def_id(impl_item.id);
899+
generics_of_def_id(ccx, type_def_id);
900+
901+
if impl_trait_ref.is_none() {
902+
span_err!(tcx.sess, impl_item.span, E0202,
903+
"associated types are not allowed in inherent impls");
904+
}
905+
906+
let typ = ccx.icx(&impl_predicates).to_ty(&ExplicitRscope, ty);
907+
908+
convert_associated_type(ccx, ImplContainer(impl_def_id), impl_item.id, Some(typ));
909+
}
910+
911+
hir::ImplItemKind::Method(ref sig, _) => {
912+
convert_method(ccx, ImplContainer(impl_def_id),
913+
impl_item.id, sig, impl_self_ty,
914+
&impl_predicates);
915+
}
916+
}
917+
}
918+
910919
fn convert_variant_ctor<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
911920
ctor_id: ast::NodeId,
912921
variant: ty::VariantDef<'tcx>,

0 commit comments

Comments
 (0)