Skip to content

Commit bdacc8b

Browse files
Migrate diagnostic
1 parent 4b23a22 commit bdacc8b

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

compiler/rustc_infer/locales/en-US.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -345,3 +345,6 @@ infer_prlf_defined_without_sub = the lifetime defined here...
345345
infer_prlf_must_oultive_with_sup = ...must outlive the lifetime `{$sup_symbol}` defined here
346346
infer_prlf_must_oultive_without_sup = ...must outlive the lifetime defined here
347347
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)
348+
349+
infer_opaque_captures_lifetime = hidden type for `{$opaque_ty}` captures lifetime that does not appear in bounds
350+
.label = opaque type defined here

compiler/rustc_infer/src/errors/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1147,3 +1147,13 @@ pub enum PlaceholderRelationLfNotSatisfied {
11471147
note: (),
11481148
},
11491149
}
1150+
1151+
#[derive(Diagnostic)]
1152+
#[diag(infer_opaque_captures_lifetime, code = "E0700")]
1153+
pub struct OpaqueCapturesLifetime<'tcx> {
1154+
#[primary_span]
1155+
pub span: Span,
1156+
#[label]
1157+
pub opaque_ty_span: Span,
1158+
pub opaque_ty: Ty<'tcx>,
1159+
}

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

+5-10
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use super::lexical_region_resolve::RegionResolutionError;
4949
use super::region_constraints::GenericKind;
5050
use super::{InferCtxt, RegionVariableOrigin, SubregionOrigin, TypeTrace, ValuePairs};
5151

52+
use crate::errors;
5253
use crate::infer;
5354
use crate::infer::error_reporting::nice_region_error::find_anon_type::find_anon_type;
5455
use crate::infer::ExpectedFound;
@@ -283,17 +284,11 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
283284
hidden_region: ty::Region<'tcx>,
284285
opaque_ty_key: ty::OpaqueTypeKey<'tcx>,
285286
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
286-
let opaque_ty = tcx.mk_opaque(opaque_ty_key.def_id.to_def_id(), opaque_ty_key.substs);
287-
288-
let mut err = struct_span_err!(
289-
tcx.sess,
287+
let mut err = tcx.sess.create_err(errors::OpaqueCapturesLifetime {
290288
span,
291-
E0700,
292-
"hidden type for `{opaque_ty}` captures lifetime that does not appear in bounds",
293-
);
294-
295-
let opaque_ty_span = tcx.def_span(opaque_ty_key.def_id);
296-
err.span_label(opaque_ty_span, "opaque type defined here");
289+
opaque_ty: tcx.mk_opaque(opaque_ty_key.def_id.to_def_id(), opaque_ty_key.substs),
290+
opaque_ty_span: tcx.def_span(opaque_ty_key.def_id),
291+
});
297292

298293
// Explain the region we are capturing.
299294
match *hidden_region {

0 commit comments

Comments
 (0)