Skip to content

Commit c6903c0

Browse files
committed
Migrate doc_comment_on_fn_param, forbidden_attr_on_fn_param
1 parent 269c853 commit c6903c0

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -372,19 +372,9 @@ impl<'a> AstValidator<'a> {
372372
})
373373
.for_each(|attr| {
374374
if attr.is_doc_comment() {
375-
self.err_handler()
376-
.struct_span_err(
377-
attr.span,
378-
"documentation comments cannot be applied to function parameters",
379-
)
380-
.span_label(attr.span, "doc comments are not allowed here")
381-
.emit();
375+
self.session.emit_err(DocCommentOnFnParam { span: attr.span });
382376
} else {
383-
self.err_handler().span_err(
384-
attr.span,
385-
"allow, cfg, cfg_attr, deny, expect, \
386-
forbid, and warn are the only allowed built-in attributes in function parameters",
387-
);
377+
self.session.emit_err(ForbiddenAttrOnFnParam { span: attr.span });
388378
}
389379
});
390380
}

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,18 @@ pub struct CVarArgsNotLast {
126126
#[primary_span]
127127
pub span: Span,
128128
}
129+
130+
#[derive(SessionDiagnostic)]
131+
#[error(ast_passes::doc_comment_on_fn_param)]
132+
pub struct DocCommentOnFnParam {
133+
#[primary_span]
134+
#[label]
135+
pub span: Span,
136+
}
137+
138+
#[derive(SessionDiagnostic)]
139+
#[error(ast_passes::forbidden_attr_on_fn_param)]
140+
pub struct ForbiddenAttrOnFnParam {
141+
#[primary_span]
142+
pub span: Span,
143+
}

compiler/rustc_error_messages/locales/en-US/ast_passes.ftl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,10 @@ ast_passes_c_var_args_without_named_arg =
4646
4747
ast_passes_c_var_args_not_last =
4848
`...` must be the last argument of a C-variadic function
49+
50+
ast_passes_doc_comment_on_fn_param =
51+
documentation comments cannot be applied to function parameters
52+
.label = doc comments are not allowed here
53+
54+
ast_passes_forbidden_attr_on_fn_param =
55+
allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters

0 commit comments

Comments
 (0)