@@ -47,7 +47,6 @@ use util::common::{indenter, pluralize};
47
47
use util:: ppaux;
48
48
49
49
use core:: dvec;
50
- use core:: option;
51
50
use core:: vec;
52
51
use syntax:: ast:: { RegionTyParamBound , TraitTyParamBound } ;
53
52
use syntax:: ast;
@@ -108,24 +107,24 @@ pub fn collect_item_types(ccx: @mut CrateCtxt, crate: @ast::crate) {
108
107
visit:: visit_crate (
109
108
* crate , ( ) ,
110
109
visit:: mk_simple_visitor ( @visit:: SimpleVisitor {
111
- visit_item : |a|convert ( ccx, a) ,
110
+ visit_item : |a| convert ( ccx, a) ,
112
111
visit_foreign_item : |a|convert_foreign ( ccx, a) ,
113
112
.. * visit:: default_simple_visitor ( )
114
113
} ) ) ;
115
114
}
116
115
117
- pub impl @mut CrateCtxt {
118
- fn to_ty<RS : region_scope + Copy + Durable >( rs: RS , ast_ty : @ast:: Ty )
119
- -> ty:: t {
116
+ impl CrateCtxt {
117
+ fn to_ty < RS : region_scope + Copy + Durable > (
118
+ & self , rs : & RS , ast_ty : @ast:: Ty ) -> ty:: t
119
+ {
120
120
ast_ty_to_ty ( self , rs, ast_ty)
121
121
}
122
122
}
123
123
124
124
impl AstConv for CrateCtxt {
125
- fn tcx ( @mut self ) -> ty:: ctxt { self . tcx }
126
- fn ccx ( @mut self ) -> @mut CrateCtxt { self }
125
+ fn tcx ( & self ) -> ty:: ctxt { self . tcx }
127
126
128
- fn get_item_ty ( @ mut self , id : ast:: def_id ) -> ty:: ty_param_bounds_and_ty {
127
+ fn get_item_ty ( & self , id : ast:: def_id ) -> ty:: ty_param_bounds_and_ty {
129
128
if id. crate != ast:: local_crate {
130
129
csearch:: get_type ( self . tcx , id)
131
130
} else {
@@ -144,13 +143,13 @@ impl AstConv for CrateCtxt {
144
143
}
145
144
}
146
145
147
- fn ty_infer ( @ mut self , span : span ) -> ty:: t {
146
+ fn ty_infer ( & self , span : span ) -> ty:: t {
148
147
self . tcx . sess . span_bug ( span,
149
148
~"found `ty_infer` in unexpected place") ;
150
149
}
151
150
}
152
151
153
- pub fn get_enum_variant_types ( ccx : @ mut CrateCtxt ,
152
+ pub fn get_enum_variant_types ( ccx : & CrateCtxt ,
154
153
enum_ty : ty:: t ,
155
154
variants : & [ ast:: variant ] ,
156
155
generics : & ast:: Generics ,
@@ -165,7 +164,7 @@ pub fn get_enum_variant_types(ccx: @mut CrateCtxt,
165
164
match variant. node . kind {
166
165
ast:: tuple_variant_kind( ref args) if args. len ( ) > 0 => {
167
166
let rs = type_rscope ( rp) ;
168
- let input_tys = args. map ( |va| ccx. to_ty ( rs, va. ty ) ) ;
167
+ let input_tys = args. map ( |va| ccx. to_ty ( & rs, va. ty ) ) ;
169
168
result_ty = Some ( ty:: mk_ctor_fn ( tcx, input_tys, enum_ty) ) ;
170
169
}
171
170
@@ -217,17 +216,17 @@ pub fn get_enum_variant_types(ccx: @mut CrateCtxt,
217
216
}
218
217
}
219
218
220
- pub fn ensure_trait_methods ( ccx : @ mut CrateCtxt ,
219
+ pub fn ensure_trait_methods ( ccx : & CrateCtxt ,
221
220
id : ast:: node_id ,
222
221
trait_ty : ty:: t ) {
223
- fn store_methods < T > ( ccx : @ mut CrateCtxt ,
222
+ fn store_methods < T > ( ccx : & CrateCtxt ,
224
223
id : ast:: node_id ,
225
224
stuff : ~[ T ] ,
226
225
f : & fn ( v : & T ) -> ty:: method ) {
227
226
ty:: store_trait_methods ( ccx. tcx , id, @vec:: map ( stuff, f) ) ;
228
227
}
229
228
230
- fn make_static_method_ty ( ccx : @ mut CrateCtxt ,
229
+ fn make_static_method_ty ( ccx : & CrateCtxt ,
231
230
am : & ast:: ty_method ,
232
231
rp : Option < ty:: region_variance > ,
233
232
m : ty:: method ,
@@ -308,7 +307,7 @@ pub fn ensure_trait_methods(ccx: @mut CrateCtxt,
308
307
}
309
308
}
310
309
311
- pub fn ensure_supertraits ( ccx : @ mut CrateCtxt ,
310
+ pub fn ensure_supertraits ( ccx : & CrateCtxt ,
312
311
id : ast:: node_id ,
313
312
sp : codemap:: span ,
314
313
rp : Option < ty:: region_variance > ,
@@ -492,7 +491,7 @@ pub fn compare_impl_method(tcx: ty::ctxt,
492
491
}
493
492
}
494
493
495
- pub fn check_methods_against_trait(ccx: @mut CrateCtxt,
494
+ pub fn check_methods_against_trait(ccx: & CrateCtxt,
496
495
generics: &ast::Generics,
497
496
rp: Option<ty::region_variance>,
498
497
selfty: ty::t,
@@ -544,11 +543,11 @@ pub fn check_methods_against_trait(ccx: @mut CrateCtxt,
544
543
}
545
544
} // fn
546
545
547
- pub fn convert_field ( ccx : @ mut CrateCtxt ,
546
+ pub fn convert_field ( ccx : & CrateCtxt ,
548
547
rp : Option < ty:: region_variance > ,
549
548
bounds : @~[ ty:: param_bounds ] ,
550
549
v : @ast:: struct_field ) {
551
- let tt = ccx. to_ty ( type_rscope ( rp) , v. node . ty ) ;
550
+ let tt = ccx. to_ty ( & type_rscope ( rp) , v. node . ty ) ;
552
551
write_ty_to_tcx ( ccx. tcx , v. node . id , tt) ;
553
552
/* add the field to the tcache */
554
553
ccx. tcx . tcache . insert ( local_def ( v. node . id ) ,
@@ -566,8 +565,8 @@ pub struct ConvertedMethod {
566
565
body_id : ast:: node_id
567
566
}
568
567
569
- pub fn convert_methods ( ccx : @ mut CrateCtxt ,
570
- ms : ~ [ @ast:: method ] ,
568
+ pub fn convert_methods ( ccx : & CrateCtxt ,
569
+ ms : & [ @ast:: method ] ,
571
570
rp : Option < ty:: region_variance > ,
572
571
rcvr_bounds : @~[ ty:: param_bounds ] )
573
572
-> ~[ ConvertedMethod ] {
@@ -593,7 +592,7 @@ pub fn convert_methods(ccx: @mut CrateCtxt,
593
592
}
594
593
}
595
594
596
- pub fn ensure_no_ty_param_bounds ( ccx : @ mut CrateCtxt ,
595
+ pub fn ensure_no_ty_param_bounds ( ccx : & CrateCtxt ,
597
596
span : span ,
598
597
generics : & ast:: Generics ,
599
598
thing : & static /str ) {
@@ -607,7 +606,7 @@ pub fn ensure_no_ty_param_bounds(ccx: @mut CrateCtxt,
607
606
}
608
607
}
609
608
610
- pub fn convert ( ccx : @ mut CrateCtxt , it : @ast:: item ) {
609
+ pub fn convert ( ccx : & CrateCtxt , it : @ast:: item ) {
611
610
let tcx = ccx. tcx ;
612
611
let rp = tcx. region_paramd_items . find ( & it. id ) ;
613
612
debug ! ( "convert: item %s with id %d rp %?" ,
@@ -627,7 +626,7 @@ pub fn convert(ccx: @mut CrateCtxt, it: @ast::item) {
627
626
}
628
627
ast:: item_impl( ref generics, trait_ref, selfty, ref ms) => {
629
628
let i_bounds = ty_param_bounds ( ccx, generics) ;
630
- let selfty = ccx. to_ty ( type_rscope ( rp) , selfty) ;
629
+ let selfty = ccx. to_ty ( & type_rscope ( rp) , selfty) ;
631
630
write_ty_to_tcx ( tcx, it. id , selfty) ;
632
631
tcx. tcache . insert ( local_def ( it. id ) ,
633
632
ty_param_bounds_and_ty {
@@ -636,7 +635,7 @@ pub fn convert(ccx: @mut CrateCtxt, it: @ast::item) {
636
635
ty : selfty} ) ;
637
636
638
637
// XXX: Bad copy of `ms` below.
639
- let cms = convert_methods ( ccx, /*bad*/ copy * ms, rp, i_bounds) ;
638
+ let cms = convert_methods ( ccx, * ms, rp, i_bounds) ;
640
639
for trait_ref. each |t| {
641
640
check_methods_against_trait( ccx, generics, rp, selfty,
642
641
* t, /*bad*/ copy cms) ;
@@ -680,7 +679,7 @@ pub fn convert(ccx: @mut CrateCtxt, it: @ast::item) {
680
679
}
681
680
}
682
681
683
- pub fn convert_struct ( ccx : @ mut CrateCtxt ,
682
+ pub fn convert_struct ( ccx : & CrateCtxt ,
684
683
rp : Option < ty:: region_variance > ,
685
684
struct_def : @ast:: struct_def ,
686
685
generics : & ast:: Generics ,
@@ -693,7 +692,7 @@ pub fn convert_struct(ccx: @mut CrateCtxt,
693
692
let t_dtor = ty:: mk_bare_fn (
694
693
tcx,
695
694
astconv:: ty_of_bare_fn (
696
- ccx, type_rscope ( rp) ,
695
+ ccx, & type_rscope ( rp) ,
697
696
ast:: impure_fn, ast:: RustAbi ,
698
697
& ast_util:: dtor_dec ( ) ) ) ;
699
698
write_ty_to_tcx ( tcx, dtor. node . id , t_dtor) ;
@@ -738,7 +737,7 @@ pub fn convert_struct(ccx: @mut CrateCtxt,
738
737
}
739
738
}
740
739
741
- pub fn convert_foreign ( ccx : @ mut CrateCtxt , i : @ast:: foreign_item ) {
740
+ pub fn convert_foreign ( ccx : & CrateCtxt , i : @ast:: foreign_item ) {
742
741
// As above, this call populates the type table with the converted
743
742
// type of the foreign item. We simply write it into the node type
744
743
// table.
@@ -747,28 +746,38 @@ pub fn convert_foreign(ccx: @mut CrateCtxt, i: @ast::foreign_item) {
747
746
ccx. tcx . tcache . insert ( local_def ( i. id ) , tpt) ;
748
747
}
749
748
750
- pub fn ty_of_method ( ccx : @ mut CrateCtxt ,
749
+ pub fn ty_of_method ( ccx : & CrateCtxt ,
751
750
m : @ast:: method ,
752
751
rp : Option < ty:: region_variance > ) -> ty:: method {
752
+ let rscope = MethodRscope {
753
+ self_ty : m. self_ty . node ,
754
+ region_parameterization : rp
755
+ } ;
756
+
753
757
ty:: method {
754
758
ident : m. ident ,
755
759
tps : ty_param_bounds ( ccx, & m. generics ) ,
756
- fty : astconv:: ty_of_bare_fn ( ccx, type_rscope ( rp ) , m. purity ,
760
+ fty : astconv:: ty_of_bare_fn ( ccx, & rscope , m. purity ,
757
761
ast:: RustAbi , & m. decl ) ,
758
762
self_ty : m. self_ty . node ,
759
763
vis : m. vis ,
760
764
def_id : local_def ( m. id )
761
765
}
762
766
}
763
767
764
- pub fn ty_of_ty_method ( self : @ mut CrateCtxt ,
768
+ pub fn ty_of_ty_method ( self : & CrateCtxt ,
765
769
m : & ast:: ty_method ,
766
770
rp : Option < ty:: region_variance > ,
767
771
id : ast:: def_id ) -> ty:: method {
772
+ let rscope = MethodRscope {
773
+ self_ty : m. self_ty . node ,
774
+ region_parameterization : rp
775
+ } ;
776
+
768
777
ty:: method {
769
778
ident : m. ident ,
770
779
tps : ty_param_bounds ( self , & m. generics ) ,
771
- fty : astconv:: ty_of_bare_fn ( self , type_rscope ( rp ) , m. purity ,
780
+ fty : astconv:: ty_of_bare_fn ( self , & rscope , m. purity ,
772
781
ast:: RustAbi , & m. decl ) ,
773
782
// assume public, because this is only invoked on trait methods
774
783
self_ty : m. self_ty . node ,
@@ -782,7 +791,7 @@ pub fn ty_of_ty_method(self: @mut CrateCtxt,
782
791
it's bound to a valid trait type. Returns the def_id for the defining
783
792
trait. Fails if the type is a type other than an trait type.
784
793
*/
785
- pub fn instantiate_trait_ref ( ccx : @ mut CrateCtxt , t : @ast:: trait_ref ,
794
+ pub fn instantiate_trait_ref ( ccx : & CrateCtxt , t : @ast:: trait_ref ,
786
795
rp : Option < ty:: region_variance > )
787
796
-> ( ast:: def_id , ty_param_substs_and_ty ) {
788
797
@@ -793,7 +802,7 @@ pub fn instantiate_trait_ref(ccx: @mut CrateCtxt, t: @ast::trait_ref,
793
802
794
803
match lookup_def_tcx ( ccx. tcx , t. path . span , t. ref_id ) {
795
804
ast:: def_ty( t_id) => {
796
- let tpt = astconv:: ast_path_to_ty ( ccx, rscope, t_id, t. path ,
805
+ let tpt = astconv:: ast_path_to_ty ( ccx, & rscope, t_id, t. path ,
797
806
t. ref_id ) ;
798
807
match ty:: get ( tpt. ty ) . sty {
799
808
ty:: ty_trait( * ) => {
@@ -806,7 +815,7 @@ pub fn instantiate_trait_ref(ccx: @mut CrateCtxt, t: @ast::trait_ref,
806
815
}
807
816
}
808
817
809
- pub fn ty_of_item ( ccx : @ mut CrateCtxt , it : @ast:: item )
818
+ pub fn ty_of_item ( ccx : & CrateCtxt , it : @ast:: item )
810
819
-> ty:: ty_param_bounds_and_ty {
811
820
let def_id = local_def ( it. id ) ;
812
821
let tcx = ccx. tcx ;
@@ -817,14 +826,14 @@ pub fn ty_of_item(ccx: @mut CrateCtxt, it: @ast::item)
817
826
let rp = tcx. region_paramd_items . find ( & it. id ) ;
818
827
match it. node {
819
828
ast:: item_const( t, _) => {
820
- let typ = ccx. to_ty ( empty_rscope, t) ;
829
+ let typ = ccx. to_ty ( & empty_rscope, t) ;
821
830
let tpt = no_params ( typ) ;
822
831
tcx. tcache . insert ( local_def ( it. id ) , tpt) ;
823
832
return tpt;
824
833
}
825
834
ast:: item_fn( ref decl, purity, ref generics, _) => {
826
835
let bounds = ty_param_bounds ( ccx, generics) ;
827
- let tofd = astconv:: ty_of_bare_fn ( ccx, empty_rscope, purity,
836
+ let tofd = astconv:: ty_of_bare_fn ( ccx, & empty_rscope, purity,
828
837
ast:: RustAbi , decl) ;
829
838
let tpt = ty_param_bounds_and_ty {
830
839
bounds : bounds,
@@ -847,7 +856,7 @@ pub fn ty_of_item(ccx: @mut CrateCtxt, it: @ast::item)
847
856
let rp = tcx. region_paramd_items . find ( & it. id ) ;
848
857
let tpt = {
849
858
let ty = {
850
- let t0 = ccx. to_ty ( type_rscope ( rp) , t) ;
859
+ let t0 = ccx. to_ty ( & type_rscope ( rp) , t) ;
851
860
// Do not associate a def id with a named, parameterized type
852
861
// like "foo<X>". This is because otherwise ty_to_str will
853
862
// print the name as merely "foo", as it has no way to
@@ -906,23 +915,21 @@ pub fn ty_of_item(ccx: @mut CrateCtxt, it: @ast::item)
906
915
}
907
916
}
908
917
909
- pub fn ty_of_foreign_item(ccx: @mut CrateCtxt, it: @ast::foreign_item)
918
+ pub fn ty_of_foreign_item(ccx: & CrateCtxt, it: @ast::foreign_item)
910
919
-> ty::ty_param_bounds_and_ty {
911
- match /*bad*/copy it.node {
920
+ match it.node {
912
921
ast::foreign_item_fn(ref fn_decl, _, ref generics) => {
913
- ty_of_foreign_fn_decl(
914
- ccx,
915
- fn_decl,
916
- local_def(it.id),
917
- generics
918
- )
922
+ ty_of_foreign_fn_decl(ccx,
923
+ fn_decl,
924
+ local_def(it.id),
925
+ generics)
919
926
}
920
927
ast::foreign_item_const(t) => {
921
- let rb = in_binding_rscope(empty_rscope);
928
+ let rb = in_binding_rscope(& empty_rscope);
922
929
ty::ty_param_bounds_and_ty {
923
930
bounds: @~[],
924
931
region_param: None,
925
- ty: ast_ty_to_ty(ccx, rb, t)
932
+ ty: ast_ty_to_ty(ccx, & rb, t)
926
933
}
927
934
}
928
935
}
@@ -932,14 +939,14 @@ pub fn ty_of_foreign_item(ccx: @mut CrateCtxt, it: @ast::foreign_item)
932
939
// of a newtyped Ty or a region) to ty's notion of ty param bounds, which can
933
940
// either be user-defined traits, or one of the four built-in traits (formerly
934
941
// known as kinds): Const, Copy, Durable, and Send.
935
- pub fn compute_bounds(ccx: @mut CrateCtxt,
942
+ pub fn compute_bounds(ccx: & CrateCtxt,
936
943
ast_bounds: @OptVec<ast::TyParamBound>)
937
944
-> ty::param_bounds {
938
945
@ast_bounds.flat_map_to_vec(|b| {
939
946
match b {
940
947
&TraitTyParamBound(b) => {
941
948
let li = &ccx.tcx.lang_items;
942
- let ity = ast_ty_to_ty(ccx, empty_rscope, b);
949
+ let ity = ast_ty_to_ty(ccx, & empty_rscope, b);
943
950
match ty::get(ity).sty {
944
951
ty::ty_trait(did, _, _) => {
945
952
if did == li.owned_trait() {
@@ -968,7 +975,7 @@ pub fn compute_bounds(ccx: @mut CrateCtxt,
968
975
} )
969
976
}
970
977
971
- pub fn ty_param_bounds ( ccx : @ mut CrateCtxt ,
978
+ pub fn ty_param_bounds ( ccx : & CrateCtxt ,
972
979
generics : & ast:: Generics )
973
980
-> @~[ ty:: param_bounds ] {
974
981
@do generics. ty_params . map_to_vec |param| {
@@ -983,15 +990,15 @@ pub fn ty_param_bounds(ccx: @mut CrateCtxt,
983
990
}
984
991
}
985
992
986
- pub fn ty_of_foreign_fn_decl ( ccx : @ mut CrateCtxt ,
993
+ pub fn ty_of_foreign_fn_decl ( ccx : & CrateCtxt ,
987
994
decl : & ast:: fn_decl ,
988
995
def_id : ast:: def_id ,
989
996
generics : & ast:: Generics )
990
997
-> ty:: ty_param_bounds_and_ty {
991
998
let bounds = ty_param_bounds ( ccx, generics) ;
992
- let rb = in_binding_rscope ( empty_rscope) ;
993
- let input_tys = decl. inputs . map ( |a| ty_of_arg ( ccx, rb, * a, None ) ) ;
994
- let output_ty = ast_ty_to_ty ( ccx, rb, decl. output ) ;
999
+ let rb = in_binding_rscope ( & empty_rscope) ;
1000
+ let input_tys = decl. inputs . map ( |a| ty_of_arg ( ccx, & rb, * a, None ) ) ;
1001
+ let output_ty = ast_ty_to_ty ( ccx, & rb, decl. output ) ;
995
1002
996
1003
let t_fn = ty:: mk_bare_fn (
997
1004
ccx. tcx ,
@@ -1009,7 +1016,7 @@ pub fn ty_of_foreign_fn_decl(ccx: @mut CrateCtxt,
1009
1016
return tpt;
1010
1017
}
1011
1018
1012
- pub fn mk_generics ( ccx : @ mut CrateCtxt , generics : & ast:: Generics )
1019
+ pub fn mk_generics ( ccx : & CrateCtxt , generics : & ast:: Generics )
1013
1020
-> ( @~[ ty:: param_bounds ] , ~[ ty:: t ] )
1014
1021
{
1015
1022
let mut i = 0 u;
@@ -1022,7 +1029,7 @@ pub fn mk_generics(ccx: @mut CrateCtxt, generics: &ast::Generics)
1022
1029
} ) )
1023
1030
}
1024
1031
1025
- pub fn mk_substs ( ccx : @ mut CrateCtxt ,
1032
+ pub fn mk_substs ( ccx : & CrateCtxt ,
1026
1033
generics : & ast:: Generics ,
1027
1034
rp : Option < ty:: region_variance > )
1028
1035
-> ( @~[ ty:: param_bounds ] , ty:: substs )
5 commit comments
bors commentedon Mar 5, 2013
saw approval from nikomatsakis
at nikomatsakis@cbfd88a
bors commentedon Mar 5, 2013
merging nikomatsakis/rust/issue-5224 = cbfd88a into auto
bors commentedon Mar 5, 2013
nikomatsakis/rust/issue-5224 = cbfd88a merged ok, testing candidate = 9ec7f3f
bors commentedon Mar 5, 2013
all tests pass:
http://buildbot.rust-lang.org/builders/auto-linux/builds/373
http://buildbot.rust-lang.org/builders/auto-win/builds/368
http://buildbot.rust-lang.org/builders/auto-mac/builds/380
bors commentedon Mar 5, 2013
fast-forwarding incoming to auto = 9ec7f3f