@@ -44,7 +44,6 @@ struct ProbeContext<'a, 'tcx:'a> {
44
44
extension_candidates : Vec < Candidate < ' tcx > > ,
45
45
impl_dups : HashSet < ast:: DefId > ,
46
46
static_candidates : Vec < CandidateSource > ,
47
- all_traits_search : bool ,
48
47
}
49
48
50
49
struct CandidateStep < ' tcx > {
@@ -211,7 +210,6 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
211
210
steps : Rc :: new ( steps) ,
212
211
opt_simplified_steps : opt_simplified_steps,
213
212
static_candidates : Vec :: new ( ) ,
214
- all_traits_search : false ,
215
213
}
216
214
}
217
215
@@ -724,60 +722,53 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
724
722
// THE ACTUAL SEARCH
725
723
726
724
fn pick ( mut self ) -> PickResult < ' tcx > {
727
- let steps = self . steps . clone ( ) ;
728
-
729
- for step in steps. iter ( ) {
730
- match self . pick_step ( step) {
731
- Some ( r) => {
732
- return r;
733
- }
734
- None => { }
735
- }
725
+ match self . pick_core ( ) {
726
+ Some ( r) => return r,
727
+ None => { }
736
728
}
737
729
738
730
let static_candidates = mem:: replace ( & mut self . static_candidates , vec ! [ ] ) ;
739
731
740
- let out_of_scope_traits = if !self . all_traits_search {
741
- // things failed, and we haven't yet looked through all
742
- // traits, so lets do that now:
743
- self . reset ( ) ;
744
- self . all_traits_search = true ;
745
-
746
- let span = self . span ;
747
- let tcx = self . tcx ( ) ;
748
-
749
- self . assemble_extension_candidates_for_all_traits ( ) ;
750
-
751
- match self . pick ( ) {
752
- Ok ( p) => vec ! [ p. method_ty. container. id( ) ] ,
753
- Err ( Ambiguity ( v) ) => v. into_iter ( ) . map ( |source| {
754
- match source {
755
- TraitSource ( id) => id,
756
- ImplSource ( impl_id) => {
757
- match ty:: trait_id_of_impl ( tcx, impl_id) {
758
- Some ( id) => id,
759
- None => tcx. sess . span_bug ( span,
760
- "found inherent method when looking \
761
- at traits")
762
- }
732
+ // things failed, so lets look at all traits, for diagnostic purposes now:
733
+ self . reset ( ) ;
734
+
735
+ let span = self . span ;
736
+ let tcx = self . tcx ( ) ;
737
+
738
+ self . assemble_extension_candidates_for_all_traits ( ) ;
739
+
740
+ let out_of_scope_traits = match self . pick_core ( ) {
741
+ Some ( Ok ( p) ) => vec ! [ p. method_ty. container. id( ) ] ,
742
+ Some ( Err ( Ambiguity ( v) ) ) => v. into_iter ( ) . map ( |source| {
743
+ match source {
744
+ TraitSource ( id) => id,
745
+ ImplSource ( impl_id) => {
746
+ match ty:: trait_id_of_impl ( tcx, impl_id) {
747
+ Some ( id) => id,
748
+ None =>
749
+ tcx. sess . span_bug ( span,
750
+ "found inherent method when looking at traits" )
763
751
}
764
752
}
765
- } ) . collect ( ) ,
766
- // it'd be really weird for this assertion to trigger,
767
- // given the `vec![]` in the else branch below
768
- Err ( NoMatch ( _, others) ) => {
769
- assert ! ( others. is_empty( ) ) ;
770
- vec ! [ ]
771
753
}
754
+ } ) . collect ( ) ,
755
+ Some ( Err ( NoMatch ( _, others) ) ) => {
756
+ assert ! ( others. is_empty( ) ) ;
757
+ vec ! [ ]
772
758
}
773
- } else {
774
- // we've just looked through all traits and didn't find
775
- // anything at all.
776
- vec ! [ ]
759
+ None => vec ! [ ] ,
777
760
} ;
761
+ ;
778
762
Err ( NoMatch ( static_candidates, out_of_scope_traits) )
779
763
}
780
764
765
+ fn pick_core ( & mut self ) -> Option < PickResult < ' tcx > > {
766
+ let steps = self . steps . clone ( ) ;
767
+
768
+ // find the first step that works
769
+ steps. iter ( ) . filter_map ( |step| self . pick_step ( step) ) . next ( )
770
+ }
771
+
781
772
fn pick_step ( & mut self , step : & CandidateStep < ' tcx > ) -> Option < PickResult < ' tcx > > {
782
773
debug ! ( "pick_step: step={}" , step. repr( self . tcx( ) ) ) ;
783
774
0 commit comments