diff options
| author | Folkert de Vries <folkert@folkertdev.nl> | 2025-09-06 15:13:02 +0200 |
|---|---|---|
| committer | Folkert de Vries <folkert@folkertdev.nl> | 2025-09-08 18:41:22 +0200 |
| commit | a093372e5e560b1a768971c2b87b306755f2c17d (patch) | |
| tree | 7b5aadc3a0d30ee78f4d745f7a33be06538e0c73 /compiler/rustc_ast_passes | |
| parent | 1656f6c668e0603fb31dac6b2b95f1cfb1be2402 (diff) | |
| download | rust-a093372e5e560b1a768971c2b87b306755f2c17d.tar.gz rust-a093372e5e560b1a768971c2b87b306755f2c17d.zip | |
disallow c-variadic associated functions (for now)
there is no reason this should not work, really, we're just cutting some scope for now
Diffstat (limited to 'compiler/rustc_ast_passes')
| -rw-r--r-- | compiler/rustc_ast_passes/messages.ftl | 2 | ||||
| -rw-r--r-- | compiler/rustc_ast_passes/src/ast_validation.rs | 14 | ||||
| -rw-r--r-- | compiler/rustc_ast_passes/src/errors.rs | 7 |
3 files changed, 18 insertions, 5 deletions
diff --git a/compiler/rustc_ast_passes/messages.ftl b/compiler/rustc_ast_passes/messages.ftl index 68ac2a05a48..6eb4e4bc452 100644 --- a/compiler/rustc_ast_passes/messages.ftl +++ b/compiler/rustc_ast_passes/messages.ftl @@ -66,6 +66,8 @@ ast_passes_body_in_extern = incorrect `{$kind}` inside `extern` block ast_passes_bound_in_context = bounds on `type`s in {$ctx} have no effect +ast_passes_c_variadic_associated_function = associated functions cannot have a C variable argument list + ast_passes_const_and_c_variadic = functions cannot be both `const` and C-variadic .const = `const` because of this .variadic = C-variadic because of this diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 672c1e94418..c5c23c47e74 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -704,12 +704,16 @@ impl<'a> AstValidator<'a> { { return; } - _ => {} + _ => { + self.dcx().emit_err(errors::BadCVariadic { span: variadic_param.span }); + } }, - FnCtxt::Assoc(_) => {} - }; - - self.dcx().emit_err(errors::BadCVariadic { span: variadic_param.span }); + FnCtxt::Assoc(_) => { + // For now, C variable argument lists are unsupported in associated functions. + let err = errors::CVariadicAssociatedFunction { span: variadic_param.span }; + self.dcx().emit_err(err); + } + } } fn check_item_named(&self, ident: Ident, kind: &str) { diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs index f8806ef21c1..a085e09fe94 100644 --- a/compiler/rustc_ast_passes/src/errors.rs +++ b/compiler/rustc_ast_passes/src/errors.rs @@ -319,6 +319,13 @@ pub(crate) struct ExternItemAscii { } #[derive(Diagnostic)] +#[diag(ast_passes_c_variadic_associated_function)] +pub(crate) struct CVariadicAssociatedFunction { + #[primary_span] + pub span: Span, +} + +#[derive(Diagnostic)] #[diag(ast_passes_bad_c_variadic)] pub(crate) struct BadCVariadic { #[primary_span] |
