1
Fork 0

best_blame_constraint: avoid blaming constraints from MIR generated by desugaring

This commit is contained in:
dianne 2024-12-13 08:04:15 -08:00
parent 2864906fce
commit 31e4d8175a
7 changed files with 36 additions and 33 deletions

View file

@ -22,6 +22,7 @@ use rustc_middle::ty::fold::fold_regions;
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable, UniverseIndex};
use rustc_mir_dataflow::points::DenseLocationMap;
use rustc_span::Span;
use rustc_span::hygiene::DesugaringKind;
use tracing::{debug, instrument, trace};
use crate::BorrowckInferCtxt;
@ -2033,7 +2034,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
| ConstraintCategory::BoringNoLocation
| ConstraintCategory::Internal
| ConstraintCategory::Predicate(_)
)
) && constraint.span.desugaring_kind().is_none_or(|kind| {
// Try to avoid blaming constraints from desugarings, since they may not clearly
// clearly match what users have written. As an exception, allow blaming returns
// generated by `?` desugaring, since the correspondence is fairly clear.
kind == DesugaringKind::QuestionMark
&& matches!(constraint.category, ConstraintCategory::Return(_))
})
};
let best_choice = if blame_source {