Skip to content

Commit f005b45

Browse files
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`).
1 parent 62a104d commit f005b45

3 files changed

Lines changed: 5 additions & 17 deletions

File tree

‎compiler/rustc_ast_passes/messages.ftl‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ ast_passes_fn_body_extern = incorrect function inside `extern` block
9797
ast_passes_fn_param_c_var_args_not_last =
9898
`...` must be the last argument of a C-variadic function
9999
100-
ast_passes_fn_param_c_var_args_only =
101-
C-variadic function must be declared with at least one named argument
102-
103100
ast_passes_fn_param_doc_comment =
104101
documentation comments cannot be applied to function parameters
105102
.label = doc comments are not allowed here

‎compiler/rustc_ast_passes/src/ast_validation.rs‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl<'a> AstValidator<'a> {
365365

366366
fncheck_fn_decl(&self,fn_decl:&FnDecl,self_semantic:SelfSemantic){
367367
self.check_decl_num_args(fn_decl);
368-
self.check_decl_cvaradic_pos(fn_decl);
368+
self.check_decl_cvariadic_pos(fn_decl);
369369
self.check_decl_attrs(fn_decl);
370370
self.check_decl_self_param(fn_decl, self_semantic);
371371
}
@@ -380,13 +380,11 @@ impl<'a> AstValidator<'a> {
380380
}
381381
}
382382

383-
fncheck_decl_cvaradic_pos(&self,fn_decl:&FnDecl){
383+
/// Emits an error if a function declaration has a variadic parameter in the
384+
/// beginning or middle of parameter list.
385+
/// Example: `fn foo(..., x: i32)` will emit an error.
386+
fncheck_decl_cvariadic_pos(&self,fn_decl:&FnDecl){
384387
match&*fn_decl.inputs{
385-
[Param{ ty, span, .. }] => {
386-
ifletTyKind::CVarArgs = ty.kind{
387-
self.dcx().emit_err(errors::FnParamCVarArgsOnly{span:*span });
388-
}
389-
}
390388
[ps @ .., _] => {
391389
forParam{ ty, span, .. }in ps {
392390
ifletTyKind::CVarArgs = ty.kind{

‎compiler/rustc_ast_passes/src/errors.rs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,6 @@ pub struct FnParamTooMany {
9292
pubmax_num_args:usize,
9393
}
9494

95-
#[derive(Diagnostic)]
96-
#[diag(ast_passes_fn_param_c_var_args_only)]
97-
pubstructFnParamCVarArgsOnly{
98-
#[primary_span]
99-
pubspan:Span,
100-
}
101-
10295
#[derive(Diagnostic)]
10396
#[diag(ast_passes_fn_param_c_var_args_not_last)]
10497
pubstructFnParamCVarArgsNotLast{

0 commit comments

Comments
 (0)