Migrate doc_comment_on_fn_param, forbidden_attr_on_fn_param

This commit is contained in:
finalchild 2022-08-18 17:46:01 +09:00
parent 269c85390c
commit c6903c04b1
3 changed files with 24 additions and 12 deletions

View File

@ -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 });
}
});
}

View File

@ -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,
}

View File

@ -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