Skip to content

add c-variadic function definitions - #2177

Merged
traviscross merged 7 commits into
rust-lang:masterfrom
folkertdev:c-variadic
Aug 8, 2026
Merged

add c-variadic function definitions#2177
traviscross merged 7 commits into
rust-lang:masterfrom
folkertdev:c-variadic

Conversation

@folkertdev

@folkertdev folkertdev commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

I think this has all of the raw material, but needs polishing.

Here is a draft of the stabilization report, for additional context: https://hackmd.io/@Q66MPiW4T7yNTKOCaEb-Lw/S1iI3WIwZg

Tracking issue: rust-lang/rust#44930

Stabilization:

@rustbot rustbot added the S-waiting-on-review Status: The marked PR is awaiting review from a maintainer label Feb 17, 2026
Comment thread src/items/functions.md Outdated
Comment thread src/items/functions.md Outdated
Comment thread src/items/functions.md Outdated

@ehuss ehuss left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the rule items.fn.params.varargs will need to be updated, since it says it can only be used in an external block.

View changes since this review

Comment thread src/items/functions.md
Comment thread src/items/functions.md Outdated
Comment thread src/items/functions.md Outdated
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 15, 2026
…-in-deps, r=mati865

report the `varargs_without_pattern` lint in deps

tracking issue: rust-lang#44930

After discussion in rust-lang/reference#2177 (comment).

Based on rust-lang#143619 (comment) there was only one actual impacted crate https://crates.io/crates/binrw. The issue was fixed in jam1garner/binrw#342, and has since been released jam1garner/binrw#342 (comment).

Hence we may as well report this loudly.

r? @ghost
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 16, 2026
…-in-deps, r=mati865

report the `varargs_without_pattern` lint in deps

tracking issue: rust-lang#44930

After discussion in rust-lang/reference#2177 (comment).

Based on rust-lang#143619 (comment) there was only one actual impacted crate https://crates.io/crates/binrw. The issue was fixed in jam1garner/binrw#342, and has since been released jam1garner/binrw#342 (comment).

Hence we may as well report this loudly.

r? @ghost
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 16, 2026
…-in-deps, r=mati865

report the `varargs_without_pattern` lint in deps

tracking issue: rust-lang#44930

After discussion in rust-lang/reference#2177 (comment).

Based on rust-lang#143619 (comment) there was only one actual impacted crate https://crates.io/crates/binrw. The issue was fixed in jam1garner/binrw#342, and has since been released jam1garner/binrw#342 (comment).

Hence we may as well report this loudly.

r? @ghost
rust-timer added a commit to rust-lang/rust that referenced this pull request Apr 16, 2026
Rollup merge of #154599 - folkertdev:varargs-without-pattern-in-deps, r=mati865

report the `varargs_without_pattern` lint in deps

tracking issue: #44930

After discussion in rust-lang/reference#2177 (comment).

Based on #143619 (comment) there was only one actual impacted crate https://crates.io/crates/binrw. The issue was fixed in jam1garner/binrw#342, and has since been released jam1garner/binrw#342 (comment).

Hence we may as well report this loudly.

r? @ghost
@folkertdev

Copy link
Copy Markdown
Contributor Author

The varargs_without_pattern is now reported in dependencies (on nightly).

I've pushed some tweaks, I'm now planning to submit a stabilization PR in coming days, so if you could look at this again that would be helpful.

@ehuss

ehuss commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

It looks like from rust-lang/rust#155974 that there is an intent to make this unavailable on certain targets. I don't think we've ever done something like that, and I'm not sure how we're going to document that. I suppose there will be a rule. It will need to be careful to distinguish that it is a compile error during validation. Unfortunately we don't define that as a specific phase in the reference, so I'm not sure how we should approach that.

@folkertdev

folkertdev commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

I don't think this is very different from https://doc.rust-lang.org/beta/unstable-book/language-features/asm-experimental-arch.html. Consequently the page on inline assembly specifies https://doc.rust-lang.org/nightly/reference/inline-assembly.html?highlight=assemb#r-asm.stable-targets.

