Skip to content

cargo clean and cargo build fails to handle renamed sub-crate in a workspace #9319

Closed
@keepsimple1

Description

@keepsimple1

Problem
In a workspace, after doing git mv foo bar to rename a sub-crate, cargo build and cargo clean fails to find renamed sub-crate.

what currently happens:

$ cargo build
error: failed to read `/Users/me/work/foo/Cargo.toml`

Caused by:
  No such file or directory (os error 2)

$ cargo clean
error: failed to read `/Users/me/work/foo/Cargo.toml`

Caused by:
  No such file or directory (os error 2)

what you expected to happen:

cargo build, especially cargo clean can find foo was renamed to bar, and continue to work.

Steps

  1. create a Cargo workspace, including at least 2 crates, say app and foo. The root Cargo.toml looks like:
[workspace]
members = [
    "app",
    "foo"
]

app is an application (executable), while foo is a library. The structure looks like this:

├── Cargo.toml
├── app
│   ├── Cargo.toml
│   ├── src
│   │   ├── main.rs
├── foo
│   ├── Cargo.toml
│   ├── src
│   │   ├── lib.rs
  1. In the sub-crate foo, its Cargo.toml looks like this:
[package]
name = "foo"
version = "0.1.0"
authors = ["[email protected]"]
edition = "2018"
  1. build the project using cargo build. It should succeed.

  2. rename foo to bar: git mv foo bar .

  3. modify root Cargo.toml to replace foo with bar.

  4. modify sub-crate Cargo.toml under bar/, to replace foo with bar.

  5. Now run cargo build again, or cargo clean. Will see the errors.

Possible Solution(s)
Not a real fix: remove the project and use git to re-pull the project.

Notes
Tried to remove target/ and remove Cargo.lock, did not fix the issue.

Output of cargo version:

cargo 1.51.0 (43b129a 2021-03-16)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Error and warning messages generated by Cargo itself.C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions