Skip to content

Commit 5c7afde

Browse files
committed
Port PlaceholderRelationLfNotSatisfied diagnostic
1 parent fdbec62 commit 5c7afde

File tree

3 files changed

+103
-30
lines changed

3 files changed

+103
-30
lines changed

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,10 @@ infer_srs_add_one = consider returning one of these bindings
338338
339339
infer_await_both_futures = consider `await`ing on both `Future`s
340340
infer_await_future = consider `await`ing on the `Future`
341-
infer_await_note = calling an async function returns a future
341+
infer_await_note = calling an async function returns a future
342+
343+
infer_prlf_defined_with_sub = the lifetime `{$sub_symbol}` defined here...
344+
infer_prlf_defined_without_sub = the lifetime defined here...
345+
infer_prlf_must_oultive_with_sup = ...must outlive the lifetime `{$sup_symbol}` defined here
346+
infer_prlf_must_oultive_without_sup = ...must outlive the lifetime defined here
347+
infer_prlf_known_limitation = this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)

compiler/rustc_infer/src/errors/mod.rs

+59
Original file line numberDiff line numberDiff line change
@@ -1093,3 +1093,62 @@ pub enum ConsiderAddingAwait {
10931093
spans: Vec<Span>,
10941094
},
10951095
}
1096+
1097+
#[derive(Diagnostic)]
1098+
pub enum PlaceholderRelationLfNotSatisfied {
1099+
#[diag(infer_lf_bound_not_satisfied)]
1100+
HasBoth {
1101+
#[primary_span]
1102+
span: Span,
1103+
#[note(infer_prlf_defined_with_sub)]
1104+
sub_span: Span,
1105+
#[note(infer_prlf_must_oultive_with_sup)]
1106+
sup_span: Span,
1107+
sub_symbol: Symbol,
1108+
sup_symbol: Symbol,
1109+
#[note(infer_prlf_known_limitation)]
1110+
note: (),
1111+
},
1112+
#[diag(infer_lf_bound_not_satisfied)]
1113+
HasSub {
1114+
#[primary_span]
1115+
span: Span,
1116+
#[note(infer_prlf_defined_with_sub)]
1117+
sub_span: Span,
1118+
#[note(infer_prlf_must_oultive_without_sup)]
1119+
sup_span: Span,
1120+
sub_symbol: Symbol,
1121+
#[note(infer_prlf_known_limitation)]
1122+
note: (),
1123+
},
1124+
#[diag(infer_lf_bound_not_satisfied)]
1125+
HasSup {
1126+
#[primary_span]
1127+
span: Span,
1128+
#[note(infer_prlf_defined_without_sub)]
1129+
sub_span: Span,
1130+
#[note(infer_prlf_must_oultive_with_sup)]
1131+
sup_span: Span,
1132+
sup_symbol: Symbol,
1133+
#[note(infer_prlf_known_limitation)]
1134+
note: (),
1135+
},
1136+
#[diag(infer_lf_bound_not_satisfied)]
1137+
HasNone {
1138+
#[primary_span]
1139+
span: Span,
1140+
#[note(infer_prlf_defined_without_sub)]
1141+
sub_span: Span,
1142+
#[note(infer_prlf_must_oultive_without_sup)]
1143+
sup_span: Span,
1144+
#[note(infer_prlf_known_limitation)]
1145+
note: (),
1146+
},
1147+
#[diag(infer_lf_bound_not_satisfied)]
1148+
OnlyPrimarySpan {
1149+
#[primary_span]
1150+
span: Span,
1151+
#[note(infer_prlf_known_limitation)]
1152+
note: (),
1153+
},
1154+
}

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs

+37-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
use crate::infer::{
2-
error_reporting::nice_region_error::NiceRegionError, RegionResolutionError, SubregionOrigin,
1+
use crate::{
2+
errors::PlaceholderRelationLfNotSatisfied,
3+
infer::{
4+
error_reporting::nice_region_error::NiceRegionError, RegionResolutionError, SubregionOrigin,
5+
},
36
};
47
use rustc_data_structures::intern::Interned;
58
use rustc_errors::{DiagnosticBuilder, ErrorGuaranteed};
@@ -16,8 +19,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
1619
Region(Interned(RePlaceholder(ty::Placeholder { name: sub_name, .. }), _)),
1720
Region(Interned(RePlaceholder(ty::Placeholder { name: sup_name, .. }), _)),
1821
)) => {
19-
let msg = "lifetime bound not satisfied";
20-
let mut err = self.tcx().sess.struct_span_err(*span, msg);
22+
let span = *span;
2123
let (sub_span, sub_symbol) = match sub_name {
2224
ty::BrNamed(def_id, symbol) => {
2325
(Some(self.tcx().def_span(def_id)), Some(symbol))
@@ -32,41 +34,47 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
3234
ty::BrAnon(_, span) => (*span, None),
3335
ty::BrEnv => (None, None),
3436
};
35-
match (sub_span, sup_span, sub_symbol, sup_symbol) {
36-
(Some(sub_span), Some(sup_span), Some(sub_symbol), Some(sup_symbol)) => {
37-
err.span_note(
37+
let diag = match (sub_span, sup_span, sub_symbol, sup_symbol) {
38+
(Some(sub_span), Some(sup_span), Some(&sub_symbol), Some(&sup_symbol)) => {
39+
PlaceholderRelationLfNotSatisfied::HasBoth {
40+
span,
3841
sub_span,
39-
format!("the lifetime `{sub_symbol}` defined here..."),
40-
);
41-
err.span_note(
4242
sup_span,
43-
format!("...must outlive the lifetime `{sup_symbol}` defined here"),
44-
);
43+
sub_symbol,
44+
sup_symbol,
45+
note: (),
46+
}
4547
}
46-
(Some(sub_span), Some(sup_span), _, Some(sup_symbol)) => {
47-
err.span_note(sub_span, "the lifetime defined here...");
48-
err.span_note(
48+
(Some(sub_span), Some(sup_span), _, Some(&sup_symbol)) => {
49+
PlaceholderRelationLfNotSatisfied::HasSup {
50+
span,
51+
sub_span,
4952
sup_span,
50-
format!("...must outlive the lifetime `{sup_symbol}` defined here"),
51-
);
53+
sup_symbol,
54+
note: (),
55+
}
5256
}
53-
(Some(sub_span), Some(sup_span), Some(sub_symbol), _) => {
54-
err.span_note(
57+
(Some(sub_span), Some(sup_span), Some(&sub_symbol), _) => {
58+
PlaceholderRelationLfNotSatisfied::HasSub {
59+
span,
5560
sub_span,
56-
format!("the lifetime `{sub_symbol}` defined here..."),
57-
);
58-
err.span_note(sup_span, "...must outlive the lifetime defined here");
61+
sup_span,
62+
sub_symbol,
63+
note: (),
64+
}
5965
}
6066
(Some(sub_span), Some(sup_span), _, _) => {
61-
err.span_note(sub_span, "the lifetime defined here...");
62-
err.span_note(sup_span, "...must outlive the lifetime defined here");
67+
PlaceholderRelationLfNotSatisfied::HasNone {
68+
span,
69+
sub_span,
70+
sup_span,
71+
note: (),
72+
}
6373
}
64-
_ => {}
65-
}
66-
err.note("this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)");
67-
Some(err)
74+
_ => PlaceholderRelationLfNotSatisfied::OnlyPrimarySpan { span, note: () },
75+
};
76+
Some(self.tcx().sess.create_err(diag))
6877
}
69-
7078
_ => None,
7179
}
7280
}

0 commit comments

Comments
 (0)