Skip to content

Cargo should not use rustc cache results (.rustc_info.json) for failures #15358

Open
@tomoverlund

Description

@tomoverlund

Problem

So I was setting up a customized rustc, stepping outside the bounds of rustup toolchains, and I got an error invoking rustc when running Cargo. I fix the error, then re-run, and immediately get the same error. I run strace to see if I can spot the problem, and I see the error message printed, but no system call to run rustc. I was going crazy!

I finally traced this to src/cargo/util/rustc.rs::cached_output():

if self.data.outputs.contains_key(&key) {
    debug!("rustc info cache hit");
} else {
    // run command
}
let output: &Output = &self.data.outputs[&key];
if output.success {
    Ok((output.stdout.clone(), output.stderr.clone()))
} else {
    Err(ProcessError::new_raw(
        msg: &format!("process didn't exit successfully: {}", cmd),
        output.code,
        &output.status,
        stdout: Some(output.stdout.as_ref()),
        stderr: Some(output.stderr.as_ref()),
    ) ProcessError                                                                                                                                                 
    .into())
}

After I removed the .rustc_info.json cache file, my cargo invocation worked. So long story short, considering that command caches are imperfect, it should not cache failures, to give the user the best chance of fixing the problem.

I also think if a cached result is used, it should append a (cached) to the standard output, because the cache is imperfect, and this might be a vital clue if something is not being rebuilt when the user expects it to be.

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version


Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cachingArea: caching of dependencies, repositories, and build artifactsC-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions