Support C23's Variadics Without a Named Parameter · rust-lang/rust@f005b45 (original) (raw)
File tree
3 files changed
lines changed
- compiler/rustc_ast_passes
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -97,9 +97,6 @@ ast_passes_fn_body_extern = incorrect function inside `extern` block | ||
97 | 97 | ast_passes_fn_param_c_var_args_not_last = |
98 | 98 | `...` must be the last argument of a C-variadic function |
99 | 99 | |
100 | -ast_passes_fn_param_c_var_args_only = | |
101 | - C-variadic function must be declared with at least one named argument | |
102 | - | |
103 | 100 | ast_passes_fn_param_doc_comment = |
104 | 101 | documentation comments cannot be applied to function parameters |
105 | 102 | .label = doc comments are not allowed here |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -365,7 +365,7 @@ impl<'a> AstValidator<'a> { | ||
365 | 365 | |
366 | 366 | fn check_fn_decl(&self, fn_decl: &FnDecl, self_semantic: SelfSemantic) { |
367 | 367 | self.check_decl_num_args(fn_decl); |
368 | -self.check_decl_cvaradic_pos(fn_decl); | |
368 | +self.check_decl_cvariadic_pos(fn_decl); | |
369 | 369 | self.check_decl_attrs(fn_decl); |
370 | 370 | self.check_decl_self_param(fn_decl, self_semantic); |
371 | 371 | } |
@@ -380,13 +380,11 @@ impl<'a> AstValidator<'a> { | ||
380 | 380 | } |
381 | 381 | } |
382 | 382 | |
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) { | |
384 | 387 | 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 | -} | |
390 | 388 | [ps @ .., _] => { |
391 | 389 | for Param { ty, span, .. } in ps { |
392 | 390 | if let TyKind::CVarArgs = ty.kind { |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -92,13 +92,6 @@ pub struct FnParamTooMany { | ||
92 | 92 | pub max_num_args: usize, |
93 | 93 | } |
94 | 94 | |
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 | - | |
102 | 95 | #[derive(Diagnostic)] |
103 | 96 | #[diag(ast_passes_fn_param_c_var_args_not_last)] |
104 | 97 | pub struct FnParamCVarArgsNotLast { |