mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-14 21:16:50 +00:00
Migrate fn_param_forbidden_self and rename others to have prefix fn_param_
This commit is contained in:
parent
07e0bc9600
commit
bfefefbcfa
@ -331,7 +331,7 @@ impl<'a> AstValidator<'a> {
|
||||
let max_num_args: usize = u16::MAX.into();
|
||||
if fn_decl.inputs.len() > max_num_args {
|
||||
let Param { span, .. } = fn_decl.inputs[0];
|
||||
self.session.emit_err(TooManyParams { span, max_num_args });
|
||||
self.session.emit_err(FnParamTooMany { span, max_num_args });
|
||||
}
|
||||
}
|
||||
|
||||
@ -339,13 +339,13 @@ impl<'a> AstValidator<'a> {
|
||||
match &*fn_decl.inputs {
|
||||
[Param { ty, span, .. }] => {
|
||||
if let TyKind::CVarArgs = ty.kind {
|
||||
self.session.emit_err(CVarArgsIsSoleParam { span: *span });
|
||||
self.session.emit_err(FnParamCVarArgsOnly { span: *span });
|
||||
}
|
||||
}
|
||||
[ps @ .., _] => {
|
||||
for Param { ty, span, .. } in ps {
|
||||
if let TyKind::CVarArgs = ty.kind {
|
||||
self.session.emit_err(CVarArgsNotLast { span: *span });
|
||||
self.session.emit_err(FnParamCVarArgsNotLast { span: *span });
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -372,9 +372,9 @@ impl<'a> AstValidator<'a> {
|
||||
})
|
||||
.for_each(|attr| {
|
||||
if attr.is_doc_comment() {
|
||||
self.session.emit_err(DocCommentOnFnParam { span: attr.span });
|
||||
self.session.emit_err(FnParamDocComment { span: attr.span });
|
||||
} else {
|
||||
self.session.emit_err(ForbiddenAttrOnFnParam { span: attr.span });
|
||||
self.session.emit_err(FnParamForbiddenAttr { span: attr.span });
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -382,14 +382,7 @@ impl<'a> AstValidator<'a> {
|
||||
fn check_decl_self_param(&self, fn_decl: &FnDecl, self_semantic: SelfSemantic) {
|
||||
if let (SelfSemantic::No, [param, ..]) = (self_semantic, &*fn_decl.inputs) {
|
||||
if param.is_self() {
|
||||
self.err_handler()
|
||||
.struct_span_err(
|
||||
param.span,
|
||||
"`self` parameter is only allowed in associated functions",
|
||||
)
|
||||
.span_label(param.span, "not semantically valid as function parameter")
|
||||
.note("associated functions are those in `impl` or `trait` definitions")
|
||||
.emit();
|
||||
self.session.emit_err(FnParamForbiddenSelf { span: param.span });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,38 +106,47 @@ pub struct ForbiddenNonLifetimeParam {
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error(ast_passes::too_many_params)]
|
||||
pub struct TooManyParams {
|
||||
#[error(ast_passes::fn_param_too_many)]
|
||||
pub struct FnParamTooMany {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub max_num_args: usize,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error(ast_passes::c_var_args_is_sole_param)]
|
||||
pub struct CVarArgsIsSoleParam {
|
||||
#[error(ast_passes::fn_param_c_var_args_only)]
|
||||
pub struct FnParamCVarArgsOnly {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error(ast_passes::c_var_args_not_last)]
|
||||
pub struct CVarArgsNotLast {
|
||||
#[error(ast_passes::fn_param_c_var_args_not_last)]
|
||||
pub struct FnParamCVarArgsNotLast {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error(ast_passes::doc_comment_on_fn_param)]
|
||||
pub struct DocCommentOnFnParam {
|
||||
#[error(ast_passes::fn_param_doc_comment)]
|
||||
pub struct FnParamDocComment {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error(ast_passes::forbidden_attr_on_fn_param)]
|
||||
pub struct ForbiddenAttrOnFnParam {
|
||||
#[error(ast_passes::fn_param_forbidden_attr)]
|
||||
pub struct FnParamForbiddenAttr {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error(ast_passes::fn_param_forbidden_self)]
|
||||
#[note]
|
||||
pub struct FnParamForbiddenSelf {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
pub span: Span,
|
||||
}
|
||||
|
@ -38,18 +38,23 @@ ast_passes_forbidden_lifetime_bound =
|
||||
ast_passes_forbidden_non_lifetime_param =
|
||||
only lifetime parameters can be used in this context
|
||||
|
||||
ast_passes_too_many_params =
|
||||
ast_passes_fn_param_too_many =
|
||||
function can not have more than {$max_num_args} arguments
|
||||
|
||||
ast_passes_c_var_args_is_sole_param =
|
||||
ast_passes_fn_param_c_var_args_only =
|
||||
C-variadic function must be declared with at least one named argument
|
||||
|
||||
ast_passes_c_var_args_not_last =
|
||||
ast_passes_fn_param_c_var_args_not_last =
|
||||
`...` must be the last argument of a C-variadic function
|
||||
|
||||
ast_passes_doc_comment_on_fn_param =
|
||||
ast_passes_fn_param_doc_comment =
|
||||
documentation comments cannot be applied to function parameters
|
||||
.label = doc comments are not allowed here
|
||||
|
||||
ast_passes_forbidden_attr_on_fn_param =
|
||||
ast_passes_fn_param_forbidden_attr =
|
||||
allow, cfg, cfg_attr, deny, expect, forbid, and warn are the only allowed built-in attributes in function parameters
|
||||
|
||||
ast_passes_fn_param_forbidden_self =
|
||||
`self` parameter is only allowed in associated functions
|
||||
.label = not semantically valid as function parameter
|
||||
.note = associated functions are those in `impl` or `trait` definitions
|
||||
|
Loading…
Reference in New Issue
Block a user