17
17
18
18
use metadata:: csearch:: { each_path, get_impl_trait} ;
19
19
use metadata:: csearch;
20
- use metadata:: cstore:: { CStore , iter_crate_data} ;
20
+ use metadata:: cstore:: iter_crate_data;
21
21
use metadata:: decoder:: { dl_def, dl_field, dl_impl} ;
22
- use middle:: resolve:: { Impl , MethodInfo } ;
23
22
use middle:: ty:: { ProvidedMethodSource , get} ;
24
23
use middle:: ty:: { lookup_item_type, subst} ;
25
24
use middle:: ty:: { substs, t, ty_bool, ty_bot, ty_box, ty_enum, ty_err} ;
@@ -31,14 +30,15 @@ use middle::ty::{ty_opaque_closure_ptr, ty_unboxed_vec};
31
30
use middle:: ty:: { type_is_ty_var} ;
32
31
use middle:: subst:: Subst ;
33
32
use middle:: ty;
33
+ use middle:: ty:: { Impl , Method } ;
34
34
use middle:: typeck:: CrateCtxt ;
35
35
use middle:: typeck:: infer:: combine:: Combine ;
36
36
use middle:: typeck:: infer:: InferCtxt ;
37
37
use middle:: typeck:: infer:: { new_infer_ctxt, resolve_ivar, resolve_type} ;
38
38
use middle:: typeck:: infer;
39
39
use syntax:: ast:: { crate , def_id, def_struct, def_ty} ;
40
40
use syntax:: ast:: { item, item_enum, item_impl, item_mod, item_struct} ;
41
- use syntax:: ast:: { local_crate, method , trait_ref, ty_path} ;
41
+ use syntax:: ast:: { local_crate, trait_ref, ty_path} ;
42
42
use syntax:: ast;
43
43
use syntax:: ast_map:: node_item;
44
44
use syntax:: ast_map;
@@ -149,16 +149,6 @@ pub fn get_base_type_def_id(inference_context: @mut InferCtxt,
149
149
}
150
150
}
151
151
152
-
153
- pub fn method_to_MethodInfo ( ast_method : @method ) -> @MethodInfo {
154
- @MethodInfo {
155
- did : local_def ( ast_method. id ) ,
156
- n_tps : ast_method. generics . ty_params . len ( ) ,
157
- ident : ast_method. ident ,
158
- explicit_self : ast_method. explicit_self . node
159
- }
160
- }
161
-
162
152
pub fn CoherenceChecker ( crate_context : @mut CrateCtxt ) -> CoherenceChecker {
163
153
CoherenceChecker {
164
154
crate_context : crate_context,
@@ -291,7 +281,7 @@ impl CoherenceChecker {
291
281
pub fn instantiate_default_methods ( & self ,
292
282
impl_id : ast:: def_id ,
293
283
trait_ref : & ty:: TraitRef ,
294
- all_methods : & mut ~[ @MethodInfo ] ) {
284
+ all_methods : & mut ~[ @Method ] ) {
295
285
let tcx = self . crate_context . tcx ;
296
286
debug ! ( "instantiate_default_methods(impl_id=%?, trait_ref=%s)" ,
297
287
impl_id, trait_ref. repr( tcx) ) ;
@@ -316,6 +306,7 @@ impl CoherenceChecker {
316
306
* trait_method) ;
317
307
318
308
debug ! ( "new_method_ty=%s" , new_method_ty. repr( tcx) ) ;
309
+ all_methods. push( new_method_ty) ;
319
310
320
311
// construct the polytype for the method based on the method_ty
321
312
let new_generics = ty:: Generics {
@@ -344,14 +335,6 @@ impl CoherenceChecker {
344
335
345
336
self . crate_context. tcx. provided_method_sources. insert( new_did,
346
337
source) ;
347
-
348
- let method_info = @MethodInfo {
349
- did : new_did,
350
- n_tps : trait_method. generics. type_param_defs. len( ) ,
351
- ident : trait_method. ident,
352
- explicit_self : trait_method. explicit_self
353
- } ;
354
- all_methods. push( method_info) ;
355
338
}
356
339
}
357
340
@@ -563,7 +546,7 @@ impl CoherenceChecker {
563
546
// here for historical reasons
564
547
pub fn check_trait_methods_are_implemented (
565
548
& self ,
566
- all_methods : & mut ~[ @MethodInfo ] ,
549
+ all_methods : & mut ~[ @Method ] ,
567
550
trait_did : def_id ,
568
551
trait_ref_span : span ) {
569
552
@@ -628,11 +611,12 @@ impl CoherenceChecker {
628
611
629
612
// Converts an implementation in the AST to an Impl structure.
630
613
pub fn create_impl_from_item ( & self , item : @item) -> @Impl {
614
+ let tcx = self . crate_context . tcx ;
631
615
match item. node {
632
616
item_impl( _, ref trait_refs, _, ref ast_methods) => {
633
617
let mut methods = ~[ ] ;
634
618
for ast_methods. iter( ) . advance |ast_method| {
635
- methods. push( method_to_MethodInfo ( * ast_method) ) ;
619
+ methods. push( ty :: method ( tcx , local_def ( ast_method. id ) ) ) ;
636
620
}
637
621
638
622
for trait_refs. iter( ) . advance |trait_ref| {
@@ -682,12 +666,12 @@ impl CoherenceChecker {
682
666
683
667
pub fn add_external_impl ( & self ,
684
668
impls_seen : & mut HashSet < def_id > ,
685
- crate_store : @mut CStore ,
686
669
impl_def_id : def_id ) {
687
- let implementation = csearch:: get_impl ( crate_store, impl_def_id) ;
670
+ let tcx = self . crate_context . tcx ;
671
+ let implementation = csearch:: get_impl ( tcx, impl_def_id) ;
688
672
689
673
debug ! ( "coherence: adding impl from external crate: %s" ,
690
- ty:: item_path_str( self . crate_context . tcx, implementation. did) ) ;
674
+ ty:: item_path_str( tcx, implementation. did) ) ;
691
675
692
676
// Make sure we don't visit the same implementation multiple times.
693
677
if !impls_seen. insert ( implementation. did ) {
@@ -696,9 +680,8 @@ impl CoherenceChecker {
696
680
}
697
681
// Good. Continue.
698
682
699
- let self_type = lookup_item_type ( self . crate_context . tcx ,
700
- implementation. did ) ;
701
- let associated_traits = get_impl_trait ( self . crate_context . tcx ,
683
+ let self_type = lookup_item_type ( tcx, implementation. did ) ;
684
+ let associated_traits = get_impl_trait ( tcx,
702
685
implementation. did ) ;
703
686
704
687
// Do a sanity check to make sure that inherent methods have base
@@ -708,12 +691,10 @@ impl CoherenceChecker {
708
691
dummy_sp ( ) ,
709
692
self_type. ty ) {
710
693
None => {
711
- let session = self . crate_context . tcx . sess ;
712
- session. bug ( fmt ! ( "no base type for external impl with no \
694
+ tcx. sess . bug ( fmt ! ( "no base type for external impl with no \
713
695
trait: %s (type %s)!",
714
- session. str_of( implementation. ident) ,
715
- ty_to_str( self . crate_context. tcx,
716
- self_type. ty) ) ) ;
696
+ tcx. sess. str_of( implementation. ident) ,
697
+ ty_to_str( tcx, self_type. ty) ) ) ;
717
698
}
718
699
Some ( _) => { } // Nothing to do.
719
700
}
@@ -756,8 +737,7 @@ impl CoherenceChecker {
756
737
}
757
738
}
758
739
759
- self . crate_context . tcx . impls . insert ( implementation. did ,
760
- implementation) ;
740
+ tcx. impls . insert ( implementation. did , implementation) ;
761
741
}
762
742
763
743
// Adds implementations and traits from external crates to the coherence
@@ -770,9 +750,7 @@ impl CoherenceChecker {
770
750
for each_path( crate_store, crate_number) |_, def_like, _| {
771
751
match def_like {
772
752
dl_impl( def_id) => {
773
- self . add_external_impl ( & mut impls_seen,
774
- crate_store,
775
- def_id)
753
+ self . add_external_impl ( & mut impls_seen, def_id)
776
754
}
777
755
dl_def( _) | dl_field => loop , // Skip this.
778
756
}
@@ -802,7 +780,7 @@ impl CoherenceChecker {
802
780
// We'll error out later. For now, just don't ICE.
803
781
loop ;
804
782
}
805
- let method_def_id = impl_info. methods [ 0 ] . did ;
783
+ let method_def_id = impl_info. methods [ 0 ] . def_id ;
806
784
807
785
let self_type = self . get_self_type_for_implementation ( * impl_info) ;
808
786
match ty:: get ( self_type. ty ) . sty {
0 commit comments