@@ -207,7 +207,6 @@ fn ast_path_substs_for_ty<'tcx,AC,RS>(
207207 decl_def_id : ast:: DefId ,
208208 decl_generics : & ty:: Generics ,
209209 self_ty : Option < ty:: t > ,
210- associated_ty : Option < ty:: t > ,
211210 path : & ast:: Path )
212211 -> Substs
213212 where AC : AstConv < ' tcx > , RS : RegionScope
@@ -243,7 +242,7 @@ fn ast_path_substs_for_ty<'tcx,AC,RS>(
243242 } ;
244243
245244 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)
247246}
248247
249248fn create_substs_for_ast_path < ' tcx , AC , RS > (
@@ -254,8 +253,7 @@ fn create_substs_for_ast_path<'tcx,AC,RS>(
254253 decl_generics : & ty:: Generics ,
255254 self_ty : Option < ty:: t > ,
256255 types : Vec < ty:: t > ,
257- regions : Vec < ty:: Region > ,
258- associated_ty : Option < ty:: t > )
256+ regions : Vec < ty:: Region > )
259257 -> Substs
260258 where AC : AstConv < ' tcx > , RS : RegionScope
261259{
@@ -366,9 +364,9 @@ fn create_substs_for_ast_path<'tcx,AC,RS>(
366364 substs. types . push (
367365 AssocSpace ,
368366 this. associated_type_binding ( span,
369- associated_ty ,
367+ self_ty ,
370368 decl_def_id,
371- param. def_id ) )
369+ param. def_id ) ) ;
372370 }
373371
374372 return substs;
@@ -417,19 +415,17 @@ pub fn instantiate_poly_trait_ref<'tcx,AC,RS>(
417415 this : & AC ,
418416 rscope : & RS ,
419417 ast_trait_ref : & ast:: PolyTraitRef ,
420- self_ty : Option < ty:: t > ,
421- associated_type : Option < ty:: t > )
418+ self_ty : Option < ty:: t > )
422419 -> Rc < ty:: TraitRef >
423420 where AC : AstConv < ' tcx > , RS : RegionScope
424421{
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)
426423}
427424
428425pub fn instantiate_trait_ref < ' tcx , AC , RS > ( this : & AC ,
429426 rscope : & RS ,
430427 ast_trait_ref : & ast:: TraitRef ,
431- self_ty : Option < ty:: t > ,
432- associated_type : Option < ty:: t > )
428+ self_ty : Option < ty:: t > )
433429 -> Rc < ty:: TraitRef >
434430 where AC : AstConv < ' tcx > ,
435431 RS : RegionScope
@@ -444,8 +440,8 @@ pub fn instantiate_trait_ref<'tcx,AC,RS>(this: &AC,
444440 ast_trait_ref. path . span ,
445441 ast_trait_ref. ref_id ) {
446442 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 ) ) ;
449445 this. tcx ( ) . trait_refs . borrow_mut ( ) . insert ( ast_trait_ref. ref_id ,
450446 trait_ref. clone ( ) ) ;
451447 trait_ref
@@ -463,7 +459,6 @@ fn ast_path_to_trait_ref<'tcx,AC,RS>(
463459 rscope : & RS ,
464460 trait_def_id : ast:: DefId ,
465461 self_ty : Option < ty:: t > ,
466- associated_type : Option < ty:: t > ,
467462 path : & ast:: Path )
468463 -> ty:: TraitRef
469464 where AC : AstConv < ' tcx > , RS : RegionScope
@@ -493,8 +488,7 @@ fn ast_path_to_trait_ref<'tcx,AC,RS>(
493488 & trait_def. generics ,
494489 self_ty,
495490 types,
496- regions,
497- associated_type) ;
491+ regions) ;
498492
499493 ty:: TraitRef :: new ( trait_def_id, substs)
500494}
@@ -517,7 +511,6 @@ pub fn ast_path_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
517511 did,
518512 & generics,
519513 None ,
520- None ,
521514 path) ;
522515 let ty = decl_ty. subst ( tcx, & substs) ;
523516 TypeAndSubsts { substs : substs, ty : ty }
@@ -558,7 +551,7 @@ pub fn ast_path_to_ty_relaxed<'tcx,AC,RS>(
558551 Substs :: new ( VecPerParamSpace :: params_from_type ( type_params) ,
559552 VecPerParamSpace :: params_from_type ( region_params) )
560553 } 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)
562555 } ;
563556
564557 let ty = decl_ty. subst ( tcx, & substs) ;
@@ -725,7 +718,6 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
725718 rscope,
726719 trait_def_id,
727720 None ,
728- None ,
729721 path) ;
730722 let empty_vec = [ ] ;
731723 let bounds = match * opt_bounds { None => empty_vec. as_slice ( ) ,
@@ -749,61 +741,37 @@ fn mk_pointer<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
749741 constr ( ast_ty_to_ty ( this, rscope, a_seq_ty) )
750742}
751743
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
760750{
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( ) ) ) ;
777753
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( ) ) ) ;
785757
786- let trait_ref = ast_path_to_trait_ref ( this,
758+ let trait_ref = instantiate_trait_ref ( this,
787759 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) ;
804771 }
805772 }
806- this. tcx ( ) . sess . span_bug ( span,
773+
774+ this. tcx ( ) . sess . span_bug ( ast_ty. span ,
807775 "this associated type didn't get added \
808776 as a parameter for some reason")
809777}
@@ -930,7 +898,6 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
930898 rscope,
931899 trait_def_id,
932900 None ,
933- None ,
934901 path) ;
935902 let empty_bounds: & [ ast:: TyParamBound ] = & [ ] ;
936903 let ast_bounds = match * bounds {
@@ -995,26 +962,7 @@ pub fn ast_ty_to_ty<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
995962 }
996963 }
997964 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)
1018966 }
1019967 ast:: TyFixedLengthVec ( ref ty, ref e) => {
1020968 match const_eval:: eval_const_expr_partial ( tcx, & * * e) {
@@ -1410,7 +1358,7 @@ fn conv_ty_poly_trait_ref<'tcx, AC, RS>(
14101358
14111359 let main_trait_bound = match partitioned_bounds. trait_bounds . remove ( 0 ) {
14121360 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 ) )
14141362 }
14151363 None => {
14161364 this. tcx ( ) . sess . span_err (
0 commit comments