Rollup merge of #113945 - chenyukang:yukang-fix-113447-slice-2, r=cjgillot
Fix wrong span for trait selection failure error reporting Fixes #113447
This commit is contained in:
commit
5054e41b64
5 changed files with 88 additions and 3 deletions
|
@ -2987,6 +2987,14 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
unsatisfied_const: bool,
|
||||
) {
|
||||
let body_def_id = obligation.cause.body_id;
|
||||
let span = if let ObligationCauseCode::BinOp { rhs_span: Some(rhs_span), .. } =
|
||||
obligation.cause.code()
|
||||
{
|
||||
*rhs_span
|
||||
} else {
|
||||
span
|
||||
};
|
||||
|
||||
// Try to report a help message
|
||||
if is_fn_trait
|
||||
&& let Ok((implemented_kind, params)) = self.type_implements_fn_trait(
|
||||
|
|
|
@ -3953,9 +3953,11 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
candidate_impls: &[ImplCandidate<'tcx>],
|
||||
span: Span,
|
||||
) {
|
||||
// We can only suggest the slice coersion for function arguments since the suggestion
|
||||
// would make no sense in turbofish or call
|
||||
let ObligationCauseCode::FunctionArgumentObligation { .. } = obligation.cause.code() else {
|
||||
// We can only suggest the slice coersion for function and binary operation arguments,
|
||||
// since the suggestion would make no sense in turbofish or call
|
||||
let (ObligationCauseCode::BinOp { .. }
|
||||
| ObligationCauseCode::FunctionArgumentObligation { .. }) = obligation.cause.code()
|
||||
else {
|
||||
return;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue