rust-osdev / x86_64

Library to program x86_64 hardware.
https://docs.rs/x86_64
Apache License 2.0
801 stars 132 forks source link

Trait Mismatch Error When Building the Project with `cargo build` #512

Open isaka-james opened 14 hours ago

isaka-james commented 14 hours ago

I am currently working on a project and encountered a trait mismatch error in the x86_64 crate while building. Since I don't have time to rewrite the library, I decided to test the crate separately by cloning it and attempting to build it.

Steps I followed:

  1. Cloned the repository and tried building it on a fresh setup.
  2. Encountered the same error related to a trait mismatch in the steps_between method in the x86_64 crate.

The error message I am receiving is as follows:

error[E0053]: method `steps_between` has an incompatible type for trait
   --> /home/masterplan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/x86_64-0.15.1/src/addr.rs:362:51
    |
362 |     fn steps_between(start: &Self, end: &Self) -> Option<usize> {
    |                                                   ^^^^^^^^^^^^^ expected `(usize, Option<usize>)`, found `Option<usize>`
    |
    = note: expected signature `fn(&addr::VirtAddr, &addr::VirtAddr) -> (usize, Option<usize>)`
               found signature `fn(&addr::VirtAddr, &addr::VirtAddr) -> Option<usize>`
help: change the output type to match the trait
    |
362 |     fn steps_between(start: &Self, end: &Self) -> (usize, Option<usize>) {
    |                                                   ~~~~~~~~~~~~~~~~~~~~~~

Steps to reproduce:

  1. Clone the repository and enter the directory:

    git clone https://github.com/rust-osdev/x86_64
    cd x86-64
  2. Set the Rust toolchain to nightly (already set in my environment):

    rustup default nightly
  3. Attempt to build the project with the following command:

    cargo build

Result:
The build fails with the error related to the trait mismatch, as shown in the terminal output above.

Screenshots/Terminal Output:

Image

Image

Image

tsatke commented 12 hours ago

Caused by rust-lang/rust/pull/130867

For now, I'd suggest you use a nightly version before that PR was merged until a version containing the fix is released.