@@ -44,7 +44,6 @@ struct ProbeContext<'a, 'tcx:'a> {
4444 extension_candidates : Vec < Candidate < ' tcx > > ,
4545 impl_dups : HashSet < ast:: DefId > ,
4646 static_candidates : Vec < CandidateSource > ,
47- all_traits_search : bool ,
4847}
4948
5049struct CandidateStep < ' tcx > {
@@ -211,7 +210,6 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
211210 steps : Rc :: new ( steps) ,
212211 opt_simplified_steps : opt_simplified_steps,
213212 static_candidates : Vec :: new ( ) ,
214- all_traits_search : false ,
215213 }
216214 }
217215
@@ -724,60 +722,53 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
724722 // THE ACTUAL SEARCH
725723
726724 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 => { }
736728 }
737729
738730 let static_candidates = mem:: replace ( & mut self . static_candidates , vec ! [ ] ) ;
739731
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" )
763751 }
764752 }
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 ! [ ]
771753 }
754+ } ) . collect ( ) ,
755+ Some ( Err ( NoMatch ( _, others) ) ) => {
756+ assert ! ( others. is_empty( ) ) ;
757+ vec ! [ ]
772758 }
773- } else {
774- // we've just looked through all traits and didn't find
775- // anything at all.
776- vec ! [ ]
759+ None => vec ! [ ] ,
777760 } ;
761+ ;
778762 Err ( NoMatch ( static_candidates, out_of_scope_traits) )
779763 }
780764
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+
781772 fn pick_step ( & mut self , step : & CandidateStep < ' tcx > ) -> Option < PickResult < ' tcx > > {
782773 debug ! ( "pick_step: step={}" , step. repr( self . tcx( ) ) ) ;
783774
0 commit comments