File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed
compiler/rustc_error_codes/src/error_codes Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -3,12 +3,13 @@ Attempted to pass an invalid type of variable into a variadic function.
33Erroneous code example:
44
55``` compile_fail,E0617
6+ # use std::os::raw::{c_char, c_int};
67extern "C" {
7- fn printf(c : *const i8 , ...);
8+ fn printf(format : *const c_char , ...) -> c_int ;
89}
910
1011unsafe {
11- printf(::std::ptr::null() , 0f32);
12+ printf("%f\n\0".as_ptr() as _ , 0f32);
1213 // error: cannot pass an `f32` to variadic function, cast to `c_double`
1314}
1415```
@@ -21,10 +22,12 @@ to import from `std::os::raw`).
2122In this case, ` c_double ` has the same size as ` f64 ` so we can use it directly:
2223
2324``` no_run
25+ # use std::os::raw::{c_char, c_int};
2426# extern "C" {
25- # fn printf(c : *const i8 , ...);
27+ # fn printf(format : *const c_char , ...) -> c_int ;
2628# }
29+
2730unsafe {
28- printf(::std::ptr::null() , 0f64); // ok!
31+ printf("%f\n\0".as_ptr() as _ , 0f64); // ok!
2932}
3033```
You can’t perform that action at this time.
0 commit comments