Cargo.toml lint config "allow" is not respected? (Possible bug)

With the release of 1.74, I've moved my Clippy configuration from into Cargo.toml. However, it appears that opting in to clippy::nursery and then allowing specific lints doesn't work. Here's a subset of my Cargo.toml:

all = "deny"
pedantic = "warn"
nursery = "warn"

redundant_pub_crate = "allow"     # Has false positives that conflict with unreachable_pub

And here's an excerpt from cargo clippy:

  = help: for further information visit
  = note: `-W clippy::redundant-pub-crate` implied by `-W clippy::nursery`
  = help: to override `-W clippy::nursery` add `#[allow(clippy::redundant_pub_crate)]

Adding #![allow(clippy::redundant_pub_crate)] to the crates that trigger the lint silences it. Why doesn't the redundant_pub_crate = "allow" in Cargo.toml have the same effect?


Isn't the inline allow the recommend style for avoiding or silencing false positives?

You mean on a case-by-case basis? I don't think that would be preferable for cases like this where the lint is a nursery lint that is known to conflict with a different enabled lint.

1 Like

Yes I think that is the advice on a case-by-case basis.

From the Cargo reference manual, it looks like you're supposed to use a priority field to specify the precedence of lint levels, so e.g. yours could be

all = { level = "deny", priority = -1 }
pedantic = "warn"
nursery = "warn"

redundant_pub_crate =  { level = "allow", priority = 1 }     # Has false positives that conflict with unreachable_pub

As I understand it, this is because the TOML format says that the order of keys in a section isn't supposed to matter, so Cargo can't just apply lint levels in the order they appear in in the config file like happens for rustc arguments or attributes.

The RFC lists some of the design choices for precedence of lints. Of note, it appears that warning users when lint levels are ambiguous is planned.


That makes sense, and works; thank you!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.