Skip to content

Commit c770ac0

Browse files
committed
explain_borrow bug
1 parent 422fde3 commit c770ac0

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

Diff for: compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_span::symbol::{kw, Symbol};
1616
use rustc_span::{sym, DesugaringKind, Span};
1717

1818
use crate::region_infer::BlameConstraint;
19+
use crate::session_diagnostics::RequireBorrowLasts;
1920
use crate::{
2021
borrow_set::BorrowData, nll::ConstraintDescription, region_infer::Cause, MirBorrowckCtxt,
2122
WriteKind,
@@ -257,15 +258,14 @@ impl<'tcx> BorrowExplanation<'tcx> {
257258
),
258259
);
259260
} else {
260-
err.span_label(
261+
//FIXME: src/test/ui/consts/const-eval/const-eval-intrinsic-promotion.rs
262+
let sub_label = RequireBorrowLasts::Lasts {
263+
category: category.description(),
264+
borrow_desc,
265+
region_name,
261266
span,
262-
format!(
263-
"{}requires that {}borrow lasts for `{}`",
264-
category.description(),
265-
borrow_desc,
266-
region_name,
267-
),
268-
);
267+
};
268+
err.subdiagnostic(sub_label);
269269
};
270270

271271
self.add_lifetime_bound_suggestion_to_diagnostic(err, &category, span, region_name);

Diff for: compiler/rustc_borrowck/src/session_diagnostics.rs

+12
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,15 @@ pub(crate) enum RegionNameLables {
167167
span: Span,
168168
},
169169
}
170+
171+
#[derive(SessionSubdiagnostic)]
172+
pub(crate) enum RequireBorrowLasts<'a> {
173+
#[label(borrowck::outlive_constraint_need_borrow_lasts_for)]
174+
Lasts {
175+
category: &'a str,
176+
borrow_desc: &'a str,
177+
region_name: &'a RegionName,
178+
#[primary_span]
179+
span: Span,
180+
},
181+
}

Diff for: compiler/rustc_error_messages/locales/en-US/borrowck.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,6 @@ borrowck_used_impl_require_static =
6161
6262
borrowck_lifetime_defined_here =
6363
lifetime `{$rg_name}` defined here
64+
65+
borrowck_outlive_constraint_need_borrow_lasts_for =
66+
{$category}requires that `{$borrow_desc}` lasts for `{$region_name}`

0 commit comments

Comments
 (0)