Rust
E0617 Invalid Variadic Argument Fix
E0617 is the compiler refusing to hand a value across a C variadic boundary in a shape the C calling convention cannot promote: an f32, a small integer, or a bool passed where the callee declared only '...'. The diagnostic names the cast that fixes it - c_double for a float, c_int or c_uint for a small integer - and applying that cast is the whole repair. This guide shows the error on the types that draw it, the casts running, and the boundary around the code: the wider types, char, pointers, and string references that pass with no cast at all, and the fixed-parameter call where the same value is fine.
Written December 1, 2026 · Tested with Rust 1.99.1 · 15 min read
- The rule underneath: variadic arguments must survive C promotion
- How to read the diagnostic
- The first failure: the index example
- The same error across the small types
Written December 1, 2026
Tested with Rust 1.99.1
What this guide is
Error E0617 is about the shape of an argument at the moment it crosses into the variadic part of a C function. The error codes index opens: "Attempted to pass an invalid type of variable into a variadic function." Its erroneous example passes 0f32 to printf and fails, because a variadic argument has no declared parameter type to convert to - the C convention promotes each argument on its own, and an f32 has no promoted form the callee can rely on. The index's repair passes 0f64 instead.
The practical payoff is that this is one of the few errors whose diagnostic hands you the finished fix: every E0617 in this guide's probed set carries a help line naming the exact cast, down to showing the rewritten call. The second payoff is knowing which values never need the cast. In the probed set, the wider integers, f64, char, raw pointers, and a &CStr all passed directly, and unsuffixed literals were inferred to allowed types - so the cast belongs only on the small types and f32. Neighboring codes in this area are E0610, a field read on a primitive, and E0618, calling a value that is not a function; E0617 is specifically the variadic argument shape.
Build every program in this guide with rustc --edition 2021. Every call into a variadic function sits in an unsafe block, because the compiler cannot check the arguments against a format string or a parameter list - that missing check is exactly why the type rule exists. In the compiler transcripts below, the file names are the bare names shown on the command line.
The rule underneath: variadic arguments must survive C promotion
A fixed parameter declares its type, so the compiler converts or rejects an argument against a known target. The ... in an extern "C" declaration declares nothing: whatever is passed travels as-is, under the C standard's default argument promotions. The error index puts it this way: "Certain Rust types must be cast before passing them to a variadic function, because of arcane ABI rules dictated by the C standard."
Under those promotions, small integers widen to int or unsigned int, and a float widens to double. Rust does not apply the promotion silently - a value whose type would have to change is refused with E0617, and the help line names the promoted target type to cast to: c_double for f32, c_int for the signed small types and bool, c_uint for the unsigned small types. A value already at a promoted size needs nothing, which is why the boundary below falls where it does.
How to read the diagnostic
In the probed set, an E0617 failure is a single error followed by a single help block. The header names the passed type: "can't pass f32 to variadic function". The carets sit under the argument expression alone - four under 0f32, one under a variable holding the value. The help block then does the repair in miniature: "cast the value to c_double", with the call rewritten and the cast marked with plus signs underneath.
That help block is the repair, not a hint toward one. The target type it names varies with the argument - c_double, c_int, or c_uint in the probed set - and it comes from std::os::raw, which the index notes you may need to import. If your diagnostic has no such help, or the header names a different code, you are in a different situation; the boundary section below covers the two nearest ones.
The first failure: the index example
The smallest shape is the error index's own, an f32 literal passed to printf:
use std::os::raw::{c_char, c_int};
extern "C" {
fn printf(format: *const c_char, ...) -> c_int;
}
fn main() {
unsafe {
printf("%f\n\0".as_ptr() as _, 0f32);
}
}
error[E0617]: can't pass `f32` to variadic function
--> index_fail.rs:7:40
|
7 | printf("%f\n\0".as_ptr() as _, 0f32);
| ^^^^
|
help: cast the value to `c_double`
|
7 | printf("%f\n\0".as_ptr() as _, 0f32 as c_double);
| +++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0617`.
The format string and the %f play no part in the rejection - the compiler never gets to matching arguments against a format. The argument's own type is the whole problem: f32 is narrower than the double a variadic float argument must arrive as.
The same error across the small types
A signed small integer fails the same way, and the help names c_int:
use std::os::raw::{c_char, c_int};
extern "C" {
fn printf(format: *const c_char, ...) -> c_int;
}
fn main() {
let x: i8 = 5;
unsafe {
printf("%d\n\0".as_ptr() as *const c_char, x);
}
}
error[E0617]: can't pass `i8` to variadic function
--> i8_fail.rs:8:52
|
8 | printf("%d\n\0".as_ptr() as *const c_char, x);
| ^
|
help: cast the value to `c_int`
|
8 | printf("%d\n\0".as_ptr() as *const c_char, x as c_int);
| ++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0617`.
An unsigned small integer fails too, with c_uint as the named target:
use std::os::raw::{c_char, c_int};
extern "C" {
fn printf(format: *const c_char, ...) -> c_int;
}
fn main() {
let x: u8 = 5;
unsafe {
printf("%d\n\0".as_ptr() as *const c_char, x);
}
}
error[E0617]: can't pass `u8` to variadic function
--> u8_fail.rs:8:52
|
8 | printf("%d\n\0".as_ptr() as *const c_char, x);
| ^
|
help: cast the value to `c_uint`
|
8 | printf("%d\n\0".as_ptr() as *const c_char, x as c_uint);
| +++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0617`.
The shape is identical to the i8 case with two changes: the header names u8, and the help names c_uint instead of c_int. A boolean fails in the signed family, with c_int named:
use std::os::raw::{c_char, c_int};
extern "C" {
fn printf(format: *const c_char, ...) -> c_int;
}
fn main() {
let x: bool = true;
unsafe {
printf("%d\n\0".as_ptr() as *const c_char, x);
}
}
error[E0617]: can't pass `bool` to variadic function
--> bool_fail.rs:8:52
|
8 | printf("%d\n\0".as_ptr() as *const c_char, x);
| ^
|
help: cast the value to `c_int`
|
8 | printf("%d\n\0".as_ptr() as *const c_char, x as c_int);
| ++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0617`.
In the probed set, i16 and u16 behaved exactly as their 8-bit counterparts - i16 drew the c_int help, u16 the c_uint help - so the failing family is: f32, i8, i16, u8, u16, and bool. Six types, one diagnostic shape, and the only variation is the type named in the header and the cast named in the help.
The repair: apply the cast the help names
The index's own repair passes an f64, which is the same size as c_double - the index says so directly - so no cast expression is even needed:
use std::os::raw::{c_char, c_int};
extern "C" {
fn printf(format: *const c_char, ...) -> c_int;
}
fn main() {
unsafe {
printf("%f\n\0".as_ptr() as _, 0f64);
}
}
0.000000
The output is 0.000000, printed by the real printf. When the value starts life as an f32 variable, the cast the help names does the same job:
use std::os::raw::{c_char, c_double, c_int};
extern "C" {
fn printf(format: *const c_char, ...) -> c_int;
}
fn main() {
let x: f32 = 1.5;
unsafe {
printf("%f\n\0".as_ptr() as *const c_char, x as c_double);
}
}
1.500000
The output is 1.500000 - the value survived the crossing unchanged, at the promoted width. The small types repair together in one call, each with its named cast:
use std::os::raw::{c_char, c_double, c_int};
extern "C" {
fn printf(format: *const c_char, ...) -> c_int;
}
fn main() {
let a: i8 = 5;
let b: bool = true;
let c: char = 'a';
let d: f32 = 1.5;
unsafe {
printf("%d %d %d %f\n\0".as_ptr() as *const c_char, a as c_int, b as c_int, c as c_int, d as c_double);
}
}
5 1 97 1.500000
The output is 5 1 97 1.500000: the i8 arrives as 5, the bool as 1, the character as its code point 97, and the f32 as 1.5. One note on that call: the char cast in it is belt and braces - as the next section shows, a char passes with no cast at all. The casts that call actually needed were the other three.
The boundary: what passes with no cast
The wider integers pass directly. An i32 - already c_int-sized - crosses untouched:
use std::os::raw::{c_char, c_int};
extern "C" {
fn printf(format: *const c_char, ...) -> c_int;
}
fn main() {
let x: i32 = 42;
unsafe {
printf("%d\n\0".as_ptr() as *const c_char, x);
}
}
42
In the probed set, u32, i64, u64, and isize also compiled and ran with no cast, each printing its value - the line falls exactly at promotion width: types at or above int width pass, types below it are refused.
The surprise in the probed set is char. A Rust char is four bytes, already at promotion width, and it passed directly - the same call that rejected the i8 accepted the char and printed its code point:
use std::os::raw::{c_char, c_int};
extern "C" {
fn printf(format: *const c_char, ...) -> c_int;
}
fn main() {
let x: char = 'a';
unsafe {
printf("%d\n\0".as_ptr() as *const c_char, x);
}
}
97
The output is 97. If you grouped char with the small types by instinct, the compiler does not: width, not being a scalar, is the criterion in every probed case.
Pointers pass directly, as C arguments have always done. A raw string pointer crosses untouched:
use std::os::raw::{c_char, c_int};
extern "C" {
fn printf(format: *const c_char, ...) -> c_int;
}
fn main() {
let s = "hello\0";
unsafe {
printf("%s\n\0".as_ptr() as *const c_char, s.as_ptr() as *const c_char);
}
}
hello
And so does a borrowed C string. A &CStr - the reference CString::as_c_str hands back - passed as a variadic argument with no cast and no .as_ptr():
use std::ffi::CString;
use std::os::raw::{c_char, c_int};
extern "C" {
fn printf(format: *const c_char, ...) -> c_int;
}
fn main() {
let s = CString::new("world").unwrap();
let r = s.as_c_str();
unsafe {
printf("%s\n\0".as_ptr() as *const c_char, r);
}
}
world
The output is world in both cases. String arguments are not where E0617 lives; it lives on the small scalar values.
The boundary: it is the variadic position, not the function
Swapping printf for another variadic declaration changes nothing. A differently named extern "C" variadic function rejects the same f32 with the same code and the same help:
use std::os::raw::{c_char, c_int};
extern "C" {
fn my_log(format: *const c_char, ...) -> c_int;
}
fn main() {
unsafe {
my_log("%f\n\0".as_ptr() as *const c_char, 0f32);
}
}
error[E0617]: can't pass `f32` to variadic function
--> own_variadic_fail.rs:7:52
|
7 | my_log("%f\n\0".as_ptr() as *const c_char, 0f32);
| ^^^^
|
help: cast the value to `c_double`
|
7 | my_log("%f\n\0".as_ptr() as *const c_char, 0f32 as c_double);
| +++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0617`.
The rule attaches to the ... in the declaration, not to any particular C function. The same declaration accepts the f64 form - declared here under the name my_log but linked to the real printf, so the call can actually run:
use std::os::raw::{c_char, c_int};
extern "C" {
#[link_name = "printf"]
fn my_log(format: *const c_char, ...) -> c_int;
}
fn main() {
unsafe {
my_log("%f\n\0".as_ptr() as *const c_char, 0f64);
}
}
0.000000
Move the same f32 out of the variadic position and the error disappears entirely. A fixed f32 parameter - here the C library's fabsf - takes the value as it is:
extern "C" {
fn fabsf(x: f32) -> f32;
}
fn main() {
let y = unsafe { fabsf(-1.5f32) };
println!("{}", y);
}
1.5
The output is 1.5. And a genuinely wrong type in a fixed position is a different error altogether: passing an f32 where a fixed f64 parameter stands draws E0308, "mismatched types", not E0617:
extern "C" {
fn fabs(x: f64) -> f64;
}
fn main() {
let y = unsafe { fabs(-1.5f32) };
println!("{}", y);
}
error[E0308]: mismatched types
--> nonvariadic_wrong.rs:5:27
|
5 | let y = unsafe { fabs(-1.5f32) };
| ---- ^^^^^^^ expected `f64`, found `f32`
| |
| arguments to this function are incorrect
|
note: function defined here
--> nonvariadic_wrong.rs:2:8
|
2 | fn fabs(x: f64) -> f64;
| ^^^^ -
help: you can convert an `f32` to an `f64`
|
5 | let y = unsafe { fabs((-1.5f32).into()) };
| + ++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0308`.
So the three situations separate cleanly: a too-narrow type in a variadic position is E0617, the same type in a matching fixed position is fine, and a mismatched type in a fixed position is E0308. The code in the header tells you which of the three you are in before you change anything.
The boundary: unsuffixed literals are inferred
A bare literal has no fixed type yet, and in the probed set the compiler inferred allowed types for both kinds. An integer literal crossed as an int-width value:
use std::os::raw::{c_char, c_int};
extern "C" {
fn printf(format: *const c_char, ...) -> c_int;
}
fn main() {
unsafe {
printf("%d\n\0".as_ptr() as *const c_char, 42);
}
}
42
A floating literal crossed as a double:
use std::os::raw::{c_char, c_int};
extern "C" {
fn printf(format: *const c_char, ...) -> c_int;
}
fn main() {
unsafe {
printf("%f\n\0".as_ptr() as *const c_char, 1.5);
}
}
1.500000
The outputs are 42 and 1.500000. E0617 in the probed set bit only on values whose type was already fixed - a suffixed literal like 0f32, or a variable with a declared small type. If your call site uses plain literals and compiles, that is inference doing the promotion for you, not an exception to the rule.
Fixes in reach order
First, read the help line and apply it literally. E0617's help names the exact target type - c_double, c_int, or c_uint in the probed set - and shows the rewritten call. Import that type from std::os::raw if it is not already in scope and cast the argument. In the probed set, that single change took every failing program to compiling and running.
Second, when you control the value's definition, declare it at the promoted type from the start: hold the number in an f64, i32, or wider variable instead of casting at every call site. The index's own repair is this move - pass 0f64, not a cast of 0f32.
Third, check whether the value is in a variadic position at all before casting anything. The same f32 is a perfectly good fixed argument, and a mismatch there is E0308 with its own fix. Casts added to fixed arguments to silence a variadic error treat the wrong call.
Last, audit the declaration if E0617 appears on a type this guide's probed set shows passing - a wide integer, a pointer, a char. The argument may be sitting in the variadic tail of a declaration whose fixed parameters you meant it for, which is a call-shape mistake, not a type-width one.
Decision summary
E0617, in this guide's probed set, fired exactly when a value of a below-promotion-width type - f32, i8, i16, u8, u16, or bool - was passed into the variadic part of an extern "C" function, whether that function was printf or another variadic declaration. Every diagnostic was a single error naming the type, with carets under the argument and a help block naming the cast: c_double for f32, c_int for the signed small types and bool, c_uint for the unsigned small types. Applying the named cast compiled and ran in every case. Passing directly with no cast were i32, u32, i64, u64, isize, f64, char, a raw *const c_char, a CString pointer, and a &CStr; unsuffixed integer and float literals were inferred to allowed types. The same f32 in a fixed parameter compiled and ran, and a wrong type in a fixed parameter drew E0308 instead.
Checklist
- Read the help block first: E0617 names its own fix - cast to the
std::os::rawtype it specifies (c_double,c_int, orc_uintin the probed set). - Cast only the variadic arguments: fixed parameters take small types as declared, and a mismatch there is E0308, a different repair.
- Do not cast the wide types: integers at
i32width and above,f64,char, and pointers pass as they are. - Prefer declaring the variable at the promoted type when you control its definition, instead of casting at every call site.
- Remember literals: a suffixed
0f32is refused, while an unsuffixed1.5is inferred tof64- the suffix is what fixed the type. - Keep the call in
unsafeand the format string honest: E0617 checks argument widths only; nothing checks that the promoted value matches what the format string claims to read.
Related guides on this site
- E0060 Variadic Function Missing Argument Fix
- E0109 Generic Argument on Non-Generic Type Fix
- E0045 Variadic on Non-C ABI Fix
- E0057 Invalid Number of Arguments Fix
Sources
- Rust error codes index, E0617 - attempted to pass an invalid type of variable into a variadic function; the erroneous example passing
0f32toprintf, the statement that certain Rust types must be cast before passing them to a variadic function because of the C standard's ABI rules, the note that the cast target may need importing fromstd::os::raw, and the repair passing0f64on the ground thatc_doublehas the same size asf64. - std::os::raw module documentation - the platform C type aliases the casts target:
c_doubleas C'sdouble,c_intas C'ssigned int, andc_uintas C'sunsigned int.
Keep Exploring
The full Rust hub \u2014 ownership, structs and enums, async, and measured comparisons.
Every guide on the site in one list, grouped by topic.
Every browser-only checker and verifier on the site.
The C++, Python, Sysadmin, Rust, Go, and TypeScript hubs.