Skip to content

cargo-new: workspace is added as an inline table #13345

New issue

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

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

Already on GitHub? # to your account

Closed
weihanglo opened this issue Jan 25, 2024 · 3 comments · Fixed by #13391
Closed

cargo-new: workspace is added as an inline table #13345

weihanglo opened this issue Jan 25, 2024 · 3 comments · Fixed by #13391
Assignees
Labels
C-bug Category: bug Command-new S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review

Comments

@weihanglo
Copy link
Member

weihanglo commented Jan 25, 2024

Problem

In #12779, cargo adds new packages to [workspace.members] automatically. This is great when workspace.member array alreay exists, but the format doesn't look good when workspace array is missing.

Steps

  1. cargo new foo && cd foo
  2. cargo add bar --lib

And you'll get the resulting TOML

workspace = { members = ["bar"] }
[package]
name = "foo"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

Possible Solution(s)

Don't add the new package to workspace.members if there is no existing workspace in Cargo.toml.

Notes

No response

Version

cargo 1.77.0-nightly (1ae631085 2024-01-17)
release: 1.77.0-nightly
commit-hash: 1ae631085f01c1a72d05df1ec81f3759a8360042
commit-date: 2024-01-17
@weihanglo weihanglo added C-bug Category: bug Command-new S-triage Status: This issue is waiting on initial triage. labels Jan 25, 2024
@epage
Copy link
Contributor

epage commented Jan 25, 2024

... is the error instead that we shouldn't be doing this if foo doesn't have a [workspace] at all?

If the existing toml contains an empty inline workspace table like workspace = {}, should we reformat it to [workspace]?

So far, we've taken the approach of preserving what the user already has rather than cleaning it up. That is rustfmt's job.

@weihanglo
Copy link
Member Author

... is the error instead that we shouldn't be doing this if foo doesn't have a [workspace] at all?

This sounds better 👍🏾.

@weihanglo weihanglo added S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review and removed S-triage Status: This issue is waiting on initial triage. labels Jan 25, 2024
@linyihai
Copy link
Contributor

@rustbot claim

I'll try.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: bug Command-new S-accepted Status: Issue or feature is accepted, and has a team member available to help mentor or review
Projects
None yet
3 participants