1
Fork 0

Restrict diagnostic context lifetime of TypeErrCtxt to InferCtxt instead of TyCtxt

This commit is contained in:
Oli Scherer 2024-06-25 08:14:35 +00:00
parent f3d9523a2e
commit 79ac8982ca
5 changed files with 20 additions and 20 deletions

View file

@ -139,7 +139,7 @@ pub struct TypeErrCtxt<'a, 'tcx> {
} }
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
pub fn dcx(&self) -> DiagCtxtHandle<'tcx> { pub fn dcx(&self) -> DiagCtxtHandle<'a> {
self.infcx.dcx() self.infcx.dcx()
} }

View file

@ -436,7 +436,7 @@ impl<'tcx> InferCtxt<'tcx> {
} }
} }
impl<'tcx> TypeErrCtxt<'_, 'tcx> { impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
#[instrument(level = "debug", skip(self, error_code))] #[instrument(level = "debug", skip(self, error_code))]
pub fn emit_inference_failure_err( pub fn emit_inference_failure_err(
&self, &self,
@ -445,7 +445,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
arg: GenericArg<'tcx>, arg: GenericArg<'tcx>,
error_code: TypeAnnotationNeeded, error_code: TypeAnnotationNeeded,
should_label_span: bool, should_label_span: bool,
) -> Diag<'tcx> { ) -> Diag<'a> {
let arg = self.resolve_vars_if_possible(arg); let arg = self.resolve_vars_if_possible(arg);
let arg_data = self.extract_inference_diagnostics_data(arg, None); let arg_data = self.extract_inference_diagnostics_data(arg, None);

View file

@ -14,7 +14,7 @@ use rustc_span::symbol::kw;
use super::ObligationCauseAsDiagArg; use super::ObligationCauseAsDiagArg;
impl<'tcx> TypeErrCtxt<'_, 'tcx> { impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
pub(super) fn note_region_origin(&self, err: &mut Diag<'_>, origin: &SubregionOrigin<'tcx>) { pub(super) fn note_region_origin(&self, err: &mut Diag<'_>, origin: &SubregionOrigin<'tcx>) {
match *origin { match *origin {
infer::Subtype(ref trace) => RegionOriginNote::WithRequirement { infer::Subtype(ref trace) => RegionOriginNote::WithRequirement {
@ -79,7 +79,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
origin: SubregionOrigin<'tcx>, origin: SubregionOrigin<'tcx>,
sub: Region<'tcx>, sub: Region<'tcx>,
sup: Region<'tcx>, sup: Region<'tcx>,
) -> Diag<'tcx> { ) -> Diag<'a> {
let mut err = match origin { let mut err = match origin {
infer::Subtype(box trace) => { infer::Subtype(box trace) => {
let terr = TypeError::RegionsDoesNotOutlive(sup, sub); let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
@ -378,7 +378,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
placeholder_origin: SubregionOrigin<'tcx>, placeholder_origin: SubregionOrigin<'tcx>,
sub: Region<'tcx>, sub: Region<'tcx>,
sup: Region<'tcx>, sup: Region<'tcx>,
) -> Diag<'tcx> { ) -> Diag<'a> {
// I can't think how to do better than this right now. -nikomatsakis // I can't think how to do better than this right now. -nikomatsakis
debug!(?placeholder_origin, ?sub, ?sup, "report_placeholder_failure"); debug!(?placeholder_origin, ?sub, ?sup, "report_placeholder_failure");
match placeholder_origin { match placeholder_origin {

View file

@ -241,8 +241,8 @@ pub fn suggest_restriction<'tcx, G: EmissionGuarantee>(
} }
} }
#[extension(pub trait TypeErrCtxtExt<'tcx>)] #[extension(pub trait TypeErrCtxtExt<'a, 'tcx>)]
impl<'tcx> TypeErrCtxt<'_, 'tcx> { impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
fn suggest_restricting_param_bound( fn suggest_restricting_param_bound(
&self, &self,
err: &mut Diag<'_>, err: &mut Diag<'_>,
@ -1845,7 +1845,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
fn point_at_returns_when_relevant( fn point_at_returns_when_relevant(
&self, &self,
err: &mut Diag<'tcx>, err: &mut Diag<'_>,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
) { ) {
match obligation.cause.code().peel_derives() { match obligation.cause.code().peel_derives() {
@ -1884,7 +1884,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
cause: &ObligationCauseCode<'tcx>, cause: &ObligationCauseCode<'tcx>,
found_node: Option<Node<'_>>, found_node: Option<Node<'_>>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
) -> Diag<'tcx> { ) -> Diag<'a> {
pub(crate) fn build_fn_sig_ty<'tcx>( pub(crate) fn build_fn_sig_ty<'tcx>(
infcx: &InferCtxt<'tcx>, infcx: &InferCtxt<'tcx>,
trait_ref: ty::TraitRef<'tcx>, trait_ref: ty::TraitRef<'tcx>,
@ -2104,7 +2104,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
fn note_conflicting_closure_bounds( fn note_conflicting_closure_bounds(
&self, &self,
cause: &ObligationCauseCode<'tcx>, cause: &ObligationCauseCode<'tcx>,
err: &mut Diag<'tcx>, err: &mut Diag<'_>,
) { ) {
// First, look for an `WhereClauseInExpr`, which means we can get // First, look for an `WhereClauseInExpr`, which means we can get
// the uninstantiated predicate list of the called function. And check // the uninstantiated predicate list of the called function. And check

View file

@ -82,8 +82,8 @@ pub fn suggest_new_overflow_limit<'tcx, G: EmissionGuarantee>(
)); ));
} }
#[extension(pub trait TypeErrCtxtExt<'tcx>)] #[extension(pub trait TypeErrCtxtExt<'a, 'tcx>)]
impl<'tcx> TypeErrCtxt<'_, 'tcx> { impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
fn report_fulfillment_errors( fn report_fulfillment_errors(
&self, &self,
mut errors: Vec<FulfillmentError<'tcx>>, mut errors: Vec<FulfillmentError<'tcx>>,
@ -228,7 +228,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
cause: OverflowCause<'tcx>, cause: OverflowCause<'tcx>,
span: Span, span: Span,
suggest_increasing_limit: bool, suggest_increasing_limit: bool,
) -> Diag<'tcx> { ) -> Diag<'a> {
fn with_short_path<'tcx, T>(tcx: TyCtxt<'tcx>, value: T) -> String fn with_short_path<'tcx, T>(tcx: TyCtxt<'tcx>, value: T) -> String
where where
T: fmt::Display + Print<'tcx, FmtPrinter<'tcx, 'tcx>>, T: fmt::Display + Print<'tcx, FmtPrinter<'tcx, 'tcx>>,
@ -1351,7 +1351,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
&self, &self,
ty: Ty<'tcx>, ty: Ty<'tcx>,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
) -> Diag<'tcx> { ) -> Diag<'a> {
let span = obligation.cause.span; let span = obligation.cause.span;
let mut diag = match ty.kind() { let mut diag = match ty.kind() {
@ -1445,8 +1445,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
} }
} }
#[extension(pub(super) trait InferCtxtPrivExt<'tcx>)] #[extension(pub(super) trait InferCtxtPrivExt<'a, 'tcx>)]
impl<'tcx> TypeErrCtxt<'_, 'tcx> { impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
fn can_match_trait( fn can_match_trait(
&self, &self,
goal: ty::TraitPredicate<'tcx>, goal: ty::TraitPredicate<'tcx>,
@ -3379,7 +3379,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
found_kind: ty::ClosureKind, found_kind: ty::ClosureKind,
kind: ty::ClosureKind, kind: ty::ClosureKind,
trait_prefix: &'static str, trait_prefix: &'static str,
) -> Diag<'tcx> { ) -> Diag<'a> {
let closure_span = self.tcx.def_span(closure_def_id); let closure_span = self.tcx.def_span(closure_def_id);
let mut err = ClosureKindMismatch { let mut err = ClosureKindMismatch {
@ -3473,7 +3473,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
span: Span, span: Span,
found_trait_ref: ty::TraitRef<'tcx>, found_trait_ref: ty::TraitRef<'tcx>,
expected_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 found_trait_ref = self.resolve_vars_if_possible(found_trait_ref);
let expected_trait_ref = self.resolve_vars_if_possible(expected_trait_ref); let expected_trait_ref = self.resolve_vars_if_possible(expected_trait_ref);
@ -3569,7 +3569,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
&self, &self,
obligation: &PredicateObligation<'tcx>, obligation: &PredicateObligation<'tcx>,
span: Span, span: Span,
) -> Result<Diag<'tcx>, ErrorGuaranteed> { ) -> Result<Diag<'a>, ErrorGuaranteed> {
if !self.tcx.features().generic_const_exprs { if !self.tcx.features().generic_const_exprs {
let guar = self let guar = self
.dcx() .dcx()