@@ -207,7 +207,6 @@ fn ast_path_substs_for_ty<'tcx,AC,RS>(
207
207
decl_def_id : ast:: DefId ,
208
208
decl_generics : & ty:: Generics ,
209
209
self_ty : Option < ty:: t > ,
210
- associated_ty : Option < ty:: t > ,
211
210
path : & ast:: Path )
212
211
-> Substs
213
212
where AC : AstConv < ' tcx > , RS : RegionScope
@@ -243,7 +242,7 @@ fn ast_path_substs_for_ty<'tcx,AC,RS>(
243
242
} ;
244
243
245
244
create_substs_for_ast_path ( this, rscope, path. span , decl_def_id,
246
- decl_generics, self_ty, types, regions, associated_ty )
245
+ decl_generics, self_ty, types, regions)
247
246
}
248
247
249
248
fn create_substs_for_ast_path < ' tcx , AC , RS > (
@@ -254,8 +253,7 @@ fn create_substs_for_ast_path<'tcx,AC,RS>(
254
253
decl_generics : & ty:: Generics ,
255
254
self_ty : Option < ty:: t > ,
256
255
types : Vec < ty:: t > ,
257
- regions : Vec < ty:: Region > ,
258
- associated_ty : Option < ty:: t > )
256
+ regions : Vec < ty:: Region > )
259
257
-> Substs
260
258
where AC : AstConv < ' tcx > , RS : RegionScope
261
259
{
@@ -366,9 +364,9 @@ fn create_substs_for_ast_path<'tcx,AC,RS>(
366
364
substs. types . push (
367
365
AssocSpace ,
368
366
this. associated_type_binding ( span,
369
- associated_ty ,
367
+ self_ty ,
370
368
decl_def_id,
371
- param. def_id ) )
369
+ param. def_id ) ) ;
372
370
}
373
371
374
372
return substs;
@@ -417,19 +415,17 @@ pub fn instantiate_poly_trait_ref<'tcx,AC,RS>(
417
415
this : & AC ,
418
416
rscope : & RS ,
419
417
ast_trait_ref : & ast:: PolyTraitRef ,
420
- self_ty : Option < ty:: t > ,
421
- associated_type : Option < ty:: t > )
418
+ self_ty : Option < ty:: t > )
422
419
-> Rc < ty:: TraitRef >
423
420
where AC : AstConv < ' tcx > , RS : RegionScope
424
421
{
425
- instantiate_trait_ref ( this, rscope, & ast_trait_ref. trait_ref , self_ty, associated_type )
422
+ instantiate_trait_ref ( this, rscope, & ast_trait_ref. trait_ref , self_ty)
426
423
}
427
424
428
425
pub fn instantiate_trait_ref < ' tcx , AC , RS > ( this : & AC ,
429
426
rscope : & RS ,
430
427
ast_trait_ref : & ast:: TraitRef ,
431
- self_ty : Option < ty:: t > ,
432
- associated_type : Option < ty:: t > )
428
+ self_ty : Option < ty:: t > )
433
429
-> Rc < ty:: TraitRef >
434
430
where AC : AstConv < ' tcx > ,
435
431
RS : RegionScope
@@ -444,8 +440,8 @@ pub fn instantiate_trait_ref<'tcx,AC,RS>(this: &AC,
444
440
ast_trait_ref. path . span ,
445
441
ast_trait_ref. ref_id ) {
446
442
def:: DefTrait ( trait_def_id) => {
447
- let trait_ref = Rc :: new ( ast_path_to_trait_ref ( this, rscope, trait_def_id, self_ty ,
448
- associated_type , & ast_trait_ref. path ) ) ;
443
+ let trait_ref = Rc :: new ( ast_path_to_trait_ref ( this, rscope, trait_def_id,
444
+ self_ty , & ast_trait_ref. path ) ) ;
449
445
this. tcx ( ) . trait_refs . borrow_mut ( ) . insert ( ast_trait_ref. ref_id ,
450
446
trait_ref. clone ( ) ) ;
451
447
trait_ref
@@ -463,7 +459,6 @@ fn ast_path_to_trait_ref<'tcx,AC,RS>(
463
459
rscope : & RS ,
464
460
trait_def_id : ast:: DefId ,
465
461
self_ty : Option < ty:: t > ,
466
- associated_type : Option < ty:: t > ,
467
462
path : & ast:: Path )
468
463
-> ty:: TraitRef
469
464
where AC : AstConv < ' tcx > , RS : RegionScope
@@ -493,8 +488,7 @@ fn ast_path_to_trait_ref<'tcx,AC,RS>(
493
488
& trait_def. generics ,
494
489
self_ty,
495
490
types,
496
- regions,
497
- associated_type) ;
491
+ regions) ;
498
492
499
493
ty:: TraitRef :: new ( trait_def_id, substs)
500
494
}
@@ -517,7 +511,6 @@ pub fn ast_path_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
517
511
did,
518
512
& generics,
519
513
None ,
520
- None ,
521
514
path) ;
522
515
let ty = decl_ty. subst ( tcx, & substs) ;
523
516
TypeAndSubsts { substs : substs, ty : ty }
@@ -558,7 +551,7 @@ pub fn ast_path_to_ty_relaxed<'tcx,AC,RS>(
558
551
Substs :: new ( VecPerParamSpace :: params_from_type ( type_params) ,
559
552
VecPerParamSpace :: params_from_type ( region_params) )
560
553
} else {
561
- ast_path_substs_for_ty ( this, rscope, did, & generics, None , None , path)
554
+ ast_path_substs_for_ty ( this, rscope, did, & generics, None , path)
562
555
} ;
563
556
564
557
let ty = decl_ty. subst ( tcx, & substs) ;
@@ -725,7 +718,6 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
725
718
rscope,
726
719
trait_def_id,
727
720
None ,
728
- None ,
729
721
path) ;
730
722
let empty_vec = [ ] ;
731
723
let bounds = match * opt_bounds { None => empty_vec. as_slice ( ) ,
@@ -749,61 +741,37 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
749
741
constr ( ast_ty_to_ty ( this, rscope, a_seq_ty) )
750
742
}
751
743
752
- fn associated_ty_to_ty < ' tcx , AC , RS > ( this : & AC ,
753
- rscope : & RS ,
754
- trait_path : & ast:: Path ,
755
- for_ast_type : & ast:: Ty ,
756
- trait_type_id : ast:: DefId ,
757
- span : Span )
758
- -> ty:: t
759
- where AC : AstConv < ' tcx > , RS : RegionScope
744
+ fn qpath_to_ty < ' tcx , AC , RS > ( this : & AC ,
745
+ rscope : & RS ,
746
+ ast_ty : & ast:: Ty , // the TyQPath
747
+ qpath : & ast:: QPath )
748
+ -> ty:: t
749
+ where AC : AstConv < ' tcx > , RS : RegionScope
760
750
{
761
- debug ! ( "associated_ty_to_ty(trait_path={}, for_ast_type={}, trait_type_id={})" ,
762
- trait_path. repr( this. tcx( ) ) ,
763
- for_ast_type. repr( this. tcx( ) ) ,
764
- trait_type_id. repr( this. tcx( ) ) ) ;
765
-
766
- // Find the trait that this associated type belongs to.
767
- let trait_did = match ty:: impl_or_trait_item ( this. tcx ( ) ,
768
- trait_type_id) . container ( ) {
769
- ty:: ImplContainer ( _) => {
770
- this. tcx ( ) . sess . span_bug ( span,
771
- "associated_ty_to_ty(): impl associated \
772
- types shouldn't go through this \
773
- function")
774
- }
775
- ty:: TraitContainer ( trait_id) => trait_id,
776
- } ;
751
+ debug ! ( "qpath_to_ty(ast_ty={})" ,
752
+ ast_ty. repr( this. tcx( ) ) ) ;
777
753
778
- let for_type = ast_ty_to_ty ( this, rscope, for_ast_type) ;
779
- if !this. associated_types_of_trait_are_valid ( for_type, trait_did) {
780
- this. tcx ( ) . sess . span_err ( span,
781
- "this associated type is not \
782
- allowed in this context") ;
783
- return ty:: mk_err ( )
784
- }
754
+ let self_type = ast_ty_to_ty ( this, rscope, & * qpath. self_type ) ;
755
+
756
+ debug ! ( "qpath_to_ty: self_type={}" , self_type. repr( this. tcx( ) ) ) ;
785
757
786
- let trait_ref = ast_path_to_trait_ref ( this,
758
+ let trait_ref = instantiate_trait_ref ( this,
787
759
rscope,
788
- trait_did,
789
- None ,
790
- Some ( for_type) ,
791
- trait_path) ;
792
-
793
- debug ! ( "associated_ty_to_ty(trait_ref={})" ,
794
- trait_ref. repr( this. tcx( ) ) ) ;
795
-
796
- let trait_def = this. get_trait_def ( trait_did) ;
797
- for type_parameter in trait_def. generics . types . iter ( ) {
798
- if type_parameter. def_id == trait_type_id {
799
- debug ! ( "associated_ty_to_ty(type_parameter={} substs={})" ,
800
- type_parameter. repr( this. tcx( ) ) ,
801
- trait_ref. substs. repr( this. tcx( ) ) ) ;
802
- return * trait_ref. substs . types . get ( type_parameter. space ,
803
- type_parameter. index )
760
+ & * qpath. trait_ref ,
761
+ Some ( self_type) ) ;
762
+
763
+ debug ! ( "qpath_to_ty: trait_ref={}" , trait_ref. repr( this. tcx( ) ) ) ;
764
+
765
+ let trait_def = this. get_trait_def ( trait_ref. def_id ) ;
766
+
767
+ for ty_param_def in trait_def. generics . types . get_slice ( AssocSpace ) . iter ( ) {
768
+ if ty_param_def. name == qpath. item_name . name {
769
+ debug ! ( "qpath_to_ty: corresponding ty_param_def={}" , ty_param_def) ;
770
+ return trait_ref. substs . type_for_def ( ty_param_def) ;
804
771
}
805
772
}
806
- this. tcx ( ) . sess . span_bug ( span,
773
+
774
+ this. tcx ( ) . sess . span_bug ( ast_ty. span ,
807
775
"this associated type didn't get added \
808
776
as a parameter for some reason")
809
777
}
@@ -930,7 +898,6 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
930
898
rscope,
931
899
trait_def_id,
932
900
None ,
933
- None ,
934
901
path) ;
935
902
let empty_bounds: & [ ast:: TyParamBound ] = & [ ] ;
936
903
let ast_bounds = match * bounds {
@@ -995,26 +962,7 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
995
962
}
996
963
}
997
964
ast:: TyQPath ( ref qpath) => {
998
- match tcx. def_map . borrow ( ) . get ( & ast_ty. id ) {
999
- None => {
1000
- tcx. sess . span_bug ( ast_ty. span ,
1001
- "unbound qualified path" )
1002
- }
1003
- Some ( & def:: DefAssociatedTy ( trait_type_id) ) => {
1004
- associated_ty_to_ty ( this,
1005
- rscope,
1006
- & qpath. trait_name ,
1007
- & * qpath. for_type ,
1008
- trait_type_id,
1009
- ast_ty. span )
1010
- }
1011
- Some ( _) => {
1012
- tcx. sess . span_err ( ast_ty. span ,
1013
- "this qualified path does not name \
1014
- an associated type") ;
1015
- ty:: mk_err ( )
1016
- }
1017
- }
965
+ qpath_to_ty ( this, rscope, ast_ty, & * * qpath)
1018
966
}
1019
967
ast:: TyFixedLengthVec ( ref ty, ref e) => {
1020
968
match const_eval:: eval_const_expr_partial ( tcx, & * * e) {
@@ -1410,7 +1358,7 @@ fn conv_ty_poly_trait_ref<'tcx, AC, RS>(
1410
1358
1411
1359
let main_trait_bound = match partitioned_bounds. trait_bounds . remove ( 0 ) {
1412
1360
Some ( trait_bound) => {
1413
- Some ( instantiate_poly_trait_ref ( this, rscope, trait_bound, None , None ) )
1361
+ Some ( instantiate_poly_trait_ref ( this, rscope, trait_bound, None ) )
1414
1362
}
1415
1363
None => {
1416
1364
this. tcx ( ) . sess . span_err (
0 commit comments