@@ -59,10 +59,12 @@ struct Candidate<'tcx> {
59
59
}
60
60
61
61
enum CandidateKind < ' tcx > {
62
- InherentImplCandidate ( /* Impl */ ast:: DefId , subst:: Substs < ' tcx > ) ,
62
+ InherentImplCandidate ( /* Impl */ ast:: DefId , subst:: Substs < ' tcx > ,
63
+ /* Normalize obligations */ Vec < traits:: PredicateObligation < ' tcx > > ) ,
63
64
ObjectCandidate ( /* Trait */ ast:: DefId , /* method_num */ usize , /* vtable index */ usize ) ,
64
65
ExtensionImplCandidate ( /* Impl */ ast:: DefId , ty:: TraitRef < ' tcx > ,
65
- subst:: Substs < ' tcx > , ItemIndex ) ,
66
+ subst:: Substs < ' tcx > , ItemIndex ,
67
+ /* Normalize obligations */ Vec < traits:: PredicateObligation < ' tcx > > ) ,
66
68
ClosureCandidate ( /* Trait */ ast:: DefId , ItemIndex ) ,
67
69
WhereClauseCandidate ( ty:: PolyTraitRef < ' tcx > , ItemIndex ) ,
68
70
ProjectionCandidate ( ast:: DefId , ItemIndex ) ,
@@ -398,16 +400,24 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
398
400
}
399
401
400
402
let ( impl_ty, impl_substs) = self . impl_ty_and_substs ( impl_def_id) ;
401
- let impl_ty = self . fcx . instantiate_type_scheme ( self . span , & impl_substs, & impl_ty ) ;
403
+ let impl_ty = impl_ty . subst ( self . tcx ( ) , & impl_substs) ;
402
404
403
405
// Determine the receiver type that the method itself expects.
404
- let xform_self_ty =
405
- self . xform_self_ty ( & item, impl_ty, & impl_substs) ;
406
+ let xform_self_ty = self . xform_self_ty ( & item, impl_ty, & impl_substs) ;
407
+
408
+ // We can't use normalize_associated_types_in as it will pollute the
409
+ // fcx's fulfillment context after this probe is over.
410
+ let cause = traits:: ObligationCause :: misc ( self . span , self . fcx . body_id ) ;
411
+ let mut selcx = & mut traits:: SelectionContext :: new ( self . fcx . infcx ( ) , self . fcx ) ;
412
+ let traits:: Normalized { value : xform_self_ty, obligations } =
413
+ traits:: normalize ( selcx, cause, & xform_self_ty) ;
414
+ debug ! ( "assemble_inherent_impl_probe: xform_self_ty = {:?}" ,
415
+ xform_self_ty. repr( self . tcx( ) ) ) ;
406
416
407
417
self . inherent_candidates . push ( Candidate {
408
418
xform_self_ty : xform_self_ty,
409
419
item : item,
410
- kind : InherentImplCandidate ( impl_def_id, impl_substs)
420
+ kind : InherentImplCandidate ( impl_def_id, impl_substs, obligations )
411
421
} ) ;
412
422
}
413
423
@@ -653,12 +663,24 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
653
663
impl_trait_ref. self_ty ( ) ,
654
664
impl_trait_ref. substs ) ;
655
665
666
+ // Normalize the receiver. We can't use normalize_associated_types_in
667
+ // as it will pollute the fcx's fulfillment context after this probe
668
+ // is over.
669
+ let cause = traits:: ObligationCause :: misc ( self . span , self . fcx . body_id ) ;
670
+ let mut selcx = & mut traits:: SelectionContext :: new ( self . fcx . infcx ( ) , self . fcx ) ;
671
+ let traits:: Normalized { value : xform_self_ty, obligations } =
672
+ traits:: normalize ( selcx, cause, & xform_self_ty) ;
673
+
656
674
debug ! ( "xform_self_ty={}" , xform_self_ty. repr( self . tcx( ) ) ) ;
657
675
658
676
self . extension_candidates . push ( Candidate {
659
677
xform_self_ty : xform_self_ty,
660
678
item : item. clone ( ) ,
661
- kind : ExtensionImplCandidate ( impl_def_id, impl_trait_ref, impl_substs, item_index)
679
+ kind : ExtensionImplCandidate ( impl_def_id,
680
+ impl_trait_ref,
681
+ impl_substs,
682
+ item_index,
683
+ obligations)
662
684
} ) ;
663
685
} ) ;
664
686
}
@@ -1026,8 +1048,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
1026
1048
// match as well (or at least may match, sometimes we
1027
1049
// don't have enough information to fully evaluate).
1028
1050
match probe. kind {
1029
- InherentImplCandidate ( impl_def_id, ref substs) |
1030
- ExtensionImplCandidate ( impl_def_id, _, ref substs, _) => {
1051
+ InherentImplCandidate ( impl_def_id, ref substs, ref ref_obligations ) |
1052
+ ExtensionImplCandidate ( impl_def_id, _, ref substs, _, ref ref_obligations ) => {
1031
1053
let selcx = & mut traits:: SelectionContext :: new ( self . infcx ( ) , self . fcx ) ;
1032
1054
let cause = traits:: ObligationCause :: misc ( self . span , self . fcx . body_id ) ;
1033
1055
@@ -1046,8 +1068,10 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
1046
1068
debug ! ( "impl_obligations={}" , obligations. repr( self . tcx( ) ) ) ;
1047
1069
1048
1070
// Evaluate those obligations to see if they might possibly hold.
1049
- obligations. iter ( ) . all ( |o| selcx. evaluate_obligation ( o) ) &&
1050
- norm_obligations. iter ( ) . all ( |o| selcx. evaluate_obligation ( o) )
1071
+ obligations. iter ( )
1072
+ . chain ( norm_obligations. iter ( ) ) . chain ( ref_obligations. iter ( ) )
1073
+ . all ( |o| selcx. evaluate_obligation ( o) )
1074
+
1051
1075
}
1052
1076
1053
1077
ProjectionCandidate ( ..) |
@@ -1281,13 +1305,13 @@ impl<'tcx> Candidate<'tcx> {
1281
1305
Pick {
1282
1306
item : self . item . clone ( ) ,
1283
1307
kind : match self . kind {
1284
- InherentImplCandidate ( def_id, _) => {
1308
+ InherentImplCandidate ( def_id, _, _ ) => {
1285
1309
InherentImplPick ( def_id)
1286
1310
}
1287
1311
ObjectCandidate ( def_id, item_num, real_index) => {
1288
1312
ObjectPick ( def_id, item_num, real_index)
1289
1313
}
1290
- ExtensionImplCandidate ( def_id, _, _, index) => {
1314
+ ExtensionImplCandidate ( def_id, _, _, index, _ ) => {
1291
1315
ExtensionImplPick ( def_id, index)
1292
1316
}
1293
1317
ClosureCandidate ( trait_def_id, index) => {
@@ -1315,9 +1339,9 @@ impl<'tcx> Candidate<'tcx> {
1315
1339
1316
1340
fn to_source ( & self ) -> CandidateSource {
1317
1341
match self . kind {
1318
- InherentImplCandidate ( def_id, _) => ImplSource ( def_id) ,
1342
+ InherentImplCandidate ( def_id, _, _ ) => ImplSource ( def_id) ,
1319
1343
ObjectCandidate ( def_id, _, _) => TraitSource ( def_id) ,
1320
- ExtensionImplCandidate ( def_id, _, _, _) => ImplSource ( def_id) ,
1344
+ ExtensionImplCandidate ( def_id, _, _, _, _ ) => ImplSource ( def_id) ,
1321
1345
ClosureCandidate ( trait_def_id, _) => TraitSource ( trait_def_id) ,
1322
1346
WhereClauseCandidate ( ref trait_ref, _) => TraitSource ( trait_ref. def_id ( ) ) ,
1323
1347
ProjectionCandidate ( trait_def_id, _) => TraitSource ( trait_def_id) ,
@@ -1335,7 +1359,7 @@ impl<'tcx> Candidate<'tcx> {
1335
1359
ClosureCandidate ( trait_def_id, item_num) => {
1336
1360
Some ( ( trait_def_id, item_num) )
1337
1361
}
1338
- ExtensionImplCandidate ( _, ref trait_ref, _, item_num) => {
1362
+ ExtensionImplCandidate ( _, ref trait_ref, _, item_num, _ ) => {
1339
1363
Some ( ( trait_ref. def_id , item_num) )
1340
1364
}
1341
1365
WhereClauseCandidate ( ref trait_ref, item_num) => {
@@ -1359,13 +1383,14 @@ impl<'tcx> Repr<'tcx> for Candidate<'tcx> {
1359
1383
impl < ' tcx > Repr < ' tcx > for CandidateKind < ' tcx > {
1360
1384
fn repr ( & self , tcx : & ty:: ctxt < ' tcx > ) -> String {
1361
1385
match * self {
1362
- InherentImplCandidate ( ref a, ref b) =>
1363
- format ! ( "InherentImplCandidate({},{})" , a. repr( tcx) , b. repr( tcx) ) ,
1386
+ InherentImplCandidate ( ref a, ref b, ref c) =>
1387
+ format ! ( "InherentImplCandidate({},{},{})" , a. repr( tcx) , b. repr( tcx) ,
1388
+ c. repr( tcx) ) ,
1364
1389
ObjectCandidate ( a, b, c) =>
1365
1390
format ! ( "ObjectCandidate({},{},{})" , a. repr( tcx) , b, c) ,
1366
- ExtensionImplCandidate ( ref a, ref b, ref c, ref d) =>
1367
- format ! ( "ExtensionImplCandidate({},{},{},{})" , a. repr( tcx) , b. repr( tcx) ,
1368
- c. repr( tcx) , d) ,
1391
+ ExtensionImplCandidate ( ref a, ref b, ref c, ref d, ref e ) =>
1392
+ format ! ( "ExtensionImplCandidate({},{},{},{},{} )" , a. repr( tcx) , b. repr( tcx) ,
1393
+ c. repr( tcx) , d, e . repr ( tcx ) ) ,
1369
1394
ClosureCandidate ( ref a, ref b) =>
1370
1395
format ! ( "ClosureCandidate({},{})" , a. repr( tcx) , b) ,
1371
1396
WhereClauseCandidate ( ref a, ref b) =>
0 commit comments