about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-02-21 04:14:06 +0000
committerMichael Goulet <michael@errs.io>2023-03-03 05:02:34 +0000
commitbdacc8bdd97f7e6542d38f8c8cf19c555bd18911 (patch)
treea5ef3b84a3a3c4ac47e6a49aea6f063314f57731
parent4b23a224ab644cea703922859f64950898eba90d (diff)
downloadrust-bdacc8bdd97f7e6542d38f8c8cf19c555bd18911.tar.gz
rust-bdacc8bdd97f7e6542d38f8c8cf19c555bd18911.zip
Migrate diagnostic
-rw-r--r--compiler/rustc_infer/locales/en-US.ftl3
-rw-r--r--compiler/rustc_infer/src/errors/mod.rs10
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/mod.rs15
3 files changed, 18 insertions, 10 deletions
diff --git a/compiler/rustc_infer/locales/en-US.ftl b/compiler/rustc_infer/locales/en-US.ftl
index c5b2b6c2d73..9794c0ac9df 100644
--- a/compiler/rustc_infer/locales/en-US.ftl
+++ b/compiler/rustc_infer/locales/en-US.ftl
@@ -345,3 +345,6 @@ infer_prlf_defined_without_sub = the lifetime defined here...
 infer_prlf_must_oultive_with_sup = ...must outlive the lifetime `{$sup_symbol}` defined here
 infer_prlf_must_oultive_without_sup = ...must outlive the lifetime defined here
 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)
+
+infer_opaque_captures_lifetime = hidden type for `{$opaque_ty}` captures lifetime that does not appear in bounds
+    .label = opaque type defined here
diff --git a/compiler/rustc_infer/src/errors/mod.rs b/compiler/rustc_infer/src/errors/mod.rs
index 7dccd0bb930..6bbd3fd3e6e 100644
--- a/compiler/rustc_infer/src/errors/mod.rs
+++ b/compiler/rustc_infer/src/errors/mod.rs
@@ -1147,3 +1147,13 @@ pub enum PlaceholderRelationLfNotSatisfied {
         note: (),
     },
 }
+
+#[derive(Diagnostic)]
+#[diag(infer_opaque_captures_lifetime, code = "E0700")]
+pub struct OpaqueCapturesLifetime<'tcx> {
+    #[primary_span]
+    pub span: Span,
+    #[label]
+    pub opaque_ty_span: Span,
+    pub opaque_ty: Ty<'tcx>,
+}
diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs
index ef6dc24a444..2acbd513852 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs
@@ -49,6 +49,7 @@ use super::lexical_region_resolve::RegionResolutionError;
 use super::region_constraints::GenericKind;
 use super::{InferCtxt, RegionVariableOrigin, SubregionOrigin, TypeTrace, ValuePairs};
 
+use crate::errors;
 use crate::infer;
 use crate::infer::error_reporting::nice_region_error::find_anon_type::find_anon_type;
 use crate::infer::ExpectedFound;
@@ -283,17 +284,11 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>(
     hidden_region: ty::Region<'tcx>,
     opaque_ty_key: ty::OpaqueTypeKey<'tcx>,
 ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
-    let opaque_ty = tcx.mk_opaque(opaque_ty_key.def_id.to_def_id(), opaque_ty_key.substs);
-
-    let mut err = struct_span_err!(
-        tcx.sess,
+    let mut err = tcx.sess.create_err(errors::OpaqueCapturesLifetime {
         span,
-        E0700,
-        "hidden type for `{opaque_ty}` captures lifetime that does not appear in bounds",
-    );
-
-    let opaque_ty_span = tcx.def_span(opaque_ty_key.def_id);
-    err.span_label(opaque_ty_span, "opaque type defined here");
+        opaque_ty: tcx.mk_opaque(opaque_ty_key.def_id.to_def_id(), opaque_ty_key.substs),
+        opaque_ty_span: tcx.def_span(opaque_ty_key.def_id),
+    });
 
     // Explain the region we are capturing.
     match *hidden_region {