Description
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
- create a Cargo workspace, including at least 2 crates, say
app
andfoo
. The rootCargo.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
- In the sub-crate
foo
, itsCargo.toml
looks like this:
[package]
name = "foo"
version = "0.1.0"
authors = ["[email protected]"]
edition = "2018"
-
build the project using
cargo build
. It should succeed. -
rename
foo
tobar
:git mv foo bar
. -
modify root
Cargo.toml
to replacefoo
withbar
. -
modify sub-crate
Cargo.toml
underbar/
, to replacefoo
withbar
. -
Now run
cargo build
again, orcargo 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)