16
16
// mappings. That mapping code resides here.
17
17
18
18
19
- use metadata:: csearch:: { each_impl, get_impl_trait} ;
20
- use metadata:: csearch;
21
19
use middle:: subst:: { self , Subst } ;
22
20
use middle:: ty:: RegionEscape ;
23
21
use middle:: ty:: { ImplContainer , ImplOrTraitItemId , ConstTraitItemId } ;
24
- use middle:: ty:: { MethodTraitItemId , TypeTraitItemId } ;
25
- use middle:: ty:: { ParameterEnvironment , lookup_item_type} ;
22
+ use middle:: ty:: { MethodTraitItemId , TypeTraitItemId , ParameterEnvironment } ;
26
23
use middle:: ty:: { Ty , ty_bool, ty_char, ty_enum, ty_err} ;
27
24
use middle:: ty:: { ty_param, TypeScheme , ty_ptr} ;
28
25
use middle:: ty:: { ty_rptr, ty_struct, ty_trait, ty_tup} ;
@@ -33,7 +30,6 @@ use middle::ty;
33
30
use CrateCtxt ;
34
31
use middle:: infer:: InferCtxt ;
35
32
use middle:: infer:: new_infer_ctxt;
36
- use std:: collections:: HashSet ;
37
33
use std:: cell:: RefCell ;
38
34
use std:: rc:: Rc ;
39
35
use syntax:: ast:: { Crate , DefId } ;
@@ -130,11 +126,6 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
130
126
Rc :: new ( ( * v. borrow ( ) ) . clone ( ) ) ) ;
131
127
}
132
128
133
- // Bring in external crates. It's fine for this to happen after the
134
- // coherence checks, because we ensure by construction that no errors
135
- // can happen at link time.
136
- self . add_external_crates ( ) ;
137
-
138
129
// Populate the table of destructors. It might seem a bit strange to
139
130
// do this here, but it's actually the most convenient place, since
140
131
// the coherence tables contain the trait -> type mappings.
@@ -267,11 +258,6 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
267
258
trait_def. record_impl ( self . crate_context . tcx , impl_def_id, impl_trait_ref) ;
268
259
}
269
260
270
- fn get_self_type_for_implementation ( & self , impl_did : DefId )
271
- -> TypeScheme < ' tcx > {
272
- self . crate_context . tcx . tcache . borrow ( ) . get ( & impl_did) . unwrap ( ) . clone ( )
273
- }
274
-
275
261
// Converts an implementation in the AST to a vector of items.
276
262
fn create_impl_from_item ( & self , item : & Item ) -> Vec < ImplOrTraitItemId > {
277
263
match item. node {
@@ -313,66 +299,6 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
313
299
}
314
300
}
315
301
316
- // External crate handling
317
-
318
- fn add_external_impl ( & self ,
319
- impls_seen : & mut HashSet < DefId > ,
320
- impl_def_id : DefId ) {
321
- let tcx = self . crate_context . tcx ;
322
- let impl_items = csearch:: get_impl_items ( & tcx. sess . cstore ,
323
- impl_def_id) ;
324
-
325
- // Make sure we don't visit the same implementation multiple times.
326
- if !impls_seen. insert ( impl_def_id) {
327
- // Skip this one.
328
- return
329
- }
330
- // Good. Continue.
331
-
332
- let _ = lookup_item_type ( tcx, impl_def_id) ;
333
- let associated_traits = get_impl_trait ( tcx, impl_def_id) ;
334
-
335
- // Do a sanity check.
336
- assert ! ( associated_traits. is_some( ) ) ;
337
-
338
- // Record all the trait items.
339
- if let Some ( trait_ref) = associated_traits {
340
- self . add_trait_impl ( trait_ref, impl_def_id) ;
341
- }
342
-
343
- // For any methods that use a default implementation, add them to
344
- // the map. This is a bit unfortunate.
345
- for item_def_id in & impl_items {
346
- let impl_item = ty:: impl_or_trait_item ( tcx, item_def_id. def_id ( ) ) ;
347
- match impl_item {
348
- ty:: MethodTraitItem ( ref method) => {
349
- if let Some ( source) = method. provided_source {
350
- tcx. provided_method_sources
351
- . borrow_mut ( )
352
- . insert ( item_def_id. def_id ( ) , source) ;
353
- }
354
- }
355
- _ => { }
356
- }
357
- }
358
-
359
- tcx. impl_items . borrow_mut ( ) . insert ( impl_def_id, impl_items) ;
360
- }
361
-
362
- // Adds implementations and traits from external crates to the coherence
363
- // info.
364
- fn add_external_crates ( & self ) {
365
- let mut impls_seen = HashSet :: new ( ) ;
366
-
367
- let crate_store = & self . crate_context . tcx . sess . cstore ;
368
- crate_store. iter_crate_data ( |crate_number, _crate_metadata| {
369
- each_impl ( crate_store, crate_number, |def_id| {
370
- assert_eq ! ( crate_number, def_id. krate) ;
371
- self . add_external_impl ( & mut impls_seen, def_id)
372
- } )
373
- } )
374
- }
375
-
376
302
//
377
303
// Destructors
378
304
//
@@ -395,7 +321,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
395
321
}
396
322
let method_def_id = items[ 0 ] ;
397
323
398
- let self_type = self . get_self_type_for_implementation ( impl_did) ;
324
+ let self_type = ty :: lookup_item_type ( tcx , impl_did) ;
399
325
match self_type. ty . sty {
400
326
ty:: ty_enum( type_def_id, _) |
401
327
ty:: ty_struct( type_def_id, _) |
@@ -451,7 +377,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
451
377
return
452
378
}
453
379
454
- let self_type = self . get_self_type_for_implementation ( impl_did) ;
380
+ let self_type = ty :: lookup_item_type ( tcx , impl_did) ;
455
381
debug ! ( "check_implementations_of_copy: self_type={} (bound)" ,
456
382
self_type. repr( tcx) ) ;
457
383
0 commit comments