Cargo check with git repository issues

I have two crates that I use in my projects that I have on Github, one is for maths and one is for graphics. The graphics crate uses some features for the maths crate for camera maths and mesh generation.

When using cargo check on the graphics crate, it reports that the Ord trait is not implemented for my Vector 3 type despite the fact that it is:

error[E0277]: the trait bound `Vector3: Ord` is not satisfied
impl Ord for Vector3 {

(I have excluded the ordering code as it is quite long and not relevant here)

Furthermore, in another project that uses both, cargo check also claims the camera maths file has an issue as I cannot multiply my Matrix3 type by Vector3 despite, again, this being possible:

error[E0277]: cannot multiply `Matrix3` by `Vector3`
impl Mul<Vector3> for Matrix3 {
    type Output = Vector3;
    fn mul(self, rhs: Vector3) -> Self::Output {
        let x = rhs.dot(self.x);
        let y = rhs.dot(self.y);
        let z = rhs.dot(self.z);
        Vector3::new(x, y, z)
    }
}

Despite cargo check claiming there are issues, the code all compiles fine and runs as expected, the main issue is that it seems to cause issues with my rust extension in VSCode so it doesn't give me syntax highlighting or proper intellisense. Running cargo update doesn't fix the issue either as the crates are all up to date.

I would be interested to know if there is a fix for this, or if it's just a problem I'll have to deal with.

Github links if needed:

I haven’t had time to investigate your code, but this sounds like you’ve got multiple Vector3 type definitions somewhere, and you’re accidentally using the wrong one. Check any glob imports you’re using (especially from 3rd-party crates) to see if they define their own Vector3 that’s shadowing yours.

I notice you have the same package under [dependencies] as well as [dev-dependencies], can you remove the [dev-dependencies] and try again?

2 Likes

I tried that, problem still persists

I've double checked all the files with problems, and there doesn't appear to be an extra Vector3 type

this shouldn't happen in theory, cargo check basically is doing the same work as cargo build except the backend codegen is skipped. do you have different toolchains installed, or do you have special configuration for rust-analyzer?

also, might be a cache issue. did you try cargo clean before cargo check?

2 Likes

I have a gut feeling you are mistaking Ord and PartialOrd somewhere.

Running cargo check fixed the issue, I had genuinely no clue that you had to do that. Turns out the problem was on my end just in a completely different way than I imagined, thank you for your help.

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.