rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

Warn if a `[patch.*]` section is used on a dependency of a library

Open fuchsnj opened this issue 2 months ago • 0 comments

What it does

If a [patch] section is used to override a dependency, it is only applicable to the current crate. Dependencies ignore this. If a library tries to patch a dependency (not a dev-dependency or build-dependency) this is useless since it won't apply to anything actually using this library, but it would appear to work in tests.

Advantage

  • Prevents accidental use of the [patch] section when it won't work

Drawbacks

There might be some edge cases where this is wanted, but I'm not currently aware of any.

Example

[patch.crates-io]
foo = { git = 'https://github.com/example/foo.git' }

Would generate a clippy warning such as

The patch override for dependency `foo` will be ignored outside of this crate.

fuchsnj avatar Jun 21 '24 19:06 fuchsnj