Closed
Description
I tried this code:
use curl_sys::{curl_easy_setopt, CURLOPT_READFUNCTION};
use libc;
// (...)
curl_easy_setopt(curl, CURLOPT_READFUNCTION, libc::fread);
I expected to see this happen: maybe not a failure, or a failure that is not completely confusing.
Instead, this happened:
error[E0617]: can't pass `unsafe extern "C" fn(*mut core::ffi::c_void, usize, usize, *mut libc::unix::FILE) -> usize {libc::unix::fread}` to variadic function
--> hg_connect.rs:844:62
|
844 | curl_easy_setopt(curl, CURLOPT_READFUNCTION, libc::fread);
| ^^^^^^^^^^^
|
help: cast the value to `unsafe extern "C" fn(*mut core::ffi::c_void, usize, usize, *mut libc::unix::FILE) -> usize`
|
844 | curl_easy_setopt(curl, CURLOPT_READFUNCTION, libc::fread as unsafe extern "C" fn(*mut core::ffi::c_void, usize, usize, *mut libc::unix::FILE) -> usize);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Note how it suggests to cast to the exact same type it started with.
rustc --version --verbose
:
rustc 1.43.0-nightly (5e7af4669 2020-02-16)
binary: rustc
commit-hash: 5e7af4669f80e5f682141f050193ab679afdb4b1
commit-date: 2020-02-16
host: aarch64-unknown-linux-gnu
release: 1.43.0-nightly
LLVM version: 9.0