Skip to content

Commit ed76b77

Browse files
committed
Auto merge of #97284 - b-naber:constraint-dyn-impl-suggestion, r=estebank
Add suggestion for relaxing static lifetime bounds on dyn trait impls in NLL This PR introduces suggestions for relaxing static lifetime bounds on impls of dyn trait items for NLL similar to what is already available in lexical region diagnostics. Fixes #95701 r? `@estebank`
2 parents 764b861 + 3c6c8d5 commit ed76b77

23 files changed

+368
-104
lines changed

compiler/rustc_borrowck/src/constraints/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub struct OutlivesConstraint<'tcx> {
9595
pub span: Span,
9696

9797
/// What caused this constraint?
98-
pub category: ConstraintCategory,
98+
pub category: ConstraintCategory<'tcx>,
9999

100100
/// Variance diagnostic information
101101
pub variance_info: VarianceDiagInfo<'tcx>,

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
788788
err: &mut Diagnostic,
789789
location: Location,
790790
issued_borrow: &BorrowData<'tcx>,
791-
explanation: BorrowExplanation,
791+
explanation: BorrowExplanation<'tcx>,
792792
) {
793793
let used_in_call = matches!(
794794
explanation,
@@ -1088,7 +1088,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10881088
BorrowExplanation::MustBeValidFor {
10891089
category:
10901090
category @ (ConstraintCategory::Return(_)
1091-
| ConstraintCategory::CallArgument
1091+
| ConstraintCategory::CallArgument(_)
10921092
| ConstraintCategory::OpaqueType),
10931093
from_closure: false,
10941094
ref region_name,
@@ -1147,7 +1147,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11471147
borrow: &BorrowData<'tcx>,
11481148
drop_span: Span,
11491149
borrow_spans: UseSpans<'tcx>,
1150-
explanation: BorrowExplanation,
1150+
explanation: BorrowExplanation<'tcx>,
11511151
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
11521152
debug!(
11531153
"report_local_value_does_not_live_long_enough(\
@@ -1352,7 +1352,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13521352
drop_span: Span,
13531353
borrow_spans: UseSpans<'tcx>,
13541354
proper_span: Span,
1355-
explanation: BorrowExplanation,
1355+
explanation: BorrowExplanation<'tcx>,
13561356
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
13571357
debug!(
13581358
"report_temporary_value_does_not_live_long_enough(\
@@ -1410,7 +1410,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14101410
borrow: &BorrowData<'tcx>,
14111411
borrow_span: Span,
14121412
return_span: Span,
1413-
category: ConstraintCategory,
1413+
category: ConstraintCategory<'tcx>,
14141414
opt_place_desc: Option<&String>,
14151415
) -> Option<DiagnosticBuilder<'cx, ErrorGuaranteed>> {
14161416
let return_kind = match category {
@@ -1508,7 +1508,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15081508
use_span: UseSpans<'tcx>,
15091509
var_span: Span,
15101510
fr_name: &RegionName,
1511-
category: ConstraintCategory,
1511+
category: ConstraintCategory<'tcx>,
15121512
constraint_span: Span,
15131513
captured_var: &str,
15141514
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
@@ -1559,7 +1559,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15591559
let msg = format!("{} is returned here", kind);
15601560
err.span_note(constraint_span, &msg);
15611561
}
1562-
ConstraintCategory::CallArgument => {
1562+
ConstraintCategory::CallArgument(_) => {
15631563
fr_name.highlight_region_name(&mut err);
15641564
if matches!(use_span.generator_kind(), Some(GeneratorKind::Async(_))) {
15651565
err.note(

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::{
2424
use super::{find_use, RegionName, UseSpans};
2525

2626
#[derive(Debug)]
27-
pub(crate) enum BorrowExplanation {
27+
pub(crate) enum BorrowExplanation<'tcx> {
2828
UsedLater(LaterUseKind, Span, Option<Span>),
2929
UsedLaterInLoop(LaterUseKind, Span, Option<Span>),
3030
UsedLaterWhenDropped {
@@ -33,7 +33,7 @@ pub(crate) enum BorrowExplanation {
3333
should_note_order: bool,
3434
},
3535
MustBeValidFor {
36-
category: ConstraintCategory,
36+
category: ConstraintCategory<'tcx>,
3737
from_closure: bool,
3838
span: Span,
3939
region_name: RegionName,
@@ -51,11 +51,11 @@ pub(crate) enum LaterUseKind {
5151
Other,
5252
}
5353

54-
impl BorrowExplanation {
54+
impl<'tcx> BorrowExplanation<'tcx> {
5555
pub(crate) fn is_explained(&self) -> bool {
5656
!matches!(self, BorrowExplanation::Unexplained)
5757
}
58-
pub(crate) fn add_explanation_to_diagnostic<'tcx>(
58+
pub(crate) fn add_explanation_to_diagnostic(
5959
&self,
6060
tcx: TyCtxt<'tcx>,
6161
body: &Body<'tcx>,
@@ -276,7 +276,7 @@ impl BorrowExplanation {
276276
pub(crate) fn add_lifetime_bound_suggestion_to_diagnostic(
277277
&self,
278278
err: &mut Diagnostic,
279-
category: &ConstraintCategory,
279+
category: &ConstraintCategory<'tcx>,
280280
span: Span,
281281
region_name: &RegionName,
282282
) {
@@ -305,7 +305,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
305305
&self,
306306
borrow_region: RegionVid,
307307
outlived_region: RegionVid,
308-
) -> (ConstraintCategory, bool, Span, Option<RegionName>) {
308+
) -> (ConstraintCategory<'tcx>, bool, Span, Option<RegionName>) {
309309
let BlameConstraint { category, from_closure, cause, variance_info: _ } =
310310
self.regioncx.best_blame_constraint(
311311
&self.body,
@@ -337,7 +337,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
337337
location: Location,
338338
borrow: &BorrowData<'tcx>,
339339
kind_place: Option<(WriteKind, Place<'tcx>)>,
340-
) -> BorrowExplanation {
340+
) -> BorrowExplanation<'tcx> {
341341
debug!(
342342
"explain_why_borrow_contains_point(location={:?}, borrow={:?}, kind_place={:?})",
343343
location, borrow, kind_place

compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl OutlivesSuggestionBuilder {
161161
pub(crate) fn intermediate_suggestion(
162162
&mut self,
163163
mbcx: &MirBorrowckCtxt<'_, '_>,
164-
errci: &ErrorConstraintInfo,
164+
errci: &ErrorConstraintInfo<'_>,
165165
diag: &mut Diagnostic,
166166
) {
167167
// Emit an intermediate note.

0 commit comments

Comments
 (0)