Skip to content

Commit

Permalink
Rollup merge of #87435 - ibraheemdev:patch-4, r=JohnTitor
Browse files Browse the repository at this point in the history
fix example code for E0617

Closes #86908
  • Loading branch information
JohnTitor authored Jul 28, 2021
2 parents 87c9f32 + 00198dd commit 9222984
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions compiler/rustc_error_codes/src/error_codes/E0617.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
}
```
Expand All @@ -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!
}
```

0 comments on commit 9222984

Please sign in to comment.