@@ -3448,7 +3448,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
34483448 trait_missing_method : bool ,
34493449 ) {
34503450 let mut alt_rcvr_sugg = false ;
3451- let mut suggest = true ;
3451+ let mut trait_in_other_version_found = false ;
34523452 if let ( SelfSource :: MethodCall ( rcvr) , false ) = ( source, unsatisfied_bounds) {
34533453 debug ! (
34543454 "suggest_traits_to_import: span={:?}, item_name={:?}, rcvr_ty={:?}, rcvr={:?}" ,
@@ -3490,21 +3490,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
34903490 // self types and rely on the suggestion to `use` the trait from
34913491 // `suggest_valid_traits`.
34923492 let did = Some ( pick. item . container_id ( self . tcx ) ) ;
3493- let skip = skippable. contains ( & did) ;
3494- if pick. autoderefs == 0 && !skip {
3495- suggest = self . detect_and_explain_multiple_crate_versions (
3493+ if skippable. contains ( & did) {
3494+ continue ;
3495+ }
3496+ trait_in_other_version_found = self
3497+ . detect_and_explain_multiple_crate_versions (
34963498 err,
34973499 pick. item . def_id ,
34983500 pick. item . ident ( self . tcx ) . span ,
34993501 rcvr. hir_id . owner ,
35003502 * rcvr_ty,
35013503 ) ;
3502- if suggest {
3503- err. span_label (
3504- pick. item . ident ( self . tcx ) . span ,
3505- format ! ( "the method is available for `{rcvr_ty}` here" ) ,
3506- ) ;
3507- }
3504+ if pick. autoderefs == 0 && !trait_in_other_version_found {
3505+ err. span_label (
3506+ pick. item . ident ( self . tcx ) . span ,
3507+ format ! ( "the method is available for `{rcvr_ty}` here" ) ,
3508+ ) ;
35083509 }
35093510 break ;
35103511 }
@@ -3701,15 +3702,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
37013702 // `Trait` that is imported directly, but `Type` came from a different version of the
37023703 // same crate.
37033704 let rcvr_ty = self . tcx . type_of ( def_id) . instantiate_identity ( ) ;
3704- suggest = self . detect_and_explain_multiple_crate_versions (
3705+ trait_in_other_version_found = self . detect_and_explain_multiple_crate_versions (
37053706 err,
37063707 assoc. def_id ,
37073708 self . tcx . def_span ( assoc. def_id ) ,
37083709 ty. hir_id . owner ,
37093710 rcvr_ty,
37103711 ) ;
37113712 }
3712- if suggest && self . suggest_valid_traits ( err, item_name, valid_out_of_scope_traits, true ) {
3713+ if !trait_in_other_version_found
3714+ && self . suggest_valid_traits ( err, item_name, valid_out_of_scope_traits, true )
3715+ {
37133716 return ;
37143717 }
37153718
@@ -4119,14 +4122,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
41194122 format ! ( "the method is available for `{rcvr_ty}` here" ) ,
41204123 ) ;
41214124 err. span_note ( multi_span, msg) ;
4122- return false ;
41234125 } else {
41244126 err. note ( msg) ;
41254127 }
4128+ return true ;
41264129 }
41274130 }
41284131 }
4129- true
4132+ false
41304133 }
41314134
41324135 /// issue #102320, for `unwrap_or` with closure as argument, suggest `unwrap_or_else`
0 commit comments