Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two mig-diag that fail ui test #101275

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 8 additions & 8 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
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
22 changes: 22 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,25 @@ 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,
},
}

#[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,
},
}
6 changes: 6 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,9 @@ 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

borrowck_outlive_constraint_need_borrow_lasts_for =
{$category}requires that `{$borrow_desc}` lasts for `{$region_name}`