Skip to content

Commit 79ac898

Browse files
committed
Restrict diagnostic context lifetime of TypeErrCtxt to InferCtxt instead of TyCtxt
1 parent f3d9523 commit 79ac898

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub struct TypeErrCtxt<'a, 'tcx> {
139139
}
140140

141141
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
142-
pub fn dcx(&self) -> DiagCtxtHandle<'tcx> {
142+
pub fn dcx(&self) -> DiagCtxtHandle<'a> {
143143
self.infcx.dcx()
144144
}
145145

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ impl<'tcx> InferCtxt<'tcx> {
436436
}
437437
}
438438

439-
impl<'tcx> TypeErrCtxt<'_, 'tcx> {
439+
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
440440
#[instrument(level = "debug", skip(self, error_code))]
441441
pub fn emit_inference_failure_err(
442442
&self,
@@ -445,7 +445,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
445445
arg: GenericArg<'tcx>,
446446
error_code: TypeAnnotationNeeded,
447447
should_label_span: bool,
448-
) -> Diag<'tcx> {
448+
) -> Diag<'a> {
449449
let arg = self.resolve_vars_if_possible(arg);
450450
let arg_data = self.extract_inference_diagnostics_data(arg, None);
451451

compiler/rustc_infer/src/infer/error_reporting/note.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_span::symbol::kw;
1414

1515
use super::ObligationCauseAsDiagArg;
1616

17-
impl<'tcx> TypeErrCtxt<'_, 'tcx> {
17+
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
1818
pub(super) fn note_region_origin(&self, err: &mut Diag<'_>, origin: &SubregionOrigin<'tcx>) {
1919
match *origin {
2020
infer::Subtype(ref trace) => RegionOriginNote::WithRequirement {
@@ -79,7 +79,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
7979
origin: SubregionOrigin<'tcx>,
8080
sub: Region<'tcx>,
8181
sup: Region<'tcx>,
82-
) -> Diag<'tcx> {
82+
) -> Diag<'a> {
8383
let mut err = match origin {
8484
infer::Subtype(box trace) => {
8585
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
@@ -378,7 +378,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
378378
placeholder_origin: SubregionOrigin<'tcx>,
379379
sub: Region<'tcx>,
380380
sup: Region<'tcx>,
381-
) -> Diag<'tcx> {
381+
) -> Diag<'a> {
382382
// I can't think how to do better than this right now. -nikomatsakis
383383
debug!(?placeholder_origin, ?sub, ?sup, "report_placeholder_failure");
384384
match placeholder_origin {

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ pub fn suggest_restriction<'tcx, G: EmissionGuarantee>(
241241
}
242242
}
243243

244-
#[extension(pub trait TypeErrCtxtExt<'tcx>)]
245-
impl<'tcx> TypeErrCtxt<'_, 'tcx> {
244+
#[extension(pub trait TypeErrCtxtExt<'a, 'tcx>)]
245+
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
246246
fn suggest_restricting_param_bound(
247247
&self,
248248
err: &mut Diag<'_>,
@@ -1845,7 +1845,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
18451845

18461846
fn point_at_returns_when_relevant(
18471847
&self,
1848-
err: &mut Diag<'tcx>,
1848+
err: &mut Diag<'_>,
18491849
obligation: &PredicateObligation<'tcx>,
18501850
) {
18511851
match obligation.cause.code().peel_derives() {
@@ -1884,7 +1884,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
18841884
cause: &ObligationCauseCode<'tcx>,
18851885
found_node: Option<Node<'_>>,
18861886
param_env: ty::ParamEnv<'tcx>,
1887-
) -> Diag<'tcx> {
1887+
) -> Diag<'a> {
18881888
pub(crate) fn build_fn_sig_ty<'tcx>(
18891889
infcx: &InferCtxt<'tcx>,
18901890
trait_ref: ty::TraitRef<'tcx>,
@@ -2104,7 +2104,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
21042104
fn note_conflicting_closure_bounds(
21052105
&self,
21062106
cause: &ObligationCauseCode<'tcx>,
2107-
err: &mut Diag<'tcx>,
2107+
err: &mut Diag<'_>,
21082108
) {
21092109
// First, look for an `WhereClauseInExpr`, which means we can get
21102110
// the uninstantiated predicate list of the called function. And check

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ pub fn suggest_new_overflow_limit<'tcx, G: EmissionGuarantee>(
8282
));
8383
}
8484

85-
#[extension(pub trait TypeErrCtxtExt<'tcx>)]
86-
impl<'tcx> TypeErrCtxt<'_, 'tcx> {
85+
#[extension(pub trait TypeErrCtxtExt<'a, 'tcx>)]
86+
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
8787
fn report_fulfillment_errors(
8888
&self,
8989
mut errors: Vec<FulfillmentError<'tcx>>,
@@ -228,7 +228,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
228228
cause: OverflowCause<'tcx>,
229229
span: Span,
230230
suggest_increasing_limit: bool,
231-
) -> Diag<'tcx> {
231+
) -> Diag<'a> {
232232
fn with_short_path<'tcx, T>(tcx: TyCtxt<'tcx>, value: T) -> String
233233
where
234234
T: fmt::Display + Print<'tcx, FmtPrinter<'tcx, 'tcx>>,
@@ -1351,7 +1351,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
13511351
&self,
13521352
ty: Ty<'tcx>,
13531353
obligation: &PredicateObligation<'tcx>,
1354-
) -> Diag<'tcx> {
1354+
) -> Diag<'a> {
13551355
let span = obligation.cause.span;
13561356

13571357
let mut diag = match ty.kind() {
@@ -1445,8 +1445,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
14451445
}
14461446
}
14471447

1448-
#[extension(pub(super) trait InferCtxtPrivExt<'tcx>)]
1449-
impl<'tcx> TypeErrCtxt<'_, 'tcx> {
1448+
#[extension(pub(super) trait InferCtxtPrivExt<'a, 'tcx>)]
1449+
impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
14501450
fn can_match_trait(
14511451
&self,
14521452
goal: ty::TraitPredicate<'tcx>,
@@ -3379,7 +3379,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
33793379
found_kind: ty::ClosureKind,
33803380
kind: ty::ClosureKind,
33813381
trait_prefix: &'static str,
3382-
) -> Diag<'tcx> {
3382+
) -> Diag<'a> {
33833383
let closure_span = self.tcx.def_span(closure_def_id);
33843384

33853385
let mut err = ClosureKindMismatch {
@@ -3473,7 +3473,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
34733473
span: Span,
34743474
found_trait_ref: ty::TraitRef<'tcx>,
34753475
expected_trait_ref: ty::TraitRef<'tcx>,
3476-
) -> Result<Diag<'tcx>, ErrorGuaranteed> {
3476+
) -> Result<Diag<'a>, ErrorGuaranteed> {
34773477
let found_trait_ref = self.resolve_vars_if_possible(found_trait_ref);
34783478
let expected_trait_ref = self.resolve_vars_if_possible(expected_trait_ref);
34793479

@@ -3569,7 +3569,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
35693569
&self,
35703570
obligation: &PredicateObligation<'tcx>,
35713571
span: Span,
3572-
) -> Result<Diag<'tcx>, ErrorGuaranteed> {
3572+
) -> Result<Diag<'a>, ErrorGuaranteed> {
35733573
if !self.tcx.features().generic_const_exprs {
35743574
let guar = self
35753575
.dcx()

0 commit comments

Comments
 (0)