Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix example code for E0617 #87435

Merged
merged 1 commit into from
Jul 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!
}
```