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