So we could have

Support for c-variadic function definitions is stable on the following architectures:

  • x86 and x86-64
  • arm
  • aarch64 and arm64ec
  • ...

The compiler will emit an error if ... is used in a function definition on an unsupported target.

Also spirv and bpf just fundamentally do not support this feature, so there you'd always get an error.

Comment thread src/items/functions.md Outdated
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

Comment thread src/items/functions.md Outdated
Comment thread src/items/functions.md Outdated
Comment thread src/items/functions.md Outdated
Comment thread src/items/functions.md Outdated
Comment thread src/items/functions.md
Comment thread src/items/functions.md Outdated

@folkertdev folkertdev left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The merge of the stabilization PR is now only blocked on the additions to the reference here (I'm not sure that is really needed, previously features have been merged with a reference PR that was "far enough along").

I've tried to address comments here as much possible now.

I'd be happy to look at this together in the reference office hours if they are at a somewhat european-friendly time.

View changes since this review

Comment thread src/items/functions.md Outdated
Comment thread src/items/functions.md Outdated
Comment thread src/items/functions.md Outdated
Comment thread src/items/functions.md Outdated
Comment thread src/items/functions.md Outdated
@traviscross traviscross added the S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository label Jul 21, 2026
Comment thread src/items/functions.md Outdated
Comment thread src/items/functions.md Outdated
Comment thread src/items/functions.md Outdated

@ehuss ehuss left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread src/items/functions.md Outdated
Comment thread src/items/functions.md Outdated
Comment thread src/special-types-and-traits.md Outdated
@traviscross
traviscross force-pushed the c-variadic branch 2 times, most recently from 88338f3 to d8b62a8 Compare July 23, 2026 18:47
The statement that the "lifetime of a `VaList` is that of the function
(call) that created it" feels a bit loose to me.  Let's pin that down
more precisely.
We're moving in the direction of having one or more examples for each
rule where possible.  Let's add examples to the new rules where they
were missing and make sense to have.
The pattern is required when the variadic parameter appears either on
a function definition or on a function declaration in a trait
definition.  Let's say that and add examples.
Comment thread src/items/functions.md Outdated
Comment thread src/items/functions.md
Comment thread src/items/functions.md Outdated
Comment thread src/items/functions.md
@DanielEScherzer

Copy link
Copy Markdown
Contributor

@rustbot label -S-waiting-on-stabilization

Stabilization merged in rust-lang/rust#155697

@rustbot rustbot removed the S-waiting-on-stabilization Waiting for a stabilization PR to be merged in the main Rust repository label Jul 28, 2026
@traviscross traviscross added the I-lang-nominated Nominated for discussion during a lang team meeting. label Jul 28, 2026
@traviscross traviscross added I-lang-nominated Nominated for discussion during a lang team meeting. and removed I-lang-nominated Nominated for discussion during a lang team meeting. labels Jul 28, 2026
Comment thread src/items/functions.md
Comment on lines +513 to +522
r[items.fn.c-variadic.abi]
Only `extern "C"` and `extern "C-unwind"` function definitions can accept a variable argument list.

```rust,compile_fail
unsafe fn f(ap: ...) {} // ERROR: Not supported.
```

```rust,compile_fail
unsafe extern "sysv64" fn f(ap: ...) {} // ERROR: Not supported.
```

@folkertdev folkertdev Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that c_variadic_naked_functions (rust-lang/rust#159746) is in FCP, this section needs to be extended. Do we just do that now, wait for FCP to be over, or do it in a separate PR?

I was thinking of something like this:

A variable argument list is only accepted on [naked functions] for the ABI strings that are listed in [items.extern.variadic.conventions].

```rust
#[unsafe(naked)]
unsafe extern "win64" fn variadic_win64(_: u32, _: ...) -> u32 {
    core::arch::naked_asm!(
        r#"
        push    rax
        mov     qword ptr [rsp + 40], r9
        mov     qword ptr [rsp + 24], rdx
        mov     qword ptr [rsp + 32], r8
        lea     rax, [rsp + 40]
        mov     qword ptr [rsp], rax
        lea     eax, [rdx + rcx]
        add     eax, r8d
        pop     rcx
        ret
    "#,
    )
}
```

[items.extern.variadic.conventions]: ../items/external-blocks.md#items.extern.variadic.conventions
[naked functions]: ../attributes.md#attributes.codegen.naked

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Let's do that in a separate PR (as this one needs to merge as the stabilization has already merged).

Co-authored-by: Daniel Scherzer <daniel.e.scherzer@gmail.com>
@traviscross
traviscross added this pull request to the merge queue Aug 8, 2026
Merged via the queue into rust-lang:master with commit 82da570 Aug 8, 2026
6 checks passed
jhpratt added a commit to jhpratt/rust that referenced this pull request Aug 11, 2026
Update books

## rust-lang/reference

9 commits in afdc77bab886d4455c11247cdd32391bfab636ae..82da570bafd9efed421bdbae0f8603ede8dd308b
2026-08-08 22:04:17 UTC to 2026-07-28 18:20:15 UTC

- add c-variadic function definitions (rust-lang/reference#2177)
- Update `no_mangle` to use the attribute template (rust-lang/reference#1904)
- enums with fields: clarify that repr(C, int) is quite different from repr(int) (rust-lang/reference#2227)
- aliasing rules also apply inside private fields (rust-lang/reference#2304)
- attributes: do not explain syntax in rules (rust-lang/reference#2306)
- Document prohibition on inner attribute macros (rust-lang/reference#2311)
- Use authentication for linkcheck (rust-lang/reference#2319)
- Stabilize passing 128-bit integers via vector registers with `asm!` on x86 (rust-lang/reference#2313)
- Add a rule for attribute macro outline modules (rust-lang/reference#2310)
@rustbot rustbot added this to the 1.99.0 milestone Aug 11, 2026
rust-timer added a commit to rust-lang/rust that referenced this pull request Aug 11, 2026
Rollup merge of #160866 - rustbot:docs-update, r=traviscross

Update books

## rust-lang/reference

9 commits in afdc77bab886d4455c11247cdd32391bfab636ae..82da570bafd9efed421bdbae0f8603ede8dd308b
2026-08-08 22:04:17 UTC to 2026-07-28 18:20:15 UTC

- add c-variadic function definitions (rust-lang/reference#2177)
- Update `no_mangle` to use the attribute template (rust-lang/reference#1904)
- enums with fields: clarify that repr(C, int) is quite different from repr(int) (rust-lang/reference#2227)
- aliasing rules also apply inside private fields (rust-lang/reference#2304)
- attributes: do not explain syntax in rules (rust-lang/reference#2306)
- Document prohibition on inner attribute macros (rust-lang/reference#2311)
- Use authentication for linkcheck (rust-lang/reference#2319)
- Stabilize passing 128-bit integers via vector registers with `asm!` on x86 (rust-lang/reference#2313)
- Add a rule for attribute macro outline modules (rust-lang/reference#2310)
pull Bot pushed a commit to LeeeeeeM/miri that referenced this pull request Aug 16, 2026
Update books

## rust-lang/reference

9 commits in afdc77bab886d4455c11247cdd32391bfab636ae..82da570bafd9efed421bdbae0f8603ede8dd308b
2026-08-08 22:04:17 UTC to 2026-07-28 18:20:15 UTC

- add c-variadic function definitions (rust-lang/reference#2177)
- Update `no_mangle` to use the attribute template (rust-lang/reference#1904)
- enums with fields: clarify that repr(C, int) is quite different from repr(int) (rust-lang/reference#2227)
- aliasing rules also apply inside private fields (rust-lang/reference#2304)
- attributes: do not explain syntax in rules (rust-lang/reference#2306)
- Document prohibition on inner attribute macros (rust-lang/reference#2311)
- Use authentication for linkcheck (rust-lang/reference#2319)
- Stabilize passing 128-bit integers via vector registers with `asm!` on x86 (rust-lang/reference#2313)
- Add a rule for attribute macro outline modules (rust-lang/reference#2310)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.