Skip to content

"cargo check" (incorrectly) shows compiler errors that are not present when running "cargo build" #9971

@RedBreadcat

Description

@RedBreadcat

Problem
I have a workspace of several crates. Two such crates are "common" (a library crate) and "game_lib", another library that depends on "common".
"common" contains several functions that are pass-by-value that were once pass-by-reference.

// Current
pub fn rotate_point_about_origin(pt: Vector2, rot: Radians, origin: Vector2) -> Vector2 {
    rotate_point(pt - origin, rot) + origin
}

// Old
pub fn rotate_point_about_origin(pt: &Vector2, rot: Radians, origin: &Vector2) -> Vector2 {
    rotate_point(pt - origin, rot) + origin // Some of this implementation was different. I can't recall how. It does not seem relevant though. In any case, it compiled.
}

However, when I run cargo c in game_lib, I'm going getting errors that suggest that the compiler is seeing the old function signature. These errors occur in multiple places in game_lib, not just the example below. They occur for multiple functions inside common too, not just geometry::rotate_point_about_origin.

error[E0308]: mismatched types
   --> game_lib\src\systems\foo\bar.rs:107:53
    |
107 |                 geometry::rotate_point_about_origin(bazz_points[2], -main_camera_rot, view_centre),
    |                                                     ^^^^^^^^^^^^^^
    |                                                     |
    |                                                     expected reference, found struct `Matrix`
    |                                                     help: consider borrowing here: `&bazz_points[2]`
    |
    = note: expected reference `&Matrix<f32, Const<2_usize>, Const<1_usize>, ArrayStorage<f32, 2_usize, 1_usize>>`
                  found struct `Matrix<f32, Const<2_usize>, Const<1_usize>, ArrayStorage<f32, 2_usize, 1_usize>>`

Running cargo b, there is no such false error. rust-analyzer does not see the false error. When I made this change a few days ago, I'm pretty sure I would have run cargo c multiple times, and did not see the error then.
I've encountered this issue a couple of other times in the past. It pops up maybe once every couple of weeks. Running cargo clean always seems to resolve the issue, but I haven't done so yet in case there's valuable information that may be gleamed.

Steps

  1. Have a workspace of multiple crates that depend on each other
  2. Make some changes in a dependent crate.
  3. [I don't know what the direct cause of the bug is.]
  4. Run cargo c and see a compiler error.

Possible Solution(s)
This feels like some kind of caching issue. Could cargo be caching some of the intermediate data used by cargo c?

Notes
Output of cargo version --verbose:

cargo 1.55.0 (32da73ab1 2021-08-23)
release: 1.55.0
commit-hash: 32da73ab19417aa89686e1d85c1440b72fdf877d
commit-date: 2021-08-23

rustc 1.55.0 (c8dfcfe04 2021-09-06)
Windows 10

Output of rustup show:

Default host: x86_64-pc-windows-msvc
rustup home:  C:\Users\[snip]\.rustup

installed toolchains
--------------------

stable-x86_64-pc-windows-msvc
nightly-x86_64-pc-windows-msvc

active toolchain
----------------

stable-x86_64-pc-windows-msvc (default)
rustc 1.55.0 (c8dfcfe04 2021-09-06)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions