Skip to content

Commit 5c537df

Browse files
committed
Ignore auto-deref for multiple crate version note
As per the case presented in #128569, we should be showing the extra info even if auto-deref is involved.
1 parent 6e54d29 commit 5c537df

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+17-14
Original file line numberDiff line numberDiff line change
@@ -3449,7 +3449,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
34493449
trait_missing_method: bool,
34503450
) {
34513451
let mut alt_rcvr_sugg = false;
3452-
let mut suggest = true;
3452+
let mut trait_in_other_version_found = false;
34533453
if let (SelfSource::MethodCall(rcvr), false) = (source, unsatisfied_bounds) {
34543454
debug!(
34553455
"suggest_traits_to_import: span={:?}, item_name={:?}, rcvr_ty={:?}, rcvr={:?}",
@@ -3491,21 +3491,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
34913491
// self types and rely on the suggestion to `use` the trait from
34923492
// `suggest_valid_traits`.
34933493
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(
34973499
err,
34983500
pick.item.def_id,
34993501
pick.item.ident(self.tcx).span,
35003502
rcvr.hir_id.owner,
35013503
*rcvr_ty,
35023504
);
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+
);
35093510
}
35103511
break;
35113512
}
@@ -3702,15 +3703,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
37023703
// `Trait` that is imported directly, but `Type` came from a different version of the
37033704
// same crate.
37043705
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(
37063707
err,
37073708
assoc.def_id,
37083709
self.tcx.def_span(assoc.def_id),
37093710
ty.hir_id.owner,
37103711
rcvr_ty,
37113712
);
37123713
}
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+
{
37143717
return;
37153718
}
37163719

@@ -4120,14 +4123,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
41204123
format!("the method is available for `{rcvr_ty}` here"),
41214124
);
41224125
err.span_note(multi_span, msg);
4123-
return false;
41244126
} else {
41254127
err.note(msg);
41264128
}
4129+
return true;
41274130
}
41284131
}
41294132
}
4130-
true
4133+
false
41314134
}
41324135

41334136
/// issue #102320, for `unwrap_or` with closure as argument, suggest `unwrap_or_else`

0 commit comments

Comments
 (0)