Skip to content

Printed function definition types can be confusing #69232

Closed
@glandium

Description

@glandium

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

Metadata

Metadata

Assignees

Labels

A-FFIArea: Foreign function interface (FFI)A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions