rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.62k stars 2.4k forks source link

Improve the diagnostics in virual workspaces #13965

Open VorpalBlade opened 4 months ago

VorpalBlade commented 4 months ago

Problem

I tried to add the following to my virtual workspace:

[lints.rust]
rust-2018-idioms = "warn"

This results in the following diagnostic:

❯ cargo check
error: failed to parse manifest at `/home/user/src/project/Cargo.toml`

Caused by:
  this virtual manifest specifies a `lints` section, which is not allowed

That diagnostic doesn't give a hint about that the solution is to rename the table to workspace.lints.rust. And googling the error did not turn up very useful results either.

Proposed Solution

❯ cargo check
error: failed to parse manifest at `/home/user/src/project/Cargo.toml`

Caused by:
  this virtual manifest specifies a `lints` section, which is not allowed
Suggestion:
  For workspaces, use `workspace.lints` instead

Note the added suggestion. Rustc is usually very good about giving useful hints. I assume Cargo should be able to do so too.

There is a question about what to do when you have a non-virtual workspace. It is not a feature I use myself, so I have no input on the diagnostic in that case.

Notes

No response

VorpalBlade commented 4 months ago

As an added note, it seems inconsistent which keys need to be prefixed by workspace. in workspaces. There is workspace.dependencies but not workspace.profile.release

heisen-li commented 4 months ago

@rustbot label +A-diagnostics +A-workspaces

epage commented 4 months ago

As an added note, it seems inconsistent which keys need to be prefixed by workspace. in workspaces. There is workspace.dependencies but not workspace.profile.release

The schema for Cargo.toml files is generally flat.

We parented inheritable tables under workspace to disambiguate them from the regular top-level table

These tables (mostly) have no effect on their own but are used to help populate regular tables.