Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 11 additions & 29 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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());

Expand All @@ -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);
Expand Down
Loading