add c-variadic function definitions - #2177
Conversation
…-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
…-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
…-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
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
|
The 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. |
|
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. |
|
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
Also spirv and bpf just fundamentally do not support this feature, so there you'd always get an error. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
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.
88338f3 to
d8b62a8
Compare
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.
|
@rustbot label -S-waiting-on-stabilization Stabilization merged in rust-lang/rust#155697 |
| 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. | ||
| ``` |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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>
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)
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)
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)
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: