1
Fork 0

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:
Matthias Krüger 2023-08-04 21:31:55 +02:00 committed by GitHub
commit 5054e41b64
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 88 additions and 3 deletions

View file

@ -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(

View file

@ -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;
};