@@ -365,9 +365,7 @@ pub fn normalize_projection_type<'a, 'b, 'gcx, 'tcx>(
365
365
// information is available.
366
366
367
367
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 ;
371
369
let ty_var = selcx. infcx ( ) . next_ty_var (
372
370
TypeVariableOrigin :: NormalizeProjectionType ( tcx. def_span ( def_id) ) ) ;
373
371
let projection = ty:: Binder ( ty:: ProjectionPredicate {
@@ -447,8 +445,8 @@ fn opt_normalize_projection_type<'a, 'b, 'gcx, 'tcx>(
447
445
// normalization. In that case, I think we will want this code:
448
446
//
449
447
// ```
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 ;
452
450
// return Some(NormalizedTy { value: v, obligations: vec![] });
453
451
// ```
454
452
@@ -585,15 +583,13 @@ fn normalize_to_error<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a, 'gcx, 'tc
585
583
depth : usize )
586
584
-> NormalizedTy < ' tcx >
587
585
{
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 ( ) ;
589
587
let trait_obligation = Obligation { cause,
590
588
recursion_depth : depth,
591
589
param_env,
592
590
predicate : trait_ref. to_predicate ( ) } ;
593
591
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 ;
597
593
let new_value = selcx. infcx ( ) . next_ty_var (
598
594
TypeVariableOrigin :: NormalizeProjectionType ( tcx. def_span ( def_id) ) ) ;
599
595
Normalized {
@@ -654,7 +650,7 @@ fn project_type<'cx, 'gcx, 'tcx>(
654
650
selcx. infcx ( ) . report_overflow_error ( & obligation, true ) ;
655
651
}
656
652
657
- let obligation_trait_ref = & obligation. predicate . trait_ref ;
653
+ let obligation_trait_ref = & obligation. predicate . trait_ref ( selcx . tcx ( ) ) ;
658
654
659
655
debug ! ( "project: obligation_trait_ref={:?}" , obligation_trait_ref) ;
660
656
@@ -743,12 +739,10 @@ fn project_type<'cx, 'gcx, 'tcx>(
743
739
& obligation_trait_ref,
744
740
candidate) ) )
745
741
}
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 ) ) )
752
746
}
753
747
}
754
748
@@ -788,10 +782,11 @@ fn assemble_candidates_from_trait_def<'cx, 'gcx, 'tcx>(
788
782
{
789
783
debug ! ( "assemble_candidates_from_trait_def(..)" ) ;
790
784
785
+ let tcx = selcx. tcx ( ) ;
791
786
// Check whether the self-type is itself a projection.
792
787
let ( def_id, substs) = match obligation_trait_ref. self_ty ( ) . sty {
793
788
ty:: TyProjection ( ref data) => {
794
- ( data. trait_ref . def_id , data. trait_ref . substs )
789
+ ( data. trait_ref ( tcx ) . def_id , data. substs )
795
790
}
796
791
ty:: TyAnon ( def_id, substs) => ( def_id, substs) ,
797
792
ty:: TyInfer ( ty:: TyVar ( _) ) => {
@@ -804,9 +799,9 @@ fn assemble_candidates_from_trait_def<'cx, 'gcx, 'tcx>(
804
799
} ;
805
800
806
801
// 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 ) ;
810
805
assemble_candidates_from_predicates ( selcx,
811
806
obligation,
812
807
obligation_trait_ref,
@@ -832,12 +827,12 @@ fn assemble_candidates_from_predicates<'cx, 'gcx, 'tcx, I>(
832
827
predicate) ;
833
828
match predicate {
834
829
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 ;
837
832
838
- let is_match = same_name && infcx. probe ( |_| {
833
+ let is_match = same_def_id && infcx. probe ( |_| {
839
834
let data_poly_trait_ref =
840
- data. to_poly_trait_ref ( ) ;
835
+ data. to_poly_trait_ref ( infcx . tcx ) ;
841
836
let obligation_poly_trait_ref =
842
837
obligation_trait_ref. to_poly_trait_ref ( ) ;
843
838
infcx. at ( & obligation. cause , obligation. param_env )
@@ -850,8 +845,8 @@ fn assemble_candidates_from_predicates<'cx, 'gcx, 'tcx, I>(
850
845
} ) ;
851
846
852
847
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 ) ;
855
850
856
851
if is_match {
857
852
candidate_set. vec . push ( ctor ( data. clone ( ) ) ) ;
@@ -916,9 +911,10 @@ fn assemble_candidates_from_impls<'cx, 'gcx, 'tcx>(
916
911
// In either case, we handle this by not adding a
917
912
// candidate for an impl if it contains a `default`
918
913
// type.
914
+ let item_name = selcx. tcx ( ) . associated_item ( obligation. predicate . item_def_id ) . name ;
919
915
let node_item = assoc_ty_def ( selcx,
920
916
impl_data. impl_def_id ,
921
- obligation . predicate . item_name ( selcx . tcx ( ) ) ) ;
917
+ item_name) ;
922
918
923
919
let is_default = if node_item. node . is_from_trait ( ) {
924
920
// If true, the impl inherited a `type Foo = Bar`
@@ -1091,10 +1087,9 @@ fn confirm_object_candidate<'cx, 'gcx, 'tcx>(
1091
1087
1092
1088
// select only those projections that are actually projecting an
1093
1089
// item with the correct name
1094
- let tcx = selcx. tcx ( ) ;
1095
1090
let env_predicates = env_predicates. filter_map ( |p| match p {
1096
1091
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 {
1098
1093
Some ( data)
1099
1094
} else {
1100
1095
None
@@ -1104,7 +1099,7 @@ fn confirm_object_candidate<'cx, 'gcx, 'tcx>(
1104
1099
1105
1100
// select those with a relevant trait-ref
1106
1101
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 ( ) ) ;
1108
1103
let obligation_poly_trait_ref = obligation_trait_ref. to_poly_trait_ref ( ) ;
1109
1104
selcx. infcx ( ) . probe ( |_| {
1110
1105
selcx. infcx ( ) . at ( & obligation. cause , obligation. param_env )
@@ -1202,7 +1197,7 @@ fn confirm_callable_candidate<'cx, 'gcx, 'tcx>(
1202
1197
// Note: we unwrap the binder here but re-create it below (1)
1203
1198
let ty:: Binder ( ( trait_ref, ret_type) ) =
1204
1199
tcx. closure_trait_ref_and_return_type ( fn_once_def_id,
1205
- obligation. predicate . trait_ref . self_ty ( ) ,
1200
+ obligation. predicate . self_ty ( ) ,
1206
1201
fn_sig,
1207
1202
flag) ;
1208
1203
@@ -1227,7 +1222,7 @@ fn confirm_param_env_candidate<'cx, 'gcx, 'tcx>(
1227
1222
let infcx = selcx. infcx ( ) ;
1228
1223
let cause = obligation. cause . clone ( ) ;
1229
1224
let param_env = obligation. param_env ;
1230
- let trait_ref = obligation. predicate . trait_ref ;
1225
+ let trait_ref = obligation. predicate . trait_ref ( infcx . tcx ) ;
1231
1226
match infcx. match_poly_projection_predicate ( cause, param_env, poly_projection, trait_ref) {
1232
1227
Ok ( InferOk { value : ty_match, obligations } ) => {
1233
1228
Progress {
@@ -1258,7 +1253,8 @@ fn confirm_impl_candidate<'cx, 'gcx, 'tcx>(
1258
1253
1259
1254
let tcx = selcx. tcx ( ) ;
1260
1255
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 ) ;
1262
1258
1263
1259
let ty = if !assoc_ty. item . defaultness . has_value ( ) {
1264
1260
// This means that the impl is missing a definition for the
@@ -1267,7 +1263,7 @@ fn confirm_impl_candidate<'cx, 'gcx, 'tcx>(
1267
1263
// just return TyError.
1268
1264
debug ! ( "confirm_impl_candidate: no associated type {:?} for {:?}" ,
1269
1265
assoc_ty. item. name,
1270
- obligation. predicate. trait_ref ) ;
1266
+ obligation. predicate) ;
1271
1267
tcx. types . err
1272
1268
} else {
1273
1269
tcx. type_of ( assoc_ty. item . def_id )
0 commit comments