You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Variadic #[device] externs surface as a codegen-time error instead of a #[device]-time diagnostic #876
A extern \"C\" fn marked #[device] that is variadic is only caught deep in device
codegen, where the error has no connection to the offending #[device] attribute or the
function signature. Users see a generic "variadic device externs are not supported" string
rather than a pointed diagnostic at the definition.
Attribute expansion / validation: crates/cuda-macros/src/lib.rs (the #[device] proc
macro) and crates/rustc-codegen-cuda/src/collector.rs.
Proposed fix
Move the c_variadic check into the #[device] macro / collector validation pass so it
is reported with a span pointing at the function signature, e.g.
"#[device] externs cannot be variadic". Keep the codegen guard as a defensive
assertion only. This matches how other unsupported device-extern shapes (e.g. char, f128, arrays-by-value) could also be lifted to attribute time.
Acceptance criteria (so a PR passes)
A variadic #[device] extern produces a compile_error!-style diagnostic with a span
on the function, not a runtime codegen panic/string.
A compile_fail trybuild fixture is added asserting the new message.
cargo test -p cuda-macros (and the existing device-extern tests) stay green.
changed the title [-]Variadic externs surface as a codegen-time error instead of a -time diagnostic[/-][+]Variadic `#[device]` externs surface as a codegen-time error instead of a `#[device]`-time diagnostic[/+]on Aug 13, 2026
What you get today, and only if the function is actually called from a kernel:
error: [rustc_codegen_cuda] Device codegen failed: Invalid device-extern
signature: `variadic_helper` is variadic; variadic device externs
are not supported
^ no file, no line, no span; fires at final-binary codegen
(One nit on the issue text: this is a clean rustc fatal with exit 101, not a codegen panic, and nothing is swallowed. The gap is purely the missing span and the late stage.)
And the hole nobody noticed: a variadic #[device] extern that is declared but never called compiles silently, because the collector only registers externs reached from kernel MIR.
The fix we expect
In the macro, generate_device_extern_block (crates/cuda-macros/src/lib.rs), about six lines modeled on the spanned ABI check a few lines above it. syn's Signature.variadic exposes the ... tokens directly:
ifletSome(variadic) = &foreign_fn.sig.variadic{return syn::Error::new_spanned(variadic,"#[device] externs cannot be variadic").to_compile_error().into();}
today after
declared AND called late, no span spanned error at macro expansion
declared, never called compiles! spanned error at macro expansion
Two corrections to the proposal
The codegen guard at device_codegen.rs stays a real error, not a defensive assertion: the collector detects device externs by the reserved name prefix, so a hand-written extern block bypasses the macro entirely, and the backend check is the only gate on that path.
Drop the aside about lifting char/f128/array checks to macro time. Those need resolved types; type MyF = f128; or a generic hides the type from a syntactic macro. Variadic ... is the one purely syntactic check, which is why it belongs here.
Acceptance criteria (updated)
The spanned macro error above.
A trybuild fixture pair modeled on the existing device_extern_wrong_abi.{rs,stderr}, registered in tests/macro_guard.rs (trybuild is already a dev-dependency; zero new infrastructure).
The existing codegen rejection untouched; cargo test -p cuda-macros green.
Activity
[-]Variadic externs surface as a codegen-time error instead of a -time diagnostic[/-][+]Variadic `#[device]` externs surface as a codegen-time error instead of a `#[device]`-time diagnostic[/+]nihalpasham commentedon Aug 14, 2026
Verified: real gap, and we'd welcome a PR. Two corrections to the proposal below, so here is the full spec.
The problem
What you get today, and only if the function is actually called from a kernel:
(One nit on the issue text: this is a clean rustc fatal with exit 101, not a codegen panic, and nothing is swallowed. The gap is purely the missing span and the late stage.)
And the hole nobody noticed: a variadic
#[device]extern that is declared but never called compiles silently, because the collector only registers externs reached from kernel MIR.The fix we expect
In the macro,
generate_device_extern_block(crates/cuda-macros/src/lib.rs), about six lines modeled on the spanned ABI check a few lines above it. syn'sSignature.variadicexposes the...tokens directly:What the user sees after:
Both holes close at once:
Two corrections to the proposal
type MyF = f128;or a generic hides the type from a syntactic macro. Variadic...is the one purely syntactic check, which is why it belongs here.Acceptance criteria (updated)
device_extern_wrong_abi.{rs,stderr}, registered intests/macro_guard.rs(trybuild is already a dev-dependency; zero new infrastructure).cargo test -p cuda-macrosgreen.cuda-macros: reject a variadic `#[device]` extern at expansion (NVIDI…