Skip to content

Commit 422fde3

Browse files
committed
lifetime defined here err
1 parent eac6c33 commit 422fde3

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_middle::ty::{self, DefIdTree, RegionVid, Ty};
1010
use rustc_span::symbol::{kw, sym, Ident, Symbol};
1111
use rustc_span::{Span, DUMMY_SP};
1212

13+
use crate::session_diagnostics::RegionNameLables;
1314
use crate::{nll::ToRegionVid, universal_regions::DefiningTy, MirBorrowckCtxt};
1415

1516
/// A name for a particular region used in emitting diagnostics. This name could be a generated
@@ -106,7 +107,11 @@ impl RegionName {
106107
match &self.source {
107108
RegionNameSource::NamedFreeRegion(span)
108109
| RegionNameSource::NamedEarlyBoundRegion(span) => {
109-
diag.span_label(*span, format!("lifetime `{self}` defined here"));
110+
let name = format!("{self}");
111+
diag.subdiagnostic(RegionNameLables::LifetimeDefinedHere {
112+
span: *span,
113+
rg_name: name,
114+
});
110115
}
111116
RegionNameSource::SynthesizedFreeEnvRegion(span, note) => {
112117
diag.span_label(*span, format!("lifetime `{self}` represents this closure's body"));

compiler/rustc_borrowck/src/session_diagnostics.rs

+10
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,13 @@ pub(crate) enum RequireStaticErr {
157157
multi_span: MultiSpan,
158158
},
159159
}
160+
161+
#[derive(SessionSubdiagnostic)]
162+
pub(crate) enum RegionNameLables {
163+
#[label(borrowck::lifetime_defined_here)]
164+
LifetimeDefinedHere {
165+
rg_name: String,
166+
#[primary_span]
167+
span: Span,
168+
},
169+
}

compiler/rustc_error_messages/locales/en-US/borrowck.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,6 @@ borrowck_returned_lifetime_short =
5858
5959
borrowck_used_impl_require_static =
6060
the used `impl` has a `'static` requirement
61+
62+
borrowck_lifetime_defined_here =
63+
lifetime `{$rg_name}` defined here

0 commit comments

Comments
 (0)