1616// mappings. That mapping code resides here.
1717
1818
19- use metadata:: csearch:: { each_impl, get_impl_trait} ;
20- use metadata:: csearch;
2119use middle:: subst:: { self , Subst } ;
2220use middle:: ty:: RegionEscape ;
2321use 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 } ;
2623use middle:: ty:: { Ty , ty_bool, ty_char, ty_enum, ty_err} ;
2724use middle:: ty:: { ty_param, TypeScheme , ty_ptr} ;
2825use middle:: ty:: { ty_rptr, ty_struct, ty_trait, ty_tup} ;
@@ -33,7 +30,6 @@ use middle::ty;
3330use CrateCtxt ;
3431use middle:: infer:: InferCtxt ;
3532use middle:: infer:: new_infer_ctxt;
36- use std:: collections:: HashSet ;
3733use std:: cell:: RefCell ;
3834use std:: rc:: Rc ;
3935use syntax:: ast:: { Crate , DefId } ;
@@ -130,11 +126,6 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
130126 Rc :: new ( ( * v. borrow ( ) ) . clone ( ) ) ) ;
131127 }
132128
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-
138129 // Populate the table of destructors. It might seem a bit strange to
139130 // do this here, but it's actually the most convenient place, since
140131 // the coherence tables contain the trait -> type mappings.
@@ -267,11 +258,6 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
267258 trait_def. record_impl ( self . crate_context . tcx , impl_def_id, impl_trait_ref) ;
268259 }
269260
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-
275261 // Converts an implementation in the AST to a vector of items.
276262 fn create_impl_from_item ( & self , item : & Item ) -> Vec < ImplOrTraitItemId > {
277263 match item. node {
@@ -313,66 +299,6 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
313299 }
314300 }
315301
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-
376302 //
377303 // Destructors
378304 //
@@ -395,7 +321,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
395321 }
396322 let method_def_id = items[ 0 ] ;
397323
398- let self_type = self . get_self_type_for_implementation ( impl_did) ;
324+ let self_type = ty :: lookup_item_type ( tcx , impl_did) ;
399325 match self_type. ty . sty {
400326 ty:: ty_enum( type_def_id, _) |
401327 ty:: ty_struct( type_def_id, _) |
@@ -451,7 +377,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
451377 return
452378 }
453379
454- let self_type = self . get_self_type_for_implementation ( impl_did) ;
380+ let self_type = ty :: lookup_item_type ( tcx , impl_did) ;
455381 debug ! ( "check_implementations_of_copy: self_type={} (bound)" ,
456382 self_type. repr( tcx) ) ;
457383
0 commit comments