@@ -2,11 +2,10 @@ pub mod on_unimplemented;
22pub mod suggestions;
33
44use super :: {
5- DerivedObligationCause , EvaluationResult , FulfillmentContext , FulfillmentError ,
6- FulfillmentErrorCode , ImplDerivedObligationCause , MismatchedProjectionTypes , Obligation ,
7- ObligationCause , ObligationCauseCode , OnUnimplementedDirective , OnUnimplementedNote ,
8- OutputTypeParameterMismatch , Overflow , PredicateObligation , SelectionContext , SelectionError ,
9- TraitNotObjectSafe ,
5+ EvaluationResult , FulfillmentContext , FulfillmentError , FulfillmentErrorCode ,
6+ MismatchedProjectionTypes , Obligation , ObligationCause , ObligationCauseCode ,
7+ OnUnimplementedDirective , OnUnimplementedNote , OutputTypeParameterMismatch , Overflow ,
8+ PredicateObligation , SelectionContext , SelectionError , TraitNotObjectSafe ,
109} ;
1110
1211use crate :: infer:: error_reporting:: { TyCategory , TypeAnnotationNeeded as ErrorCode } ;
@@ -661,77 +660,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
661660 } else if !suggested {
662661 // Can't show anything else useful, try to find similar impls.
663662 let impl_candidates = self . find_similar_impl_candidates ( trait_ref) ;
664- if ! self . report_similar_impl_candidates (
663+ self . report_similar_impl_candidates (
665664 impl_candidates,
666665 trait_ref,
667666 & mut err,
668- ) {
669- // This is *almost* equivalent to
670- // `obligation.cause.code().peel_derives()`, but it gives us the
671- // trait predicate for that corresponding root obligation. This
672- // lets us get a derived obligation from a type parameter, like
673- // when calling `string.strip_suffix(p)` where `p` is *not* an
674- // implementer of `Pattern<'_>`.
675- let mut code = obligation. cause . code ( ) ;
676- let mut trait_pred = trait_predicate;
677- let mut peeled = false ;
678- loop {
679- match & * code {
680- ObligationCauseCode :: FunctionArgumentObligation {
681- parent_code,
682- ..
683- } => {
684- code = & parent_code;
685- }
686- ObligationCauseCode :: ImplDerivedObligation (
687- box ImplDerivedObligationCause {
688- derived :
689- DerivedObligationCause {
690- parent_code,
691- parent_trait_pred,
692- } ,
693- ..
694- } ,
695- )
696- | ObligationCauseCode :: BuiltinDerivedObligation (
697- DerivedObligationCause {
698- parent_code,
699- parent_trait_pred,
700- } ,
701- )
702- | ObligationCauseCode :: DerivedObligation (
703- DerivedObligationCause {
704- parent_code,
705- parent_trait_pred,
706- } ,
707- ) => {
708- peeled = true ;
709- code = & parent_code;
710- trait_pred = * parent_trait_pred;
711- }
712- _ => break ,
713- } ;
714- }
715- let def_id = trait_pred. def_id ( ) ;
716- // Mention *all* the `impl`s for the *top most* obligation, the
717- // user might have meant to use one of them, if any found. We skip
718- // auto-traits or fundamental traits that might not be exactly what
719- // the user might expect to be presented with. Instead this is
720- // useful for less general traits.
721- if peeled
722- && !self . tcx . trait_is_auto ( def_id)
723- && !self . tcx . lang_items ( ) . items ( ) . contains ( & Some ( def_id) )
724- {
725- let trait_ref = trait_pred. to_poly_trait_ref ( ) ;
726- let impl_candidates =
727- self . find_similar_impl_candidates ( trait_ref) ;
728- self . report_similar_impl_candidates (
729- impl_candidates,
730- trait_ref,
731- & mut err,
732- ) ;
733- }
734- }
667+ ) ;
735668 }
736669
737670 // Changing mutability doesn't make a difference to whether we have
0 commit comments