Skip to content

Commit ecca7da

Browse files
authored
Rollup merge of rust-lang#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.
2 parents aed26c9 + 2ea9e1d commit ecca7da

File tree

1 file changed

+11
-29
lines changed

1 file changed

+11
-29
lines changed

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+11-29
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,7 @@ pub(crate) enum RegionErrorKind<'tcx> {
147147
pub(crate) struct ErrorConstraintInfo<'tcx> {
148148
// fr: outlived_fr
149149
pub(super) fr: RegionVid,
150-
pub(super) fr_is_local: bool,
151150
pub(super) outlived_fr: RegionVid,
152-
pub(super) outlived_fr_is_local: bool,
153151

154152
// Category and span for best blame constraint
155153
pub(super) category: ConstraintCategory<'tcx>,
@@ -471,14 +469,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
471469
fr_is_local, outlived_fr_is_local, category
472470
);
473471

474-
let errci = ErrorConstraintInfo {
475-
fr,
476-
outlived_fr,
477-
fr_is_local,
478-
outlived_fr_is_local,
479-
category,
480-
span: cause.span,
481-
};
472+
let errci = ErrorConstraintInfo { fr, outlived_fr, category, span: cause.span };
482473

483474
let mut diag = match (category, fr_is_local, outlived_fr_is_local) {
484475
(ConstraintCategory::Return(kind), true, false) if self.is_closure_fn_mut(fr) => {
@@ -680,11 +671,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
680671
&& self.regioncx.universal_regions().defining_ty.is_fn_def())
681672
|| self.regioncx.universal_regions().defining_ty.is_const()
682673
{
683-
return self.report_general_error(&ErrorConstraintInfo {
684-
fr_is_local: true,
685-
outlived_fr_is_local: false,
686-
..*errci
687-
});
674+
return self.report_general_error(errci);
688675
}
689676

690677
let mut diag =
@@ -762,15 +749,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
762749
/// ```
763750
#[allow(rustc::diagnostic_outside_of_impl)] // FIXME
764751
fn report_general_error(&self, errci: &ErrorConstraintInfo<'tcx>) -> Diag<'infcx> {
765-
let ErrorConstraintInfo {
766-
fr,
767-
fr_is_local,
768-
outlived_fr,
769-
outlived_fr_is_local,
770-
span,
771-
category,
772-
..
773-
} = errci;
752+
let ErrorConstraintInfo { fr, outlived_fr, span, category, .. } = errci;
774753

775754
let mir_def_name = self.infcx.tcx.def_descr(self.mir_def_id().to_def_id());
776755

@@ -789,19 +768,22 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
789768
let outlived_fr_name = self.give_region_a_name(*outlived_fr).unwrap();
790769
outlived_fr_name.highlight_region_name(&mut diag);
791770

792-
let err_category = match (category, outlived_fr_is_local, fr_is_local) {
793-
(ConstraintCategory::Return(_), true, _) => LifetimeReturnCategoryErr::WrongReturn {
771+
let err_category = if matches!(category, ConstraintCategory::Return(_))
772+
&& self.regioncx.universal_regions().is_local_free_region(*outlived_fr)
773+
{
774+
LifetimeReturnCategoryErr::WrongReturn {
794775
span: *span,
795776
mir_def_name,
796777
outlived_fr_name,
797778
fr_name: &fr_name,
798-
},
799-
_ => LifetimeReturnCategoryErr::ShortReturn {
779+
}
780+
} else {
781+
LifetimeReturnCategoryErr::ShortReturn {
800782
span: *span,
801783
category_desc: category.description(),
802784
free_region_name: &fr_name,
803785
outlived_fr_name,
804-
},
786+
}
805787
};
806788

807789
diag.subdiagnostic(err_category);

0 commit comments

Comments
 (0)