@@ -369,6 +369,24 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
369
369
///////////////////////////////////////////////////////////////////////////
370
370
// CANDIDATE ASSEMBLY
371
371
372
+ fn push_inherent_candidate ( & mut self , xform_self_ty : Ty < ' tcx > , item : ty:: AssociatedItem ,
373
+ kind : CandidateKind < ' tcx > , import_id : Option < ast:: NodeId > ) {
374
+ if self . tcx . vis_is_accessible_from ( item. vis , self . body_id ) {
375
+ self . inherent_candidates . push ( Candidate { xform_self_ty, item, kind, import_id } ) ;
376
+ } else if self . private_candidate . is_none ( ) {
377
+ self . private_candidate = Some ( item. def ( ) ) ;
378
+ }
379
+ }
380
+
381
+ fn push_extension_candidate ( & mut self , xform_self_ty : Ty < ' tcx > , item : ty:: AssociatedItem ,
382
+ kind : CandidateKind < ' tcx > , import_id : Option < ast:: NodeId > ) {
383
+ if self . tcx . vis_is_accessible_from ( item. vis , self . body_id ) {
384
+ self . extension_candidates . push ( Candidate { xform_self_ty, item, kind, import_id } ) ;
385
+ } else if self . private_candidate . is_none ( ) {
386
+ self . private_candidate = Some ( item. def ( ) ) ;
387
+ }
388
+ }
389
+
372
390
fn assemble_inherent_candidates ( & mut self ) {
373
391
let steps = self . steps . clone ( ) ;
374
392
for step in steps. iter ( ) {
@@ -499,11 +517,6 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
499
517
continue
500
518
}
501
519
502
- if !self . tcx . vis_is_accessible_from ( item. vis , self . body_id ) {
503
- self . private_candidate = Some ( item. def ( ) ) ;
504
- continue
505
- }
506
-
507
520
let ( impl_ty, impl_substs) = self . impl_ty_and_substs ( impl_def_id) ;
508
521
let impl_ty = impl_ty. subst ( self . tcx , impl_substs) ;
509
522
@@ -519,12 +532,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
519
532
debug ! ( "assemble_inherent_impl_probe: xform_self_ty = {:?}" ,
520
533
xform_self_ty) ;
521
534
522
- self . inherent_candidates . push ( Candidate {
523
- xform_self_ty : xform_self_ty,
524
- item : item,
525
- kind : InherentImplCandidate ( impl_substs, obligations) ,
526
- import_id : None ,
527
- } ) ;
535
+ self . push_inherent_candidate ( xform_self_ty, item,
536
+ InherentImplCandidate ( impl_substs, obligations) , None ) ;
528
537
}
529
538
}
530
539
@@ -548,12 +557,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
548
557
let xform_self_ty =
549
558
this. xform_self_ty ( & item, new_trait_ref. self_ty ( ) , new_trait_ref. substs ) ;
550
559
551
- this. inherent_candidates . push ( Candidate {
552
- xform_self_ty : xform_self_ty,
553
- item : item,
554
- kind : ObjectCandidate ,
555
- import_id : None ,
556
- } ) ;
560
+ this. push_inherent_candidate ( xform_self_ty, item, ObjectCandidate , None ) ;
557
561
} ) ;
558
562
}
559
563
@@ -599,12 +603,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
599
603
// `WhereClausePick`.
600
604
assert ! ( !trait_ref. substs. needs_infer( ) ) ;
601
605
602
- this. inherent_candidates . push ( Candidate {
603
- xform_self_ty : xform_self_ty,
604
- item : item,
605
- kind : WhereClauseCandidate ( poly_trait_ref) ,
606
- import_id : None ,
607
- } ) ;
606
+ this. push_inherent_candidate ( xform_self_ty, item,
607
+ WhereClauseCandidate ( poly_trait_ref) , None ) ;
608
608
} ) ;
609
609
}
610
610
@@ -743,12 +743,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
743
743
744
744
debug ! ( "xform_self_ty={:?}" , xform_self_ty) ;
745
745
746
- self . extension_candidates . push ( Candidate {
747
- xform_self_ty : xform_self_ty,
748
- item : item. clone ( ) ,
749
- kind : ExtensionImplCandidate ( impl_def_id, impl_substs, obligations) ,
750
- import_id : import_id,
751
- } ) ;
746
+ self . push_extension_candidate ( xform_self_ty, item,
747
+ ExtensionImplCandidate ( impl_def_id, impl_substs, obligations) , import_id) ;
752
748
} ) ;
753
749
}
754
750
@@ -833,12 +829,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
833
829
} ) ;
834
830
835
831
let xform_self_ty = self . xform_self_ty ( & item, step. self_ty , substs) ;
836
- self . inherent_candidates . push ( Candidate {
837
- xform_self_ty : xform_self_ty,
838
- item : item. clone ( ) ,
839
- kind : TraitCandidate ,
840
- import_id : import_id,
841
- } ) ;
832
+ self . push_inherent_candidate ( xform_self_ty, item, TraitCandidate , import_id) ;
842
833
}
843
834
844
835
Ok ( ( ) )
@@ -854,7 +845,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
854
845
trait_def_id,
855
846
item) ;
856
847
857
- for step in self . steps . iter ( ) {
848
+ for step in Rc :: clone ( & self . steps ) . iter ( ) {
858
849
debug ! ( "assemble_projection_candidates: step={:?}" , step) ;
859
850
860
851
let ( def_id, substs) = match step. self_ty . sty {
@@ -889,12 +880,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
889
880
bound,
890
881
xform_self_ty) ;
891
882
892
- self . extension_candidates . push ( Candidate {
893
- xform_self_ty : xform_self_ty,
894
- item : item. clone ( ) ,
895
- kind : TraitCandidate ,
896
- import_id : import_id,
897
- } ) ;
883
+ self . push_extension_candidate ( xform_self_ty, item, TraitCandidate , import_id) ;
898
884
}
899
885
}
900
886
}
@@ -918,12 +904,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
918
904
bound,
919
905
xform_self_ty) ;
920
906
921
- self . extension_candidates . push ( Candidate {
922
- xform_self_ty : xform_self_ty,
923
- item : item. clone ( ) ,
924
- kind : WhereClauseCandidate ( poly_bound) ,
925
- import_id : import_id,
926
- } ) ;
907
+ self . push_extension_candidate ( xform_self_ty, item,
908
+ WhereClauseCandidate ( poly_bound) , import_id) ;
927
909
}
928
910
}
929
911
0 commit comments