@@ -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 < ' tcx > ,
209
209
self_ty : Option < Ty < ' tcx > > ,
210
- associated_ty : Option < Ty < ' tcx > > ,
211
210
path : & ast:: Path )
212
211
-> Substs < ' tcx >
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 < ' tcx > ,
255
254
self_ty : Option < Ty < ' tcx > > ,
256
255
types : Vec < Ty < ' tcx > > ,
257
- regions : Vec < ty:: Region > ,
258
- associated_ty : Option < Ty < ' tcx > > )
256
+ regions : Vec < ty:: Region > )
259
257
-> Substs < ' tcx >
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 < ' tcx > > ,
421
- associated_type : Option < Ty < ' tcx > > )
418
+ self_ty : Option < Ty < ' tcx > > )
422
419
-> Rc < ty:: TraitRef < ' tcx > >
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 < ' tcx > > ,
432
- associated_type : Option < Ty < ' tcx > > )
428
+ self_ty : Option < Ty < ' tcx > > )
433
429
-> Rc < ty:: TraitRef < ' tcx > >
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 < ' tcx > > ,
466
- associated_type : Option < Ty < ' tcx > > ,
467
462
path : & ast:: Path )
468
463
-> ty:: TraitRef < ' tcx >
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) ;
@@ -726,7 +719,6 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
726
719
rscope,
727
720
trait_def_id,
728
721
None ,
729
- None ,
730
722
path) ;
731
723
let empty_vec = [ ] ;
732
724
let bounds = match * opt_bounds { None => empty_vec. as_slice ( ) ,
@@ -750,61 +742,37 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
750
742
constr ( ast_ty_to_ty ( this, rscope, a_seq_ty) )
751
743
}
752
744
753
- fn associated_ty_to_ty < ' tcx , AC , RS > ( this : & AC ,
754
- rscope : & RS ,
755
- trait_path : & ast:: Path ,
756
- for_ast_type : & ast:: Ty ,
757
- trait_type_id : ast:: DefId ,
758
- span : Span )
759
- -> Ty < ' tcx >
760
- where AC : AstConv < ' tcx > , RS : RegionScope
745
+ fn qpath_to_ty < ' tcx , AC , RS > ( this : & AC ,
746
+ rscope : & RS ,
747
+ ast_ty : & ast:: Ty , // the TyQPath
748
+ qpath : & ast:: QPath )
749
+ -> Ty < ' tcx >
750
+ where AC : AstConv < ' tcx > , RS : RegionScope
761
751
{
762
- debug ! ( "associated_ty_to_ty(trait_path={}, for_ast_type={}, trait_type_id={})" ,
763
- trait_path. repr( this. tcx( ) ) ,
764
- for_ast_type. repr( this. tcx( ) ) ,
765
- trait_type_id. repr( this. tcx( ) ) ) ;
766
-
767
- // Find the trait that this associated type belongs to.
768
- let trait_did = match ty:: impl_or_trait_item ( this. tcx ( ) ,
769
- trait_type_id) . container ( ) {
770
- ty:: ImplContainer ( _) => {
771
- this. tcx ( ) . sess . span_bug ( span,
772
- "associated_ty_to_ty(): impl associated \
773
- types shouldn't go through this \
774
- function")
775
- }
776
- ty:: TraitContainer ( trait_id) => trait_id,
777
- } ;
752
+ debug ! ( "qpath_to_ty(ast_ty={})" ,
753
+ ast_ty. repr( this. tcx( ) ) ) ;
778
754
779
- let for_type = ast_ty_to_ty ( this, rscope, for_ast_type) ;
780
- if !this. associated_types_of_trait_are_valid ( for_type, trait_did) {
781
- this. tcx ( ) . sess . span_err ( span,
782
- "this associated type is not \
783
- allowed in this context") ;
784
- return ty:: mk_err ( )
785
- }
755
+ let self_type = ast_ty_to_ty ( this, rscope, & * qpath. self_type ) ;
756
+
757
+ debug ! ( "qpath_to_ty: self_type={}" , self_type. repr( this. tcx( ) ) ) ;
786
758
787
- let trait_ref = ast_path_to_trait_ref ( this,
759
+ let trait_ref = instantiate_trait_ref ( this,
788
760
rscope,
789
- trait_did,
790
- None ,
791
- Some ( for_type) ,
792
- trait_path) ;
793
-
794
- debug ! ( "associated_ty_to_ty(trait_ref={})" ,
795
- trait_ref. repr( this. tcx( ) ) ) ;
796
-
797
- let trait_def = this. get_trait_def ( trait_did) ;
798
- for type_parameter in trait_def. generics . types . iter ( ) {
799
- if type_parameter. def_id == trait_type_id {
800
- debug ! ( "associated_ty_to_ty(type_parameter={} substs={})" ,
801
- type_parameter. repr( this. tcx( ) ) ,
802
- trait_ref. substs. repr( this. tcx( ) ) ) ;
803
- return * trait_ref. substs . types . get ( type_parameter. space ,
804
- type_parameter. index )
761
+ & * qpath. trait_ref ,
762
+ Some ( self_type) ) ;
763
+
764
+ debug ! ( "qpath_to_ty: trait_ref={}" , trait_ref. repr( this. tcx( ) ) ) ;
765
+
766
+ let trait_def = this. get_trait_def ( trait_ref. def_id ) ;
767
+
768
+ for ty_param_def in trait_def. generics . types . get_slice ( AssocSpace ) . iter ( ) {
769
+ if ty_param_def. name == qpath. item_name . name {
770
+ debug ! ( "qpath_to_ty: corresponding ty_param_def={}" , ty_param_def) ;
771
+ return trait_ref. substs . type_for_def ( ty_param_def) ;
805
772
}
806
773
}
807
- this. tcx ( ) . sess . span_bug ( span,
774
+
775
+ this. tcx ( ) . sess . span_bug ( ast_ty. span ,
808
776
"this associated type didn't get added \
809
777
as a parameter for some reason")
810
778
}
@@ -931,7 +899,6 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
931
899
rscope,
932
900
trait_def_id,
933
901
None ,
934
- None ,
935
902
path) ;
936
903
let empty_bounds: & [ ast:: TyParamBound ] = & [ ] ;
937
904
let ast_bounds = match * bounds {
@@ -996,26 +963,7 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
996
963
}
997
964
}
998
965
ast:: TyQPath ( ref qpath) => {
999
- match tcx. def_map . borrow ( ) . get ( & ast_ty. id ) {
1000
- None => {
1001
- tcx. sess . span_bug ( ast_ty. span ,
1002
- "unbound qualified path" )
1003
- }
1004
- Some ( & def:: DefAssociatedTy ( trait_type_id) ) => {
1005
- associated_ty_to_ty ( this,
1006
- rscope,
1007
- & qpath. trait_name ,
1008
- & * qpath. for_type ,
1009
- trait_type_id,
1010
- ast_ty. span )
1011
- }
1012
- Some ( _) => {
1013
- tcx. sess . span_err ( ast_ty. span ,
1014
- "this qualified path does not name \
1015
- an associated type") ;
1016
- ty:: mk_err ( )
1017
- }
1018
- }
966
+ qpath_to_ty ( this, rscope, ast_ty, & * * qpath)
1019
967
}
1020
968
ast:: TyFixedLengthVec ( ref ty, ref e) => {
1021
969
match const_eval:: eval_const_expr_partial ( tcx, & * * e) {
@@ -1411,7 +1359,7 @@ fn conv_ty_poly_trait_ref<'tcx, AC, RS>(
1411
1359
1412
1360
let main_trait_bound = match partitioned_bounds. trait_bounds . remove ( 0 ) {
1413
1361
Some ( trait_bound) => {
1414
- Some ( instantiate_poly_trait_ref ( this, rscope, trait_bound, None , None ) )
1362
+ Some ( instantiate_poly_trait_ref ( this, rscope, trait_bound, None ) )
1415
1363
}
1416
1364
None => {
1417
1365
this. tcx ( ) . sess . span_err (
0 commit comments