Very confused about dependencies

I'm very confused about a type problem in a project (GitHub - brmmm3/scandir-rs: Fast scandir implementation based on jwalk which is implemented in Rust.). In this project I'm using another Rust project (GitHub - brmmm3/jwalk: Filesystem walk performed in parallel with streamed and sorted results).
The jwalk project itself compiles with success on Windows and on Linux., BUT when I use this project in scandir-rs project then the compilation fails on Windows with the following errors:

error[E0308]: mismatched types
   --> D:\Workspace\Rust\jwalk\src\core\metadata.rs:100:21
    |
99  |                 DeviceIoControl(
    |                 --------------- arguments to this function are incorrect
100 |                     self.as_raw_handle(),
    |                     ^^^^^^^^^^^^^^^^^^^^ expected `winapi::ctypes::c_void`, found `std::ffi::c_void`
    |
    = note: `std::ffi::c_void` and `winapi::ctypes::c_void` have similar names, but are actually distinct types
note: `std::ffi::c_void` is defined in crate `core`
   --> C:\Users\bam5wi\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\ffi\mod.rs:204:1
    |
204 | pub enum c_void {
    | ^^^^^^^^^^^^^^^
note: `winapi::ctypes::c_void` is defined in crate `winapi`
   --> C:\Users\bam5wi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\lib.rs:38:5
    |
38  |     pub enum c_void {}
    |     ^^^^^^^^^^^^^^^
note: function defined here
   --> C:\Users\bam5wi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\um\ioapiset.rs:38:12
    |
38  |     pub fn DeviceIoControl(
    |            ^^^^^^^^^^^^^^^

error[E0308]: mismatched types
   --> D:\Workspace\Rust\jwalk\src\core\metadata.rs:119:44
    |
119 |             cvt(GetFileInformationByHandle(self.as_raw_handle(), &mut info))?;
    |                 -------------------------- ^^^^^^^^^^^^^^^^^^^^ expected `winapi::ctypes::c_void`, found `std::ffi::c_void`
    |                 |
    |                 arguments to this function are incorrect
    |
    = note: `std::ffi::c_void` and `winapi::ctypes::c_void` have similar names, but are actually distinct types
note: `std::ffi::c_void` is defined in crate `core`
   --> C:\Users\bam5wi\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\ffi\mod.rs:204:1
    |
204 | pub enum c_void {
    | ^^^^^^^^^^^^^^^
note: `winapi::ctypes::c_void` is defined in crate `winapi`
   --> C:\Users\bam5wi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\lib.rs:38:5
    |
38  |     pub enum c_void {}
    |     ^^^^^^^^^^^^^^^
note: function defined here
   --> C:\Users\bam5wi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\um\fileapi.rs:333:12
    |
333 |     pub fn GetFileInformationByHandle(
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^

I'm using latest Rust nightly.

1 Like

If you have two different types with the same name, then they are still different types.

The winapi crate provides a feature that will turn them into the same type:

[dependencies]
winapi = { version = "...", features = ["std"] }

Alternatively, you can insert a cast.

self.as_raw_handle().cast()
1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.