]> git.lizzy.rs Git - rust.git/commitdiff
Split infer_explicit_lifetime_required into several diags
authorNikita Tomashevich <quant3234@gmail.com>
Thu, 3 Nov 2022 17:45:14 +0000 (20:45 +0300)
committerNikita Tomashevich <quant3234@gmail.com>
Wed, 28 Dec 2022 11:53:48 +0000 (14:53 +0300)
compiler/rustc_error_messages/locales/en-US/infer.ftl
compiler/rustc_infer/src/errors/mod.rs
compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs

index f74af62702e9995e7cc688c443460c530fdd7500..52babec4f9ea74b730646cd28f79771f66ac7c5b 100644 (file)
@@ -173,16 +173,15 @@ infer_msl_trait_note = this has an implicit `'static` lifetime requirement
 infer_msl_trait_sugg = consider relaxing the implicit `'static` requirement
 infer_suggest_add_let_for_letchains = consider adding `let`
 
-infer_explicit_lifetime_required = explicit lifetime required in {$ident_kind ->
-    [ident] the type of `{$simple_ident}`
-    *[param_type] parameter type
-}
+infer_explicit_lifetime_required_with_ident = explicit lifetime required in the type of `{$simple_ident}`
     .label = lifetime `{$named}` required
 
-infer_explicit_lifetime_required_sugg = add explicit lifetime `{$named}` to {$ident_kind ->
-    [ident] the type of `{$simple_ident}`
-    *[param_type] type
-}
+infer_explicit_lifetime_required_with_param_type = explicit lifetime required in parameter type
+    .label = lifetime `{$named}` required
+
+infer_explicit_lifetime_required_sugg_with_ident = add explicit lifetime `{$named}` to the type of `{$simple_ident}`
+
+infer_explicit_lifetime_required_sugg_with_param_type = add explicit lifetime `{$named}` to type
 
 infer_actual_impl_expl_expected_signature_two = {$leading_ellipsis ->
     [true] ...
index 51b04eb0df011287851db58a847b0a4e89385730..9e3def93a6d3df8b5642eb2a01b0d3fd0661b5e5 100644 (file)
@@ -523,23 +523,38 @@ pub struct MismatchedStaticLifetime<'a> {
 }
 
 #[derive(Diagnostic)]
-#[diag(infer_explicit_lifetime_required, code = "E0621")]
-pub struct ExplicitLifetimeRequired<'a> {
-    #[primary_span]
-    #[label]
-    pub span: Span,
-    pub ident_kind: &'static str,
-    pub simple_ident: String,
-    pub named: String,
-
-    #[suggestion(
-        infer_explicit_lifetime_required_sugg,
-        code = "{new_ty}",
-        applicability = "unspecified"
-    )]
-    pub new_ty_span: Span,
-    #[skip_arg]
-    pub new_ty: Ty<'a>,
+pub enum ExplicitLifetimeRequired<'a> {
+    #[diag(infer_explicit_lifetime_required_with_ident, code = "E0621")]
+    WithIdent {
+        #[primary_span]
+        #[label]
+        span: Span,
+        simple_ident: Ident,
+        named: String,
+        #[suggestion(
+            infer_explicit_lifetime_required_sugg_with_ident,
+            code = "{new_ty}",
+            applicability = "unspecified"
+        )]
+        new_ty_span: Span,
+        #[skip_arg]
+        new_ty: Ty<'a>,
+    },
+    #[diag(infer_explicit_lifetime_required_with_param_type, code = "E0621")]
+    WithParamType {
+        #[primary_span]
+        #[label]
+        span: Span,
+        named: String,
+        #[suggestion(
+            infer_explicit_lifetime_required_sugg_with_param_type,
+            code = "{new_ty}",
+            applicability = "unspecified"
+        )]
+        new_ty_span: Span,
+        #[skip_arg]
+        new_ty: Ty<'a>,
+    },
 }
 
 #[derive(Subdiagnostic)]
index d7751158902b8bfc90446396f1a7895f1f919ef6..4e13ec90228d66c8b451cb885b17ed794094e258 100644 (file)
@@ -89,18 +89,17 @@ pub(super) fn try_report_named_anon_conflict(
         {
             return None;
         }
-
-        let simple_ident = param.pat.simple_ident();
-        let (ident_kind, simple_ident) = match simple_ident {
-            Some(ident) => ("ident", ident.to_string()),
-            None => ("param_type", String::new()),
-        };
-
         let named = named.to_string();
-
-        let err =
-            ExplicitLifetimeRequired { span, ident_kind, simple_ident, named, new_ty_span, new_ty };
-        let err = self.tcx().sess.parse_sess.create_err(err);
-        Some(err)
+        let err = match param.pat.simple_ident() {
+            Some(simple_ident) => ExplicitLifetimeRequired::WithIdent {
+                span,
+                simple_ident,
+                named,
+                new_ty_span,
+                new_ty,
+            },
+            None => ExplicitLifetimeRequired::WithParamType { span, named, new_ty_span, new_ty },
+        };
+        Some(self.tcx().sess.parse_sess.create_err(err))
     }
 }