]> git.lizzy.rs Git - rust.git/commitdiff
Migrate forbidden_lifetime_bound, forbidden_non_lifetime_param, too_many_params,...
authorfinalchild <finalchild2@gmail.com>
Thu, 18 Aug 2022 08:38:11 +0000 (17:38 +0900)
committerfinalchild <finalchild2@gmail.com>
Sun, 21 Aug 2022 15:57:21 +0000 (00:57 +0900)
compiler/rustc_ast_passes/src/ast_validation.rs
compiler/rustc_ast_passes/src/errors.rs
compiler/rustc_error_messages/locales/en-US/ast_passes.ftl

index 234243f372c25865327becd3791e923394c0e4f5..7735d95f71ee9934bc6789c92252836cc5599f64 100644 (file)
@@ -293,14 +293,7 @@ fn check_trait_fn_not_async(&self, fn_span: Span, asyncness: Async) {
 
     fn check_trait_fn_not_const(&self, constness: Const) {
         if let Const::Yes(span) = constness {
-            struct_span_err!(
-                self.session,
-                span,
-                E0379,
-                "functions in traits cannot be declared const"
-            )
-            .span_label(span, "functions in traits cannot be const")
-            .emit();
+            self.session.emit_err(TraitFnConst { span });
         }
     }
 
@@ -313,8 +306,7 @@ fn check_late_bound_lifetime_defs(&self, params: &[GenericParam]) {
                 GenericParamKind::Lifetime { .. } => {
                     if !param.bounds.is_empty() {
                         let spans: Vec<_> = param.bounds.iter().map(|b| b.span()).collect();
-                        self.err_handler()
-                            .span_err(spans, "lifetime bounds cannot be used in this context");
+                        self.session.emit_err(ForbiddenLifetimeBound { spans });
                     }
                     None
                 }
@@ -322,10 +314,7 @@ fn check_late_bound_lifetime_defs(&self, params: &[GenericParam]) {
             })
             .collect();
         if !non_lt_param_spans.is_empty() {
-            self.err_handler().span_err(
-                non_lt_param_spans,
-                "only lifetime parameters can be used in this context",
-            );
+            self.session.emit_err(ForbiddenNonLifetimeParam { spans: non_lt_param_spans });
         }
     }
 
@@ -342,10 +331,7 @@ fn check_decl_num_args(&self, fn_decl: &FnDecl) {
         let max_num_args: usize = u16::MAX.into();
         if fn_decl.inputs.len() > max_num_args {
             let Param { span, .. } = fn_decl.inputs[0];
-            self.err_handler().span_fatal(
-                span,
-                &format!("function can not have more than {} arguments", max_num_args),
-            );
+            self.session.emit_err(TooManyParams { span, max_num_args });
         }
     }
 
@@ -353,19 +339,13 @@ fn check_decl_cvaradic_pos(&self, fn_decl: &FnDecl) {
         match &*fn_decl.inputs {
             [Param { ty, span, .. }] => {
                 if let TyKind::CVarArgs = ty.kind {
-                    self.err_handler().span_err(
-                        *span,
-                        "C-variadic function must be declared with at least one named argument",
-                    );
+                    self.session.emit_err(CVarArgsWithoutNamedArg { span: *span });
                 }
             }
             [ps @ .., _] => {
                 for Param { ty, span, .. } in ps {
                     if let TyKind::CVarArgs = ty.kind {
-                        self.err_handler().span_err(
-                            *span,
-                            "`...` must be the last argument of a C-variadic function",
-                        );
+                        self.session.emit_err(CVarArgsNotLast { span: *span });
                     }
                 }
             }
index 7a7073b5a510750c35d02289334d436cd082d75f..cc92f00714de04f04df5d8ed74cce42e9c2be96a 100644 (file)
@@ -90,3 +90,39 @@ pub struct TraitFnConst {
     #[label]
     pub span: Span,
 }
+
+#[derive(SessionDiagnostic)]
+#[error(ast_passes::forbidden_lifetime_bound)]
+pub struct ForbiddenLifetimeBound {
+    #[primary_span]
+    pub spans: Vec<Span>,
+}
+
+#[derive(SessionDiagnostic)]
+#[error(ast_passes::forbidden_non_lifetime_param)]
+pub struct ForbiddenNonLifetimeParam {
+    #[primary_span]
+    pub spans: Vec<Span>,
+}
+
+#[derive(SessionDiagnostic)]
+#[error(ast_passes::too_many_params)]
+pub struct TooManyParams {
+    #[primary_span]
+    pub span: Span,
+    pub max_num_args: usize,
+}
+
+#[derive(SessionDiagnostic)]
+#[error(ast_passes::c_var_args_without_named_arg)]
+pub struct CVarArgsWithoutNamedArg {
+    #[primary_span]
+    pub span: Span,
+}
+
+#[derive(SessionDiagnostic)]
+#[error(ast_passes::c_var_args_not_last)]
+pub struct CVarArgsNotLast {
+    #[primary_span]
+    pub span: Span,
+}
index fa6a02493f3b7e9ebee0b3b7f23b653523971fa6..c0994063fc3436cf7e05276c23a8c36d113cd7be 100644 (file)
@@ -31,3 +31,18 @@ ast_passes_trait_fn_async =
 ast_passes_trait_fn_const =
     functions in traits cannot be declared const
     .label = functions in traits cannot be const
+
+ast_passes_forbidden_lifetime_bound =
+    lifetime bounds cannot be used in this context
+
+ast_passes_forbidden_non_lifetime_param =
+    only lifetime parameters can be used in this context
+
+ast_passes_too_many_params =
+    function can not have more than {$max_num_args} arguments
+
+ast_passes_c_var_args_without_named_arg =
+    C-variadic function must be declared with at least one named argument
+
+ast_passes_c_var_args_not_last =
+    `...` must be the last argument of a C-variadic function