@@ -365,9 +365,7 @@ pub fn normalize_projection_type<'a, 'b, 'gcx, 'tcx>(
365365 // information is available.
366366
367367 let tcx = selcx. infcx ( ) . tcx ;
368- let def_id = tcx. associated_items ( projection_ty. trait_ref . def_id ) . find ( |i|
369- i. name == projection_ty. item_name ( tcx) && i. kind == ty:: AssociatedKind :: Type
370- ) . map ( |i| i. def_id ) . unwrap ( ) ;
368+ let def_id = projection_ty. item_def_id ;
371369 let ty_var = selcx. infcx ( ) . next_ty_var (
372370 TypeVariableOrigin :: NormalizeProjectionType ( tcx. def_span ( def_id) ) ) ;
373371 let projection = ty:: Binder ( ty:: ProjectionPredicate {
@@ -447,8 +445,8 @@ fn opt_normalize_projection_type<'a, 'b, 'gcx, 'tcx>(
447445 // normalization. In that case, I think we will want this code:
448446 //
449447 // ```
450- // let ty = selcx.tcx().mk_projection(projection_ty.trait_ref ,
451- // projection_ty.item_name(tcx) ;
448+ // let ty = selcx.tcx().mk_projection(projection_ty.item_def_id ,
449+ // projection_ty.substs ;
452450 // return Some(NormalizedTy { value: v, obligations: vec![] });
453451 // ```
454452
@@ -585,15 +583,13 @@ fn normalize_to_error<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a, 'gcx, 'tc
585583 depth : usize )
586584 -> NormalizedTy < ' tcx >
587585{
588- let trait_ref = projection_ty. trait_ref . to_poly_trait_ref ( ) ;
586+ let trait_ref = projection_ty. trait_ref ( selcx . tcx ( ) ) . to_poly_trait_ref ( ) ;
589587 let trait_obligation = Obligation { cause,
590588 recursion_depth : depth,
591589 param_env,
592590 predicate : trait_ref. to_predicate ( ) } ;
593591 let tcx = selcx. infcx ( ) . tcx ;
594- let def_id = tcx. associated_items ( projection_ty. trait_ref . def_id ) . find ( |i|
595- i. name == projection_ty. item_name ( tcx) && i. kind == ty:: AssociatedKind :: Type
596- ) . map ( |i| i. def_id ) . unwrap ( ) ;
592+ let def_id = projection_ty. item_def_id ;
597593 let new_value = selcx. infcx ( ) . next_ty_var (
598594 TypeVariableOrigin :: NormalizeProjectionType ( tcx. def_span ( def_id) ) ) ;
599595 Normalized {
@@ -654,7 +650,7 @@ fn project_type<'cx, 'gcx, 'tcx>(
654650 selcx. infcx ( ) . report_overflow_error ( & obligation, true ) ;
655651 }
656652
657- let obligation_trait_ref = & obligation. predicate . trait_ref ;
653+ let obligation_trait_ref = & obligation. predicate . trait_ref ( selcx . tcx ( ) ) ;
658654
659655 debug ! ( "project: obligation_trait_ref={:?}" , obligation_trait_ref) ;
660656
@@ -743,12 +739,10 @@ fn project_type<'cx, 'gcx, 'tcx>(
743739 & obligation_trait_ref,
744740 candidate) ) )
745741 }
746- None => {
747- Ok ( ProjectedTy :: NoProgress (
748- selcx. tcx ( ) . mk_projection (
749- obligation. predicate . trait_ref . clone ( ) ,
750- obligation. predicate . item_name ( selcx. tcx ( ) ) ) ) )
751- }
742+ None => Ok ( ProjectedTy :: NoProgress (
743+ selcx. tcx ( ) . mk_projection (
744+ obligation. predicate . item_def_id ,
745+ obligation. predicate . substs ) ) )
752746 }
753747}
754748
@@ -788,10 +782,11 @@ fn assemble_candidates_from_trait_def<'cx, 'gcx, 'tcx>(
788782{
789783 debug ! ( "assemble_candidates_from_trait_def(..)" ) ;
790784
785+ let tcx = selcx. tcx ( ) ;
791786 // Check whether the self-type is itself a projection.
792787 let ( def_id, substs) = match obligation_trait_ref. self_ty ( ) . sty {
793788 ty:: TyProjection ( ref data) => {
794- ( data. trait_ref . def_id , data. trait_ref . substs )
789+ ( data. trait_ref ( tcx ) . def_id , data. substs )
795790 }
796791 ty:: TyAnon ( def_id, substs) => ( def_id, substs) ,
797792 ty:: TyInfer ( ty:: TyVar ( _) ) => {
@@ -804,9 +799,9 @@ fn assemble_candidates_from_trait_def<'cx, 'gcx, 'tcx>(
804799 } ;
805800
806801 // If so, extract what we know from the trait and try to come up with a good answer.
807- let trait_predicates = selcx . tcx ( ) . predicates_of ( def_id) ;
808- let bounds = trait_predicates. instantiate ( selcx . tcx ( ) , substs) ;
809- let bounds = elaborate_predicates ( selcx . tcx ( ) , bounds. predicates ) ;
802+ let trait_predicates = tcx. predicates_of ( def_id) ;
803+ let bounds = trait_predicates. instantiate ( tcx, substs) ;
804+ let bounds = elaborate_predicates ( tcx, bounds. predicates ) ;
810805 assemble_candidates_from_predicates ( selcx,
811806 obligation,
812807 obligation_trait_ref,
@@ -832,12 +827,12 @@ fn assemble_candidates_from_predicates<'cx, 'gcx, 'tcx, I>(
832827 predicate) ;
833828 match predicate {
834829 ty:: Predicate :: Projection ( ref data) => {
835- let tcx = selcx . tcx ( ) ;
836- let same_name = data. item_name ( tcx ) == obligation. predicate . item_name ( tcx ) ;
830+ let same_def_id =
831+ data. 0 . projection_ty . item_def_id == obligation. predicate . item_def_id ;
837832
838- let is_match = same_name && infcx. probe ( |_| {
833+ let is_match = same_def_id && infcx. probe ( |_| {
839834 let data_poly_trait_ref =
840- data. to_poly_trait_ref ( ) ;
835+ data. to_poly_trait_ref ( infcx . tcx ) ;
841836 let obligation_poly_trait_ref =
842837 obligation_trait_ref. to_poly_trait_ref ( ) ;
843838 infcx. at ( & obligation. cause , obligation. param_env )
@@ -850,8 +845,8 @@ fn assemble_candidates_from_predicates<'cx, 'gcx, 'tcx, I>(
850845 } ) ;
851846
852847 debug ! ( "assemble_candidates_from_predicates: candidate={:?} \
853- is_match={} same_name ={}",
854- data, is_match, same_name ) ;
848+ is_match={} same_def_id ={}",
849+ data, is_match, same_def_id ) ;
855850
856851 if is_match {
857852 candidate_set. vec . push ( ctor ( data. clone ( ) ) ) ;
@@ -916,9 +911,10 @@ fn assemble_candidates_from_impls<'cx, 'gcx, 'tcx>(
916911 // In either case, we handle this by not adding a
917912 // candidate for an impl if it contains a `default`
918913 // type.
914+ let item_name = selcx. tcx ( ) . associated_item ( obligation. predicate . item_def_id ) . name ;
919915 let node_item = assoc_ty_def ( selcx,
920916 impl_data. impl_def_id ,
921- obligation . predicate . item_name ( selcx . tcx ( ) ) ) ;
917+ item_name) ;
922918
923919 let is_default = if node_item. node . is_from_trait ( ) {
924920 // If true, the impl inherited a `type Foo = Bar`
@@ -1091,10 +1087,9 @@ fn confirm_object_candidate<'cx, 'gcx, 'tcx>(
10911087
10921088 // select only those projections that are actually projecting an
10931089 // item with the correct name
1094- let tcx = selcx. tcx ( ) ;
10951090 let env_predicates = env_predicates. filter_map ( |p| match p {
10961091 ty:: Predicate :: Projection ( data) =>
1097- if data. item_name ( tcx ) == obligation. predicate . item_name ( tcx ) {
1092+ if data. 0 . projection_ty . item_def_id == obligation. predicate . item_def_id {
10981093 Some ( data)
10991094 } else {
11001095 None
@@ -1104,7 +1099,7 @@ fn confirm_object_candidate<'cx, 'gcx, 'tcx>(
11041099
11051100 // select those with a relevant trait-ref
11061101 let mut env_predicates = env_predicates. filter ( |data| {
1107- let data_poly_trait_ref = data. to_poly_trait_ref ( ) ;
1102+ let data_poly_trait_ref = data. to_poly_trait_ref ( selcx . tcx ( ) ) ;
11081103 let obligation_poly_trait_ref = obligation_trait_ref. to_poly_trait_ref ( ) ;
11091104 selcx. infcx ( ) . probe ( |_| {
11101105 selcx. infcx ( ) . at ( & obligation. cause , obligation. param_env )
@@ -1202,7 +1197,7 @@ fn confirm_callable_candidate<'cx, 'gcx, 'tcx>(
12021197 // Note: we unwrap the binder here but re-create it below (1)
12031198 let ty:: Binder ( ( trait_ref, ret_type) ) =
12041199 tcx. closure_trait_ref_and_return_type ( fn_once_def_id,
1205- obligation. predicate . trait_ref . self_ty ( ) ,
1200+ obligation. predicate . self_ty ( ) ,
12061201 fn_sig,
12071202 flag) ;
12081203
@@ -1227,7 +1222,7 @@ fn confirm_param_env_candidate<'cx, 'gcx, 'tcx>(
12271222 let infcx = selcx. infcx ( ) ;
12281223 let cause = obligation. cause . clone ( ) ;
12291224 let param_env = obligation. param_env ;
1230- let trait_ref = obligation. predicate . trait_ref ;
1225+ let trait_ref = obligation. predicate . trait_ref ( infcx . tcx ) ;
12311226 match infcx. match_poly_projection_predicate ( cause, param_env, poly_projection, trait_ref) {
12321227 Ok ( InferOk { value : ty_match, obligations } ) => {
12331228 Progress {
@@ -1258,7 +1253,8 @@ fn confirm_impl_candidate<'cx, 'gcx, 'tcx>(
12581253
12591254 let tcx = selcx. tcx ( ) ;
12601255 let param_env = obligation. param_env ;
1261- let assoc_ty = assoc_ty_def ( selcx, impl_def_id, obligation. predicate . item_name ( tcx) ) ;
1256+ let assoc_ty = assoc_ty_def ( selcx, impl_def_id,
1257+ tcx. associated_item ( obligation. predicate . item_def_id ) . name ) ;
12621258
12631259 let ty = if !assoc_ty. item . defaultness . has_value ( ) {
12641260 // This means that the impl is missing a definition for the
@@ -1267,7 +1263,7 @@ fn confirm_impl_candidate<'cx, 'gcx, 'tcx>(
12671263 // just return TyError.
12681264 debug ! ( "confirm_impl_candidate: no associated type {:?} for {:?}" ,
12691265 assoc_ty. item. name,
1270- obligation. predicate. trait_ref ) ;
1266+ obligation. predicate) ;
12711267 tcx. types . err
12721268 } else {
12731269 tcx. type_of ( assoc_ty. item . def_id )
0 commit comments