Skip to content

Commit 35dbec3

Browse files
committed
Port another diagnostic
1 parent cb8ea01 commit 35dbec3

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,10 @@ infer_region_explanation = {$pref_kind ->
146146
[source_pointer_valid_for] source pointer is only valid for
147147
[type_satisfy] type must satisfy
148148
[type_outlive] type must outlive
149-
[lf_instantiated_with] lifetime parameter instantiated with
150-
[lf_must_outlive] but lifetime parameter must outlive
149+
[lf_param_instantiated_with] lifetime parameter instantiated with
150+
[lf_param_must_outlive] but lifetime parameter must outlive
151+
[lf_instantiated_with] lifetime instantiated with
152+
[lf_must_outlive] but lifetime must outlive
151153
[type_valid_for] the type is valid for
152154
[borrow_lasts_for] but the borrow lasts for
153155
[pointer_valid_for] the pointer is valid for

compiler/rustc_infer/src/errors/note_and_explain.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ pub enum PrefixKind {
127127
SourcePointerValidFor,
128128
TypeSatisfy,
129129
TypeOutlive,
130+
LfParamInstantiatedWith,
131+
LfParamMustOutlive,
130132
LfInstantiatedWith,
131133
LfMustOutlive,
132134
TypeValidFor,
@@ -151,6 +153,8 @@ impl IntoDiagnosticArg for PrefixKind {
151153
Self::SourcePointerValidFor => "source_pointer_valid_for",
152154
Self::TypeSatisfy => "type_satisfy",
153155
Self::TypeOutlive => "type_outlive",
156+
Self::LfParamInstantiatedWith => "lf_param_instantiated_with",
157+
Self::LfParamMustOutlive => "lf_param_must_outlive",
154158
Self::LfInstantiatedWith => "lf_instantiated_with",
155159
Self::LfMustOutlive => "lf_must_outlive",
156160
Self::TypeValidFor => "type_valid_for",

compiler/rustc_infer/src/infer/error_reporting/note.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::errors::{
55
use crate::infer::error_reporting::{note_and_explain_region, TypeErrCtxt};
66
use crate::infer::{self, SubregionOrigin};
77
use rustc_errors::{
8-
fluent, struct_span_err, AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder,
9-
ErrorGuaranteed, IntoDiagnostic,
8+
fluent, AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed,
9+
IntoDiagnostic,
1010
};
1111
use rustc_hir::def_id::{DefId, LocalDefId};
1212
use rustc_middle::traits::ObligationCauseCode;
@@ -184,14 +184,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
184184
self.tcx,
185185
sup,
186186
None,
187-
note_and_explain::PrefixKind::LfInstantiatedWith,
187+
note_and_explain::PrefixKind::LfParamInstantiatedWith,
188188
note_and_explain::SuffixKind::Empty,
189189
);
190190
let param_must_outlive = note_and_explain::RegionExplanation::new(
191191
self.tcx,
192192
sub,
193193
None,
194-
note_and_explain::PrefixKind::LfMustOutlive,
194+
note_and_explain::PrefixKind::LfParamMustOutlive,
195195
note_and_explain::SuffixKind::Empty,
196196
);
197197
LfBoundNotSatisfied {
@@ -279,25 +279,25 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
279279
err
280280
}
281281
infer::AscribeUserTypeProvePredicate(span) => {
282-
let mut err =
283-
struct_span_err!(self.tcx.sess, span, E0478, "lifetime bound not satisfied");
284-
note_and_explain_region(
282+
let instantiated = note_and_explain::RegionExplanation::new(
285283
self.tcx,
286-
&mut err,
287-
"lifetime instantiated with ",
288284
sup,
289-
"",
290285
None,
286+
note_and_explain::PrefixKind::LfInstantiatedWith,
287+
note_and_explain::SuffixKind::Empty,
291288
);
292-
note_and_explain_region(
289+
let must_outlive = note_and_explain::RegionExplanation::new(
293290
self.tcx,
294-
&mut err,
295-
"but lifetime must outlive ",
296291
sub,
297-
"",
298292
None,
293+
note_and_explain::PrefixKind::LfMustOutlive,
294+
note_and_explain::SuffixKind::Empty,
299295
);
300-
err
296+
LfBoundNotSatisfied {
297+
span,
298+
notes: instantiated.into_iter().chain(must_outlive).collect(),
299+
}
300+
.into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic)
301301
}
302302
};
303303
if sub.is_error() || sup.is_error() {

0 commit comments

Comments
 (0)