Auto merge of #126996 - oli-obk:do_not_count_errors, r=nnethercote
Automatically taint InferCtxt when errors are emitted r? `@nnethercote` Basically `InferCtxt::dcx` now returns a `DiagCtxt` that refers back to the `Cell<Option<ErrorGuaranteed>>` of the `InferCtxt` and thus when invoking `Diag::emit`, and the diagnostic is an error, we taint the `InferCtxt` directly. That change on its own has no effect at all, because `InferCtxt` already tracks whether errors have been emitted by recording the global error count when it gets opened, and checking at the end whether the count changed. So I removed that error count check, which had a bit of fallout that I immediately fixed by invoking `InferCtxt::dcx` instead of `TyCtxt::dcx` in a bunch of places. The remaining new errors are because an error was reported in another query, and never bubbled up. I think they are minor enough for this to be ok, and sometimes it actually improves diagnostics, by not silencing useful diagnostics anymore. fixes #126485 (cc `@olafes)` There are more improvements we can do (like tainting in hir ty lowering), but I would rather do that in follow up PRs, because it requires some refactorings.
This commit is contained in:
commit
7b21c18fe4
77 changed files with 899 additions and 829 deletions
|
@ -88,7 +88,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
found_args: Vec<ArgKind>,
|
||||
is_closure: bool,
|
||||
closure_arg_span: Option<Span>,
|
||||
) -> Diag<'tcx> {
|
||||
) -> Diag<'_> {
|
||||
let kind = if is_closure { "closure" } else { "function" };
|
||||
|
||||
let args_str = |arguments: &[ArgKind], other: &[ArgKind]| {
|
||||
|
|
|
@ -241,8 +241,8 @@ pub fn suggest_restriction<'tcx, G: EmissionGuarantee>(
|
|||
}
|
||||
}
|
||||
|
||||
#[extension(pub trait TypeErrCtxtExt<'tcx>)]
|
||||
impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
#[extension(pub trait TypeErrCtxtExt<'a, 'tcx>)]
|
||||
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
fn suggest_restricting_param_bound(
|
||||
&self,
|
||||
err: &mut Diag<'_>,
|
||||
|
@ -1845,7 +1845,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
|
||||
fn point_at_returns_when_relevant(
|
||||
&self,
|
||||
err: &mut Diag<'tcx>,
|
||||
err: &mut Diag<'_>,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
) {
|
||||
match obligation.cause.code().peel_derives() {
|
||||
|
@ -1884,7 +1884,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
cause: &ObligationCauseCode<'tcx>,
|
||||
found_node: Option<Node<'_>>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
) -> Diag<'tcx> {
|
||||
) -> Diag<'a> {
|
||||
pub(crate) fn build_fn_sig_ty<'tcx>(
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
trait_ref: ty::TraitRef<'tcx>,
|
||||
|
@ -2104,7 +2104,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
fn note_conflicting_closure_bounds(
|
||||
&self,
|
||||
cause: &ObligationCauseCode<'tcx>,
|
||||
err: &mut Diag<'tcx>,
|
||||
err: &mut Diag<'_>,
|
||||
) {
|
||||
// First, look for an `WhereClauseInExpr`, which means we can get
|
||||
// the uninstantiated predicate list of the called function. And check
|
||||
|
|
|
@ -82,8 +82,8 @@ pub fn suggest_new_overflow_limit<'tcx, G: EmissionGuarantee>(
|
|||
));
|
||||
}
|
||||
|
||||
#[extension(pub trait TypeErrCtxtExt<'tcx>)]
|
||||
impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
#[extension(pub trait TypeErrCtxtExt<'a, 'tcx>)]
|
||||
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
fn report_fulfillment_errors(
|
||||
&self,
|
||||
mut errors: Vec<FulfillmentError<'tcx>>,
|
||||
|
@ -228,7 +228,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
cause: OverflowCause<'tcx>,
|
||||
span: Span,
|
||||
suggest_increasing_limit: bool,
|
||||
) -> Diag<'tcx> {
|
||||
) -> Diag<'a> {
|
||||
fn with_short_path<'tcx, T>(tcx: TyCtxt<'tcx>, value: T) -> String
|
||||
where
|
||||
T: fmt::Display + Print<'tcx, FmtPrinter<'tcx, 'tcx>>,
|
||||
|
@ -1101,7 +1101,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
&& let ty::FnPtr(sig) = by_ref_captures.kind()
|
||||
&& !sig.skip_binder().output().is_unit()
|
||||
{
|
||||
let mut err = self.tcx.dcx().create_err(AsyncClosureNotFn {
|
||||
let mut err = self.dcx().create_err(AsyncClosureNotFn {
|
||||
span: self.tcx.def_span(closure_def_id),
|
||||
kind: expected_kind.as_str(),
|
||||
});
|
||||
|
@ -1351,7 +1351,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
&self,
|
||||
ty: Ty<'tcx>,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
) -> Diag<'tcx> {
|
||||
) -> Diag<'a> {
|
||||
let span = obligation.cause.span;
|
||||
|
||||
let mut diag = match ty.kind() {
|
||||
|
@ -1445,8 +1445,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
#[extension(pub(super) trait InferCtxtPrivExt<'tcx>)]
|
||||
impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||
#[extension(pub(super) trait InferCtxtPrivExt<'a, 'tcx>)]
|
||||
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
||||
fn can_match_trait(
|
||||
&self,
|
||||
goal: ty::TraitPredicate<'tcx>,
|
||||
|
@ -2884,7 +2884,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
self.suggest_unsized_bound_if_applicable(err, obligation);
|
||||
if let Some(span) = err.span.primary_span()
|
||||
&& let Some(mut diag) =
|
||||
self.tcx.dcx().steal_non_err(span, StashKey::AssociatedTypeSuggestion)
|
||||
self.dcx().steal_non_err(span, StashKey::AssociatedTypeSuggestion)
|
||||
&& let Ok(ref mut s1) = err.suggestions
|
||||
&& let Ok(ref mut s2) = diag.suggestions
|
||||
{
|
||||
|
@ -3379,7 +3379,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
found_kind: ty::ClosureKind,
|
||||
kind: ty::ClosureKind,
|
||||
trait_prefix: &'static str,
|
||||
) -> Diag<'tcx> {
|
||||
) -> Diag<'a> {
|
||||
let closure_span = self.tcx.def_span(closure_def_id);
|
||||
|
||||
let mut err = ClosureKindMismatch {
|
||||
|
@ -3422,7 +3422,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
found_trait_ref: ty::TraitRef<'tcx>,
|
||||
expected_trait_ref: ty::TraitRef<'tcx>,
|
||||
terr: TypeError<'tcx>,
|
||||
) -> Diag<'tcx> {
|
||||
) -> Diag<'a> {
|
||||
let self_ty = found_trait_ref.self_ty();
|
||||
let (cause, terr) = if let ty::Closure(def_id, _) = self_ty.kind() {
|
||||
(
|
||||
|
@ -3473,7 +3473,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
span: Span,
|
||||
found_trait_ref: ty::TraitRef<'tcx>,
|
||||
expected_trait_ref: ty::TraitRef<'tcx>,
|
||||
) -> Result<Diag<'tcx>, ErrorGuaranteed> {
|
||||
) -> Result<Diag<'a>, ErrorGuaranteed> {
|
||||
let found_trait_ref = self.resolve_vars_if_possible(found_trait_ref);
|
||||
let expected_trait_ref = self.resolve_vars_if_possible(expected_trait_ref);
|
||||
|
||||
|
@ -3553,7 +3553,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
})
|
||||
.unwrap_or((found_span, None, found));
|
||||
|
||||
self.report_arg_count_mismatch(
|
||||
self.infcx.report_arg_count_mismatch(
|
||||
span,
|
||||
closure_span,
|
||||
expected,
|
||||
|
@ -3569,7 +3569,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
&self,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
span: Span,
|
||||
) -> Result<Diag<'tcx>, ErrorGuaranteed> {
|
||||
) -> Result<Diag<'a>, ErrorGuaranteed> {
|
||||
if !self.tcx.features().generic_const_exprs {
|
||||
let guar = self
|
||||
.dcx()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue