Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cargo check use older version of code #15073

Open
Jeanbouvatt opened this issue Jan 16, 2025 · 6 comments
Open

Cargo check use older version of code #15073

Jeanbouvatt opened this issue Jan 16, 2025 · 6 comments
Labels
A-rebuild-detection Area: rebuild detection and fingerprinting C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@Jeanbouvatt
Copy link

Problem

cargo check raise error although it should not, cargo build works fine. file_1.rs of my code base call a function from another file file_2.rs. cargo check seems to use an older version of file_2.rs. which raises error

Steps

I am unsure on how to reproduce the error. I tried to provide an archive of my project but compressed archive weight 200 MB, upload thus fails on github. If I try to remove target/ then upload might work but problem disappear

Possible Solution(s)

Cargo check should know the file has changed and, therefore, not raise an error.

Notes

Here are some more advanced details on how

I work on a project with two subprojects

.
├── Cargo.lock
├── Cargo.toml
├── yake
│   ├── Cargo.toml
│   └── src
│       ├── cli.rs
│       └── main.rs
└── yake_rust
    ├── Cargo.toml
    ├── README.md
    └── src
        └── stopwords
            └── mod.rs

yake_rust provides libs and stuff while yake provides CLI, yake depends on yake_rust

# yake/Cargo.toml
# [...] 
[dependencies]
yake-rust = { path = "../yake_rust" }
# [...]

cli.rs defines parse_language as such:

fn parse_language(cli_language: &str) -> Result<StopWords, String> {
    StopWords::predefined(cli_language)
        .ok_or_else(|| format!("Could not find language {}, did you enable this feature?", cli_language))
}

ok_or_else is a method for Option returned by StopWords::predefined defined in yake_rust/src/stopwords/mod.rs:

    pub fn predefined(lang: &str) -> Option<Self>

However an older version of this code used Result as a return type of StopWords:

    pub fn predefined(lang: &str) -> Result<Self, String>

running cargo check I got :

02:38:41 jean@jean:~/dev/yake-rust (optional_json U:5 ✗)
      ▶  $ cargo check
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package:   /home/jean/dev/yake-rust/yake_rust/Cargo.toml
workspace: /home/jean/dev/yake-rust/Cargo.toml
    Checking yake v0.1.0 (/home/jean/dev/yake-rust/yake)
error[E0599]: no method named `ok_or_else` found for enum `Result` in the current scope
  --> yake/src/cli.rs:82:10
   |
81 | /     StopWords::predefined(cli_language)
82 | |         .ok_or_else(|| format!("Could not find language {}, did you enable this feature?", cli_language))
   | |_________-^^^^^^^^^^
   |
help: there is a method `or_else` with a similar name
   |
82 |         .or_else(|| format!("Could not find language {}, did you enable this feature?", cli_language))
   |          ~~~~~~~

For more information about this error, try `rustc --explain E0599`.
error: could not compile `yake` (bin "yake") due to 1 previous error

It feels like cargo check use a cached version of this file. cargo build work fine though

      ▶  $ cargo build
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
# [...]

warning: `yake` (bin "yake") generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s

Version

cargo 1.82.0 (8f40fc59f 2024-08-21)
release: 1.82.0
commit-hash: 8f40fc59fb0c8df91c97405785197f3c630304ea
commit-date: 2024-08-21
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.9.0-DEV (sys:0.4.74+curl-8.9.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Ubuntu 22.4.0 (jammy) [64-bit]
@Jeanbouvatt Jeanbouvatt added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Jan 16, 2025
@Jeanbouvatt
Copy link
Author

Updating cargo with rustup update stable also removed the problem:

cargo 1.84.0 (66221abde 2024-11-19)
release: 1.84.0
commit-hash: 66221abdeca2002d318fde6efff516aab091df0e
commit-date: 2024-11-19
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.9.0-DEV (sys:0.4.74+curl-8.9.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Ubuntu 22.4.0 (jammy) [64-bit]

I still have an archive of my old project with bug, including target directory If you need

@weihanglo
Copy link
Member

Updating toolchain works because caches are not compatible between two versions of Rust.

Would you mind adding -Zchecksum-freshness for each cargo invocation and try again? That flag switches to file checksum based rebuild detection rather than mtime.

@Jeanbouvatt
Copy link
Author

I cannot reproduce the problem, possibly because I updated my cargo version to 1.84.

I tried rustup toolchain install 1.82.0 then cargo +1.82.0 check with no raised error. Using -Zchecksum-freshness raised error since I was not using nightly build but I don't know which nightly I should get to match as closely as possible 1.82.0

@weihanglo
Copy link
Member

Maybe set the env var RUSTC_BOOTSTRAP=1 and try again?

@weihanglo weihanglo added the A-rebuild-detection Area: rebuild detection and fingerprinting label Jan 16, 2025
@weihanglo
Copy link
Member

@Jeanbouvatt
Copy link
Author

Jeanbouvatt commented Jan 16, 2025

RUSTC_BOOTSTRAP=1 did not provide different result for cargo +1.82.0 check.Sorry I cannot reproduce issue 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rebuild-detection Area: rebuild detection and fingerprinting C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants