@@ -27,34 +27,34 @@ use rustc::hir::map as hir_map;
27
27
use rustc:: hir:: { self , ItemImpl } ;
28
28
29
29
pub 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
+ }
47
37
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) ;
53
47
} ) ;
48
+ impls. sort ( ) ;
49
+ for impl_def_id in impls {
50
+ f ( tcx, trait_def_id, impl_def_id) ;
51
+ }
54
52
}
55
53
}
56
54
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 ) {
58
58
let items = tcx. associated_item_def_ids ( impl_did) ;
59
59
if items. is_empty ( ) {
60
60
// 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:
96
96
}
97
97
}
98
98
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 ) {
100
102
debug ! ( "visit_implementation_of_copy: impl_did={:?}" , impl_did) ;
101
103
102
104
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:
166
168
}
167
169
168
170
fn 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 ) {
172
173
debug ! ( "visit_implementation_of_coerce_unsized: impl_did={:?}" ,
173
174
impl_did) ;
174
175
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
+
175
183
let impl_node_id = if let Some ( n) = tcx. map . as_local_node_id ( impl_did) {
176
184
n
177
185
} else {
0 commit comments