-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Problem
Running a command like cargo new main never adds the [workspace] section into the Cargo.toml it just created. This is already reported as a feature request in #8365, but there are more issues with that.
In case you cd into that directory and run cargo new baz there is a message that "baz" was added as a member into the workspace of its parent. But actually nothing is added and there is still no [workspace] section in the first Cargo.toml. But if you add an empty [workspace] section into the first Cargo.toml manually, before adding a child package then the child package will be added into the members array of the [workspace] section as well. If Cargo can't add a new workspace member without the [workspace] section existing then an error must be printed. Otherwise it should create the [workspace] section and add the new member into it. Now it just lies and it looks like a bug.
Steps
This is from Bash of Git for Windows:
$ cargo new --vcs none main && cd main
Creating binary (application) `main` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
$ cat Cargo.toml
[package]
name = "main"
version = "0.1.0"
edition = "2021"
[dependencies]
$ cargo new baz
Creating binary (application) `baz` package
Adding `baz` as member of workspace at `D:\develop\2\main`
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
$ cat Cargo.toml
[package]
name = "main"
version = "0.1.0"
edition = "2021"
[dependencies]
$ rm -rf baz
$ echo "[workspace]" >> Cargo.toml
$ cat Cargo.toml
[package]
name = "main"
version = "0.1.0"
edition = "2021"
[dependencies]
[workspace]
$ cargo new baz
Creating binary (application) `baz` package
Adding `baz` as member of workspace at `D:\develop\2\main`
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
$ cat Cargo.toml
[package]
name = "main"
version = "0.1.0"
edition = "2021"
[dependencies]
[workspace]
members = ["baz"]Possible Solution(s)
No response
Notes
No response
Version
$ cargo version --verbose
cargo 1.79.0 (ffa9cf99a 2024-06-03)
release: 1.79.0
commit-hash: ffa9cf99a594e59032757403d4c780b46dc2c43a
commit-date: 2024-06-03
host: x86_64-pc-windows-msvc
libgit2: 1.7.2 (sys:0.18.3 vendored)
libcurl: 8.6.0-DEV (sys:0.4.72+curl-8.6.0 vendored ssl:Schannel)
os: Windows 10.0.19045 (Windows 10 Pro) [64-bit]