1
Fork 0

Support C23's Variadics Without a Named Parameter

This PR removes the static check that disallowed extern functions
with ellipsis (varargs) as the only parameter since this is now
valid in C23.

Also, adds a doc comment for `check_decl_cvariadic_pos()` and
fixes the name of the function (`varadic` -> `variadic`).
This commit is contained in:
Veera 2024-04-16 18:53:05 -04:00
parent 62a104df98
commit f005b451c2
3 changed files with 5 additions and 17 deletions

View file

@ -97,9 +97,6 @@ ast_passes_fn_body_extern = incorrect function inside `extern` block
ast_passes_fn_param_c_var_args_not_last = ast_passes_fn_param_c_var_args_not_last =
`...` must be the last argument of a C-variadic function `...` must be the last argument of a C-variadic function
ast_passes_fn_param_c_var_args_only =
C-variadic function must be declared with at least one named argument
ast_passes_fn_param_doc_comment = ast_passes_fn_param_doc_comment =
documentation comments cannot be applied to function parameters documentation comments cannot be applied to function parameters
.label = doc comments are not allowed here .label = doc comments are not allowed here

View file

@ -365,7 +365,7 @@ impl<'a> AstValidator<'a> {
fn check_fn_decl(&self, fn_decl: &FnDecl, self_semantic: SelfSemantic) { fn check_fn_decl(&self, fn_decl: &FnDecl, self_semantic: SelfSemantic) {
self.check_decl_num_args(fn_decl); self.check_decl_num_args(fn_decl);
self.check_decl_cvaradic_pos(fn_decl); self.check_decl_cvariadic_pos(fn_decl);
self.check_decl_attrs(fn_decl); self.check_decl_attrs(fn_decl);
self.check_decl_self_param(fn_decl, self_semantic); self.check_decl_self_param(fn_decl, self_semantic);
} }
@ -380,13 +380,11 @@ impl<'a> AstValidator<'a> {
} }
} }
fn check_decl_cvaradic_pos(&self, fn_decl: &FnDecl) { /// Emits an error if a function declaration has a variadic parameter in the
/// beginning or middle of parameter list.
/// Example: `fn foo(..., x: i32)` will emit an error.
fn check_decl_cvariadic_pos(&self, fn_decl: &FnDecl) {
match &*fn_decl.inputs { match &*fn_decl.inputs {
[Param { ty, span, .. }] => {
if let TyKind::CVarArgs = ty.kind {
self.dcx().emit_err(errors::FnParamCVarArgsOnly { span: *span });
}
}
[ps @ .., _] => { [ps @ .., _] => {
for Param { ty, span, .. } in ps { for Param { ty, span, .. } in ps {
if let TyKind::CVarArgs = ty.kind { if let TyKind::CVarArgs = ty.kind {

View file

@ -92,13 +92,6 @@ pub struct FnParamTooMany {
pub max_num_args: usize, pub max_num_args: usize,
} }
#[derive(Diagnostic)]
#[diag(ast_passes_fn_param_c_var_args_only)]
pub struct FnParamCVarArgsOnly {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(ast_passes_fn_param_c_var_args_not_last)] #[diag(ast_passes_fn_param_c_var_args_not_last)]
pub struct FnParamCVarArgsNotLast { pub struct FnParamCVarArgsNotLast {