Rollup merge of #87435 - ibraheemdev:patch-4, r=JohnTitor
fix example code for E0617 Closes #86908
This commit is contained in:
commit
9222984636
@ -3,12 +3,13 @@ Attempted to pass an invalid type of variable into a variadic function.
|
|||||||
Erroneous code example:
|
Erroneous code example:
|
||||||
|
|
||||||
```compile_fail,E0617
|
```compile_fail,E0617
|
||||||
|
# use std::os::raw::{c_char, c_int};
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn printf(c: *const i8, ...);
|
fn printf(format: *const c_char, ...) -> c_int;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
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`
|
// 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:
|
In this case, `c_double` has the same size as `f64` so we can use it directly:
|
||||||
|
|
||||||
```no_run
|
```no_run
|
||||||
|
# use std::os::raw::{c_char, c_int};
|
||||||
# extern "C" {
|
# extern "C" {
|
||||||
# fn printf(c: *const i8, ...);
|
# fn printf(format: *const c_char, ...) -> c_int;
|
||||||
# }
|
# }
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
printf(::std::ptr::null(), 0f64); // ok!
|
printf("%f\n\0".as_ptr() as _, 0f64); // ok!
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user