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.
This commit is contained in:
parent
eeb72835d2
commit
4e985534e8
@ -3448,7 +3448,7 @@ fn suggest_traits_to_import(
|
|||||||
trait_missing_method: bool,
|
trait_missing_method: bool,
|
||||||
) {
|
) {
|
||||||
let mut alt_rcvr_sugg = false;
|
let mut alt_rcvr_sugg = false;
|
||||||
let mut suggest = true;
|
let mut trait_in_other_version_found = false;
|
||||||
if let (SelfSource::MethodCall(rcvr), false) = (source, unsatisfied_bounds) {
|
if let (SelfSource::MethodCall(rcvr), false) = (source, unsatisfied_bounds) {
|
||||||
debug!(
|
debug!(
|
||||||
"suggest_traits_to_import: span={:?}, item_name={:?}, rcvr_ty={:?}, rcvr={:?}",
|
"suggest_traits_to_import: span={:?}, item_name={:?}, rcvr_ty={:?}, rcvr={:?}",
|
||||||
@ -3490,22 +3490,23 @@ fn suggest_traits_to_import(
|
|||||||
// self types and rely on the suggestion to `use` the trait from
|
// self types and rely on the suggestion to `use` the trait from
|
||||||
// `suggest_valid_traits`.
|
// `suggest_valid_traits`.
|
||||||
let did = Some(pick.item.container_id(self.tcx));
|
let did = Some(pick.item.container_id(self.tcx));
|
||||||
let skip = skippable.contains(&did);
|
if skippable.contains(&did) {
|
||||||
if pick.autoderefs == 0 && !skip {
|
continue;
|
||||||
suggest = self.detect_and_explain_multiple_crate_versions(
|
}
|
||||||
|
trait_in_other_version_found = self
|
||||||
|
.detect_and_explain_multiple_crate_versions(
|
||||||
err,
|
err,
|
||||||
pick.item.def_id,
|
pick.item.def_id,
|
||||||
pick.item.ident(self.tcx).span,
|
pick.item.ident(self.tcx).span,
|
||||||
rcvr.hir_id.owner,
|
rcvr.hir_id.owner,
|
||||||
*rcvr_ty,
|
*rcvr_ty,
|
||||||
);
|
);
|
||||||
if suggest {
|
if pick.autoderefs == 0 && !trait_in_other_version_found {
|
||||||
err.span_label(
|
err.span_label(
|
||||||
pick.item.ident(self.tcx).span,
|
pick.item.ident(self.tcx).span,
|
||||||
format!("the method is available for `{rcvr_ty}` here"),
|
format!("the method is available for `{rcvr_ty}` here"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Err(MethodError::Ambiguity(_)) => {
|
Err(MethodError::Ambiguity(_)) => {
|
||||||
@ -3701,7 +3702,7 @@ fn suggest_traits_to_import(
|
|||||||
// `Trait` that is imported directly, but `Type` came from a different version of the
|
// `Trait` that is imported directly, but `Type` came from a different version of the
|
||||||
// same crate.
|
// same crate.
|
||||||
let rcvr_ty = self.tcx.type_of(def_id).instantiate_identity();
|
let rcvr_ty = self.tcx.type_of(def_id).instantiate_identity();
|
||||||
suggest = self.detect_and_explain_multiple_crate_versions(
|
trait_in_other_version_found = self.detect_and_explain_multiple_crate_versions(
|
||||||
err,
|
err,
|
||||||
assoc.def_id,
|
assoc.def_id,
|
||||||
self.tcx.def_span(assoc.def_id),
|
self.tcx.def_span(assoc.def_id),
|
||||||
@ -3709,7 +3710,9 @@ fn suggest_traits_to_import(
|
|||||||
rcvr_ty,
|
rcvr_ty,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if suggest && self.suggest_valid_traits(err, item_name, valid_out_of_scope_traits, true) {
|
if !trait_in_other_version_found
|
||||||
|
&& self.suggest_valid_traits(err, item_name, valid_out_of_scope_traits, true)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4119,14 +4122,14 @@ fn detect_and_explain_multiple_crate_versions(
|
|||||||
format!("the method is available for `{rcvr_ty}` here"),
|
format!("the method is available for `{rcvr_ty}` here"),
|
||||||
);
|
);
|
||||||
err.span_note(multi_span, msg);
|
err.span_note(multi_span, msg);
|
||||||
return false;
|
|
||||||
} else {
|
} else {
|
||||||
err.note(msg);
|
err.note(msg);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
true
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// issue #102320, for `unwrap_or` with closure as argument, suggest `unwrap_or_else`
|
/// issue #102320, for `unwrap_or` with closure as argument, suggest `unwrap_or_else`
|
||||||
|
Loading…
Reference in New Issue
Block a user