Skip to content

Commit 00198dd

Browse files
committed
fix example code for E0617
1 parent 18840b0 commit 00198dd

File tree

1 file changed

+7
-4
lines changed
  • compiler/rustc_error_codes/src/error_codes

1 file changed

+7
-4
lines changed

compiler/rustc_error_codes/src/error_codes/E0617.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ Attempted to pass an invalid type of variable into a variadic function.
33
Erroneous code example:
44

55
```compile_fail,E0617
6+
# use std::os::raw::{c_char, c_int};
67
extern "C" {
7-
fn printf(c: *const i8, ...);
8+
fn printf(format: *const c_char, ...) -> c_int;
89
}
910
1011
unsafe {
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`).
2122
In 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+
2730
unsafe {
28-
printf(::std::ptr::null(), 0f64); // ok!
31+
printf("%f\n\0".as_ptr() as _, 0f64); // ok!
2932
}
3033
```

0 commit comments

Comments
 (0)