Skip to content

Commit 2c28796

Browse files
committed
outlives_sugg ini
1 parent 295da9c commit 2c28796

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// #![deny(rustc::untranslatable_diagnostic)]
2+
// #![deny(rustc::diagnostic_outside_of_impl)]
13
//! Contains utilities for generating suggestions for borrowck errors related to unsatisfied
24
//! outlives constraints.
35
@@ -7,7 +9,7 @@ use rustc_middle::ty::RegionVid;
79
use smallvec::SmallVec;
810
use std::collections::BTreeMap;
911

10-
use crate::MirBorrowckCtxt;
12+
use crate::{session_diagnostics::OnLifetimeBound, MirBorrowckCtxt};
1113

1214
use super::{ErrorConstraintInfo, RegionName, RegionNameSource};
1315

@@ -171,9 +173,7 @@ impl OutlivesSuggestionBuilder {
171173
if let (Some(fr_name), Some(outlived_fr_name)) = (fr_name, outlived_fr_name)
172174
&& !matches!(outlived_fr_name.source, RegionNameSource::Static)
173175
{
174-
diag.help(&format!(
175-
"consider adding the following bound: `{fr_name}: {outlived_fr_name}`",
176-
));
176+
diag.subdiagnostic(OnLifetimeBound::Add { fr_name: &fr_name, outlived_fr_name: &outlived_fr_name });
177177
}
178178
}
179179

compiler/rustc_borrowck/src/session_diagnostics.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,9 @@ pub(crate) enum MustValidFor<'a> {
337337
span: Span,
338338
},
339339
}
340+
341+
#[derive(SessionSubdiagnostic)]
342+
pub(crate) enum OnLifetimeBound<'a> {
343+
#[help(borrowck::consider_add_lifetime_bound)]
344+
Add { fr_name: &'a RegionName, outlived_fr_name: &'a RegionName },
345+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,6 @@ borrowck_perhaps_save_in_new_local_to_drop =
135135
136136
borrowck_outlive_constraint_need_borrow_for =
137137
{$category}requires that `{$desc}` is borrowed for `{$region_name}`
138+
139+
borrowck_consider_add_lifetime_bound =
140+
consider adding the following bound: `{$fr_name}: {$outlived_fr_name}`

0 commit comments

Comments
 (0)