File tree 1 file changed +7
-4
lines changed
compiler/rustc_error_codes/src/error_codes
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.
3
3
Erroneous code example:
4
4
5
5
``` compile_fail,E0617
6
+ # use std::os::raw::{c_char, c_int};
6
7
extern "C" {
7
- fn printf(c : *const i8 , ...);
8
+ fn printf(format : *const c_char , ...) -> c_int ;
8
9
}
9
10
10
11
unsafe {
11
- printf(::std::ptr::null() , 0f32);
12
+ printf("%f\n\0".as_ptr() as _ , 0f32);
12
13
// error: cannot pass an `f32` to variadic function, cast to `c_double`
13
14
}
14
15
```
@@ -21,10 +22,12 @@ to import from `std::os::raw`).
21
22
In this case, ` c_double ` has the same size as ` f64 ` so we can use it directly:
22
23
23
24
``` no_run
25
+ # use std::os::raw::{c_char, c_int};
24
26
# extern "C" {
25
- # fn printf(c : *const i8 , ...);
27
+ # fn printf(format : *const c_char , ...) -> c_int ;
26
28
# }
29
+
27
30
unsafe {
28
- printf(::std::ptr::null() , 0f64); // ok!
31
+ printf("%f\n\0".as_ptr() as _ , 0f64); // ok!
29
32
}
30
33
```
You can’t perform that action at this time.
0 commit comments