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

File tree

3 files changed

+5
-17
lines changed

3 files changed

+5
-17
lines changed

compiler/rustc_ast_passes/messages.ftl

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl<'a> AstValidator<'a> {
365365

366366
fn check_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-
fn check_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+
fn check_decl_cvariadic_pos(&self, fn_decl: &FnDecl) {
384387
match &*fn_decl.inputs {
385-
[Param { ty, span, .. }] => {
386-
if let TyKind::CVarArgs = ty.kind {
387-
self.dcx().emit_err(errors::FnParamCVarArgsOnly { span: *span });
388-
}
389-
}
390388
[ps @ .., _] => {
391389
for Param { ty, span, .. } in ps {
392390
if let TyKind::CVarArgs = ty.kind {

compiler/rustc_ast_passes/src/errors.rs

-7
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,6 @@ pub struct FnParamTooMany {
9292
pub max_num_args: usize,
9393
}
9494

95-
#[derive(Diagnostic)]
96-
#[diag(ast_passes_fn_param_c_var_args_only)]
97-
pub struct FnParamCVarArgsOnly {
98-
#[primary_span]
99-
pub span: Span,
100-
}
101-
10295
#[derive(Diagnostic)]
10396
#[diag(ast_passes_fn_param_c_var_args_not_last)]
10497
pub struct FnParamCVarArgsNotLast {

0 commit comments

Comments
 (0)