Configuring lints for an entire workspace?

I have some large workspaces and am trying to figure out how to specify lints centrally for them.

For example I would like:

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

but putting that in Cargo.toml for the workspace doesn't work:

❯ 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

How does one go about configuring lints (rustc as well as clippy) centrally for a whole workspace without having to duplicate and synchronize the configuration across the hundred or so crates in the workspace?

Rust version is 1.78.0

So I figured out the answer. Apparently you need to put:

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

This is probably to support non-virtual workspaces. But the diagnostic could be improved IMO and I'll file an issue for that.

1 Like

Yes, but also, in general, all information that is inheritable by packages in the workspace (but does not alter the workspace itself) is under [workspace.*], and all information that unconditionally applies to the entire workspace (e.g. [patch] and [profile]) is under a different path. This difference matters because workspace inheritance is explicit — each package must specify what it wants to inherit — and the other things are implicit.

Lints aren't inherited by a package until you specify lints.workspace = true in that package's manifest.

5 Likes