diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index 552d9d1d3f9de..b7e2510e035ac 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -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);