Skip to content

Commit

Permalink
lifetime defined here err
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyJado committed Sep 1, 2022
1 parent eac6c33 commit 422fde3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use rustc_middle::ty::{self, DefIdTree, RegionVid, Ty};
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{Span, DUMMY_SP};

use crate::session_diagnostics::RegionNameLables;
use crate::{nll::ToRegionVid, universal_regions::DefiningTy, MirBorrowckCtxt};

/// A name for a particular region used in emitting diagnostics. This name could be a generated
Expand Down Expand Up @@ -106,7 +107,11 @@ impl RegionName {
match &self.source {
RegionNameSource::NamedFreeRegion(span)
| RegionNameSource::NamedEarlyBoundRegion(span) => {
diag.span_label(*span, format!("lifetime `{self}` defined here"));
let name = format!("{self}");
diag.subdiagnostic(RegionNameLables::LifetimeDefinedHere {
span: *span,
rg_name: name,
});
}
RegionNameSource::SynthesizedFreeEnvRegion(span, note) => {
diag.span_label(*span, format!("lifetime `{self}` represents this closure's body"));
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_borrowck/src/session_diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,13 @@ pub(crate) enum RequireStaticErr {
multi_span: MultiSpan,
},
}

#[derive(SessionSubdiagnostic)]
pub(crate) enum RegionNameLables {
#[label(borrowck::lifetime_defined_here)]
LifetimeDefinedHere {
rg_name: String,
#[primary_span]
span: Span,
},
}
3 changes: 3 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/borrowck.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ borrowck_returned_lifetime_short =
borrowck_used_impl_require_static =
the used `impl` has a `'static` requirement
borrowck_lifetime_defined_here =
lifetime `{$rg_name}` defined here

0 comments on commit 422fde3

Please sign in to comment.