@@ -3449,7 +3449,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3449
3449
trait_missing_method : bool ,
3450
3450
) {
3451
3451
let mut alt_rcvr_sugg = false ;
3452
- let mut suggest = true ;
3452
+ let mut trait_in_other_version_found = false ;
3453
3453
if let ( SelfSource :: MethodCall ( rcvr) , false ) = ( source, unsatisfied_bounds) {
3454
3454
debug ! (
3455
3455
"suggest_traits_to_import: span={:?}, item_name={:?}, rcvr_ty={:?}, rcvr={:?}" ,
@@ -3491,21 +3491,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3491
3491
// self types and rely on the suggestion to `use` the trait from
3492
3492
// `suggest_valid_traits`.
3493
3493
let did = Some ( pick. item . container_id ( self . tcx ) ) ;
3494
- let skip = skippable. contains ( & did) ;
3495
- if pick. autoderefs == 0 && !skip {
3496
- suggest = self . detect_and_explain_multiple_crate_versions (
3494
+ if skippable. contains ( & did) {
3495
+ continue ;
3496
+ }
3497
+ trait_in_other_version_found = self
3498
+ . detect_and_explain_multiple_crate_versions (
3497
3499
err,
3498
3500
pick. item . def_id ,
3499
3501
pick. item . ident ( self . tcx ) . span ,
3500
3502
rcvr. hir_id . owner ,
3501
3503
* rcvr_ty,
3502
3504
) ;
3503
- if suggest {
3504
- err. span_label (
3505
- pick. item . ident ( self . tcx ) . span ,
3506
- format ! ( "the method is available for `{rcvr_ty}` here" ) ,
3507
- ) ;
3508
- }
3505
+ if pick. autoderefs == 0 && !trait_in_other_version_found {
3506
+ err. span_label (
3507
+ pick. item . ident ( self . tcx ) . span ,
3508
+ format ! ( "the method is available for `{rcvr_ty}` here" ) ,
3509
+ ) ;
3509
3510
}
3510
3511
break ;
3511
3512
}
@@ -3702,15 +3703,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3702
3703
// `Trait` that is imported directly, but `Type` came from a different version of the
3703
3704
// same crate.
3704
3705
let rcvr_ty = self . tcx . type_of ( def_id) . instantiate_identity ( ) ;
3705
- suggest = self . detect_and_explain_multiple_crate_versions (
3706
+ trait_in_other_version_found = self . detect_and_explain_multiple_crate_versions (
3706
3707
err,
3707
3708
assoc. def_id ,
3708
3709
self . tcx . def_span ( assoc. def_id ) ,
3709
3710
ty. hir_id . owner ,
3710
3711
rcvr_ty,
3711
3712
) ;
3712
3713
}
3713
- if suggest && self . suggest_valid_traits ( err, item_name, valid_out_of_scope_traits, true ) {
3714
+ if !trait_in_other_version_found
3715
+ && self . suggest_valid_traits ( err, item_name, valid_out_of_scope_traits, true )
3716
+ {
3714
3717
return ;
3715
3718
}
3716
3719
@@ -4120,14 +4123,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4120
4123
format ! ( "the method is available for `{rcvr_ty}` here" ) ,
4121
4124
) ;
4122
4125
err. span_note ( multi_span, msg) ;
4123
- return false ;
4124
4126
} else {
4125
4127
err. note ( msg) ;
4126
4128
}
4129
+ return true ;
4127
4130
}
4128
4131
}
4129
4132
}
4130
- true
4133
+ false
4131
4134
}
4132
4135
4133
4136
/// issue #102320, for `unwrap_or` with closure as argument, suggest `unwrap_or_else`
0 commit comments