diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index 2f61849c383c5..af8492ed04328 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -16,6 +16,7 @@ use rustc_span::symbol::{kw, Symbol}; use rustc_span::{sym, DesugaringKind, Span}; use crate::region_infer::BlameConstraint; +use crate::session_diagnostics::RequireBorrowLasts; use crate::{ borrow_set::BorrowData, nll::ConstraintDescription, region_infer::Cause, MirBorrowckCtxt, WriteKind, @@ -257,15 +258,14 @@ impl<'tcx> BorrowExplanation<'tcx> { ), ); } else { - err.span_label( + //FIXME: src/test/ui/consts/const-eval/const-eval-intrinsic-promotion.rs + let sub_label = RequireBorrowLasts::Lasts { + category: category.description(), + borrow_desc, + region_name, span, - format!( - "{}requires that {}borrow lasts for `{}`", - category.description(), - borrow_desc, - region_name, - ), - ); + }; + err.subdiagnostic(sub_label); }; self.add_lifetime_bound_suggestion_to_diagnostic(err, &category, span, region_name); diff --git a/compiler/rustc_borrowck/src/session_diagnostics.rs b/compiler/rustc_borrowck/src/session_diagnostics.rs index 0da5678a34865..202c70e39f05d 100644 --- a/compiler/rustc_borrowck/src/session_diagnostics.rs +++ b/compiler/rustc_borrowck/src/session_diagnostics.rs @@ -167,3 +167,15 @@ pub(crate) enum RegionNameLables { span: Span, }, } + +#[derive(SessionSubdiagnostic)] +pub(crate) enum RequireBorrowLasts<'a> { + #[label(borrowck::outlive_constraint_need_borrow_lasts_for)] + Lasts { + category: &'a str, + borrow_desc: &'a str, + region_name: &'a RegionName, + #[primary_span] + span: Span, + }, +} diff --git a/compiler/rustc_error_messages/locales/en-US/borrowck.ftl b/compiler/rustc_error_messages/locales/en-US/borrowck.ftl index 8e8380c4da2ca..ba9500a2426f9 100644 --- a/compiler/rustc_error_messages/locales/en-US/borrowck.ftl +++ b/compiler/rustc_error_messages/locales/en-US/borrowck.ftl @@ -61,3 +61,6 @@ borrowck_used_impl_require_static = borrowck_lifetime_defined_here = lifetime `{$rg_name}` defined here + +borrowck_outlive_constraint_need_borrow_lasts_for = + {$category}requires that `{$borrow_desc}` lasts for `{$region_name}`