@@ -44,6 +44,7 @@ struct ProbeContext<'a, 'tcx:'a> {
44
44
inherent_candidates : Vec < Candidate < ' tcx > > ,
45
45
extension_candidates : Vec < Candidate < ' tcx > > ,
46
46
impl_dups : HashSet < DefId > ,
47
+ import_id : Option < ast:: NodeId > ,
47
48
48
49
/// Collects near misses when the candidate functions are missing a `self` keyword and is only
49
50
/// used for error reporting
@@ -66,6 +67,7 @@ struct Candidate<'tcx> {
66
67
xform_self_ty : Ty < ' tcx > ,
67
68
item : ty:: ImplOrTraitItem < ' tcx > ,
68
69
kind : CandidateKind < ' tcx > ,
70
+ import_id : Option < ast:: NodeId > ,
69
71
}
70
72
71
73
#[ derive( Debug ) ]
@@ -83,6 +85,7 @@ enum CandidateKind<'tcx> {
83
85
pub struct Pick < ' tcx > {
84
86
pub item : ty:: ImplOrTraitItem < ' tcx > ,
85
87
pub kind : PickKind < ' tcx > ,
88
+ pub import_id : Option < ast:: NodeId > ,
86
89
87
90
// Indicates that the source expression should be autoderef'd N times
88
91
//
@@ -246,6 +249,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
246
249
inherent_candidates : Vec :: new ( ) ,
247
250
extension_candidates : Vec :: new ( ) ,
248
251
impl_dups : HashSet :: new ( ) ,
252
+ import_id : None ,
249
253
steps : Rc :: new ( steps) ,
250
254
opt_simplified_steps : opt_simplified_steps,
251
255
static_candidates : Vec :: new ( ) ,
@@ -427,7 +431,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
427
431
self . inherent_candidates . push ( Candidate {
428
432
xform_self_ty : xform_self_ty,
429
433
item : item,
430
- kind : InherentImplCandidate ( impl_substs, obligations)
434
+ kind : InherentImplCandidate ( impl_substs, obligations) ,
435
+ import_id : self . import_id ,
431
436
} ) ;
432
437
}
433
438
@@ -455,7 +460,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
455
460
this. inherent_candidates . push ( Candidate {
456
461
xform_self_ty : xform_self_ty,
457
462
item : item,
458
- kind : ObjectCandidate
463
+ kind : ObjectCandidate ,
464
+ import_id : this. import_id ,
459
465
} ) ;
460
466
} ) ;
461
467
}
@@ -524,7 +530,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
524
530
this. inherent_candidates . push ( Candidate {
525
531
xform_self_ty : xform_self_ty,
526
532
item : item,
527
- kind : WhereClauseCandidate ( poly_trait_ref)
533
+ kind : WhereClauseCandidate ( poly_trait_ref) ,
534
+ import_id : this. import_id ,
528
535
} ) ;
529
536
} ) ;
530
537
}
@@ -568,9 +575,13 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
568
575
let mut duplicates = HashSet :: new ( ) ;
569
576
let opt_applicable_traits = self . fcx . ccx . trait_map . get ( & expr_id) ;
570
577
if let Some ( applicable_traits) = opt_applicable_traits {
571
- for & trait_did in applicable_traits {
578
+ for trait_candidate in applicable_traits {
579
+ let trait_did = trait_candidate. def_id ;
572
580
if duplicates. insert ( trait_did) {
573
- try!( self . assemble_extension_candidates_for_trait ( trait_did) ) ;
581
+ self . import_id = trait_candidate. import_id ;
582
+ let result = self . assemble_extension_candidates_for_trait ( trait_did) ;
583
+ self . import_id = None ;
584
+ try!( result) ;
574
585
}
575
586
}
576
587
}
@@ -670,7 +681,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
670
681
self . extension_candidates . push ( Candidate {
671
682
xform_self_ty : xform_self_ty,
672
683
item : item. clone ( ) ,
673
- kind : ExtensionImplCandidate ( impl_def_id, impl_substs, obligations)
684
+ kind : ExtensionImplCandidate ( impl_def_id, impl_substs, obligations) ,
685
+ import_id : self . import_id ,
674
686
} ) ;
675
687
} ) ;
676
688
}
@@ -745,7 +757,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
745
757
self . inherent_candidates . push ( Candidate {
746
758
xform_self_ty : xform_self_ty,
747
759
item : item. clone ( ) ,
748
- kind : TraitCandidate
760
+ kind : TraitCandidate ,
761
+ import_id : self . import_id ,
749
762
} ) ;
750
763
}
751
764
@@ -802,7 +815,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
802
815
self . extension_candidates . push ( Candidate {
803
816
xform_self_ty : xform_self_ty,
804
817
item : item. clone ( ) ,
805
- kind : TraitCandidate
818
+ kind : TraitCandidate ,
819
+ import_id : self . import_id ,
806
820
} ) ;
807
821
}
808
822
}
@@ -833,7 +847,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
833
847
self . extension_candidates . push ( Candidate {
834
848
xform_self_ty : xform_self_ty,
835
849
item : item. clone ( ) ,
836
- kind : WhereClauseCandidate ( poly_bound)
850
+ kind : WhereClauseCandidate ( poly_bound) ,
851
+ import_id : self . import_id ,
837
852
} ) ;
838
853
}
839
854
}
@@ -1126,6 +1141,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
1126
1141
Some ( Pick {
1127
1142
item : probes[ 0 ] . item . clone ( ) ,
1128
1143
kind : TraitPick ,
1144
+ import_id : probes[ 0 ] . import_id ,
1129
1145
autoderefs : 0 ,
1130
1146
autoref : None ,
1131
1147
unsize : None
@@ -1329,6 +1345,7 @@ impl<'tcx> Candidate<'tcx> {
1329
1345
WhereClausePick ( trait_ref. clone ( ) )
1330
1346
}
1331
1347
} ,
1348
+ import_id : self . import_id ,
1332
1349
autoderefs : 0 ,
1333
1350
autoref : None ,
1334
1351
unsize : None
0 commit comments