Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
lifetime defined here err
  • Loading branch information
AndyJado committed Sep 1, 2022
commit 422fde3f9eb2db7b7165b9f688e2894c5fbaa138
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