@@ -27,34 +27,34 @@ use rustc::hir::map as hir_map;
2727use rustc:: hir:: { self , ItemImpl } ;
2828
2929pub fn check < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ) {
30- if let Some ( drop_trait) = tcx. lang_items . drop_trait ( ) {
31- tcx. lookup_trait_def ( drop_trait)
32- . for_each_impl ( tcx, |impl_did| visit_implementation_of_drop ( tcx, impl_did) ) ;
33- }
34-
35- if let Some ( copy_trait) = tcx. lang_items . copy_trait ( ) {
36- tcx. lookup_trait_def ( copy_trait)
37- . for_each_impl ( tcx, |impl_did| visit_implementation_of_copy ( tcx, impl_did) ) ;
38- }
39-
40- if let Some ( coerce_unsized_trait) = tcx. lang_items . coerce_unsized_trait ( ) {
41- let unsize_trait = match tcx. lang_items . require ( UnsizeTraitLangItem ) {
42- Ok ( id) => id,
43- Err ( err) => {
44- tcx. sess . fatal ( & format ! ( "`CoerceUnsized` implementation {}" , err) ) ;
45- }
46- } ;
30+ check_trait ( tcx, tcx. lang_items . drop_trait ( ) , visit_implementation_of_drop) ;
31+ check_trait ( tcx, tcx. lang_items . copy_trait ( ) , visit_implementation_of_copy) ;
32+ check_trait (
33+ tcx,
34+ tcx. lang_items . coerce_unsized_trait ( ) ,
35+ visit_implementation_of_coerce_unsized) ;
36+ }
4737
48- tcx. lookup_trait_def ( coerce_unsized_trait) . for_each_impl ( tcx, |impl_did| {
49- visit_implementation_of_coerce_unsized ( tcx,
50- impl_did,
51- unsize_trait,
52- coerce_unsized_trait)
38+ fn check_trait < ' a , ' tcx , F > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
39+ trait_def_id : Option < DefId > ,
40+ mut f : F )
41+ where F : FnMut ( TyCtxt < ' a , ' tcx , ' tcx > , DefId , DefId )
42+ {
43+ if let Some ( trait_def_id) = trait_def_id {
44+ let mut impls = vec ! [ ] ;
45+ tcx. lookup_trait_def ( trait_def_id) . for_each_impl ( tcx, |did| {
46+ impls. push ( did) ;
5347 } ) ;
48+ impls. sort ( ) ;
49+ for impl_def_id in impls {
50+ f ( tcx, trait_def_id, impl_def_id) ;
51+ }
5452 }
5553}
5654
57- fn visit_implementation_of_drop < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , impl_did : DefId ) {
55+ fn visit_implementation_of_drop < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
56+ _drop_did : DefId ,
57+ impl_did : DefId ) {
5858 let items = tcx. associated_item_def_ids ( impl_did) ;
5959 if items. is_empty ( ) {
6060 // We'll error out later. For now, just don't ICE.
@@ -96,7 +96,9 @@ fn visit_implementation_of_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did:
9696 }
9797}
9898
99- fn visit_implementation_of_copy < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > , impl_did : DefId ) {
99+ fn visit_implementation_of_copy < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
100+ _copy_did : DefId ,
101+ impl_did : DefId ) {
100102 debug ! ( "visit_implementation_of_copy: impl_did={:?}" , impl_did) ;
101103
102104 let impl_node_id = if let Some ( n) = tcx. map . as_local_node_id ( impl_did) {
@@ -166,12 +168,18 @@ fn visit_implementation_of_copy<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, impl_did:
166168}
167169
168170fn visit_implementation_of_coerce_unsized < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
169- impl_did : DefId ,
170- unsize_trait : DefId ,
171- coerce_unsized_trait : DefId ) {
171+ coerce_unsized_trait : DefId ,
172+ impl_did : DefId ) {
172173 debug ! ( "visit_implementation_of_coerce_unsized: impl_did={:?}" ,
173174 impl_did) ;
174175
176+ let unsize_trait = match tcx. lang_items . require ( UnsizeTraitLangItem ) {
177+ Ok ( id) => id,
178+ Err ( err) => {
179+ tcx. sess . fatal ( & format ! ( "`CoerceUnsized` implementation {}" , err) ) ;
180+ }
181+ } ;
182+
175183 let impl_node_id = if let Some ( n) = tcx. map . as_local_node_id ( impl_did) {
176184 n
177185 } else {
0 commit comments