Rollup merge of #137006 - dianne:remove-errci-fields, r=compiler-errors

borrowck diagnostics cleanup: remove an unused and a barely-used field

This removes the fields `fr_is_local` and `outlived_fr_is_local` from the struct `ErrorConstraintInfo`. `fr_is_local` was fully unused, but wasn't caught by dead-code analysis. For symmetry, and since `outlived_fr_is_local` was used only once and is easy to recompute, I've removed it too. That makes its one use a bit longer, but constructing/destructuring an `ErrorConsraintInfo` now fits on one line.
This commit is contained in:
Jubilee 2025-02-14 14:05:25 -08:00 committed by GitHub
commit 388823cf00
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -147,9 +147,7 @@ pub(crate) enum RegionErrorKind<'tcx> {
pub(crate) struct ErrorConstraintInfo<'tcx> {
// fr: outlived_fr
pub(super) fr: RegionVid,
pub(super) fr_is_local: bool,
pub(super) outlived_fr: RegionVid,
pub(super) outlived_fr_is_local: bool,
// Category and span for best blame constraint
pub(super) category: ConstraintCategory<'tcx>,
@ -471,14 +469,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
fr_is_local, outlived_fr_is_local, category
);
let errci = ErrorConstraintInfo {
fr,
outlived_fr,
fr_is_local,
outlived_fr_is_local,
category,
span: cause.span,
};
let errci = ErrorConstraintInfo { fr, outlived_fr, category, span: cause.span };
let mut diag = match (category, fr_is_local, outlived_fr_is_local) {
(ConstraintCategory::Return(kind), true, false) if self.is_closure_fn_mut(fr) => {
@ -680,11 +671,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
&& self.regioncx.universal_regions().defining_ty.is_fn_def())
|| self.regioncx.universal_regions().defining_ty.is_const()
{
return self.report_general_error(&ErrorConstraintInfo {
fr_is_local: true,
outlived_fr_is_local: false,
..*errci
});
return self.report_general_error(errci);
}
let mut diag =
@ -762,15 +749,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
/// ```
#[allow(rustc::diagnostic_outside_of_impl)] // FIXME
fn report_general_error(&self, errci: &ErrorConstraintInfo<'tcx>) -> Diag<'infcx> {
let ErrorConstraintInfo {
fr,
fr_is_local,
outlived_fr,
outlived_fr_is_local,
span,
category,
..
} = errci;
let ErrorConstraintInfo { fr, outlived_fr, span, category, .. } = errci;
let mir_def_name = self.infcx.tcx.def_descr(self.mir_def_id().to_def_id());
@ -789,19 +768,22 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
let outlived_fr_name = self.give_region_a_name(*outlived_fr).unwrap();
outlived_fr_name.highlight_region_name(&mut diag);
let err_category = match (category, outlived_fr_is_local, fr_is_local) {
(ConstraintCategory::Return(_), true, _) => LifetimeReturnCategoryErr::WrongReturn {
let err_category = if matches!(category, ConstraintCategory::Return(_))
&& self.regioncx.universal_regions().is_local_free_region(*outlived_fr)
{
LifetimeReturnCategoryErr::WrongReturn {
span: *span,
mir_def_name,
outlived_fr_name,
fr_name: &fr_name,
},
_ => LifetimeReturnCategoryErr::ShortReturn {
}
} else {
LifetimeReturnCategoryErr::ShortReturn {
span: *span,
category_desc: category.description(),
free_region_name: &fr_name,
outlived_fr_name,
},
}
};
diag.subdiagnostic(err_category);