From c6903c04b1c95061680aafa9da7e8dbccabb9069 Mon Sep 17 00:00:00 2001 From: finalchild Date: Thu, 18 Aug 2022 17:46:01 +0900 Subject: [PATCH] Migrate doc_comment_on_fn_param, forbidden_attr_on_fn_param --- compiler/rustc_ast_passes/src/ast_validation.rs | 14 ++------------ compiler/rustc_ast_passes/src/errors.rs | 15 +++++++++++++++ .../locales/en-US/ast_passes.ftl | 7 +++++++ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 7735d95f71e..e42d716d5ae 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -372,19 +372,9 @@ fn check_decl_attrs(&self, fn_decl: &FnDecl) { }) .for_each(|attr| { if attr.is_doc_comment() { - self.err_handler() - .struct_span_err( - attr.span, - "documentation comments cannot be applied to function parameters", - ) - .span_label(attr.span, "doc comments are not allowed here") - .emit(); + self.session.emit_err(DocCommentOnFnParam { span: attr.span }); } else { - self.err_handler().span_err( - attr.span, - "allow, cfg, cfg_attr, deny, expect, \ - forbid, and warn are the only allowed built-in attributes in function parameters", - ); + self.session.emit_err(ForbiddenAttrOnFnParam { span: attr.span }); } }); } diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs index cc92f00714d..2b6d3d2a39a 100644 --- a/compiler/rustc_ast_passes/src/errors.rs +++ b/compiler/rustc_ast_passes/src/errors.rs @@ -126,3 +126,18 @@ pub struct CVarArgsNotLast { #[primary_span] pub span: Span, } + +#[derive(SessionDiagnostic)] +#[error(ast_passes::doc_comment_on_fn_param)] +pub struct DocCommentOnFnParam { + #[primary_span] + #[label] + pub span: Span, +} + +#[derive(SessionDiagnostic)] +#[error(ast_passes::forbidden_attr_on_fn_param)] +pub struct ForbiddenAttrOnFnParam { + #[primary_span] + pub span: Span, +} diff --git a/compiler/rustc_error_messages/locales/en-US/ast_passes.ftl b/compiler/rustc_error_messages/locales/en-US/ast_passes.ftl index c0994063fc3..bca73baea00 100644 --- a/compiler/rustc_error_messages/locales/en-US/ast_passes.ftl +++ b/compiler/rustc_error_messages/locales/en-US/ast_passes.ftl @@ -46,3 +46,10 @@ ast_passes_c_var_args_without_named_arg = ast_passes_c_var_args_not_last = `...` must be the last argument of a C-variadic function + +ast_passes_doc_comment_on_fn_param = + documentation comments cannot be applied to function parameters + .label = doc comments are not allowed here + +ast_passes_forbidden_attr_on_fn_param = + allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters