diff --git a/compiler/rustc_error_codes/src/error_codes/E0617.md b/compiler/rustc_error_codes/src/error_codes/E0617.md index 1c5d1f87b91..eed384b4959 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0617.md +++ b/compiler/rustc_error_codes/src/error_codes/E0617.md @@ -3,12 +3,13 @@ Attempted to pass an invalid type of variable into a variadic function. Erroneous code example: ```compile_fail,E0617 +# use std::os::raw::{c_char, c_int}; extern "C" { - fn printf(c: *const i8, ...); + fn printf(format: *const c_char, ...) -> c_int; } unsafe { - printf(::std::ptr::null(), 0f32); + printf("%f\n\0".as_ptr() as _, 0f32); // error: cannot pass an `f32` to variadic function, cast to `c_double` } ``` @@ -21,10 +22,12 @@ to import from `std::os::raw`). In this case, `c_double` has the same size as `f64` so we can use it directly: ```no_run +# use std::os::raw::{c_char, c_int}; # extern "C" { -# fn printf(c: *const i8, ...); +# fn printf(format: *const c_char, ...) -> c_int; # } + unsafe { - printf(::std::ptr::null(), 0f64); // ok! + printf("%f\n\0".as_ptr() as _, 0f64); // ok! } ```