Skip to content

restriction lint: indirect_derive #14979

New issue

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

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

Already on GitHub? Sign in to your account

Open
lolbinarycat opened this issue Jun 5, 2025 · 0 comments
Open

restriction lint: indirect_derive #14979

lolbinarycat opened this issue Jun 5, 2025 · 0 comments
Labels
A-lint Area: New lints

Comments

@lolbinarycat
Copy link

What it does

when enabled, this would produce a warning and suggestion whenever referring to a derive macro through a reexport instead of via the original package.

(optionally this would only trigger if the reexport is behind a feature flag, but i'm not sure how feasible that is)

Advantage

Enabling a derive feature flag has a slight overhead on compile times as it linearizes the dependency tree.

For example, building serde with the derive feature enabled means that serde and serde_derive can't be built in parallel.

This is something that often is done internally in the rust project, see rust-lang/rust#141989.
There is currently no automated way to refactor this, as it requires a level of namespace awareness that most (all?) IDEs lack.

Drawbacks

Some library crates may not want their _derive crates to be part of the public API for semver reasons.

May require adding a new entry to Cargo.toml

Example

use serde::Deserialize;

#[derive(Deserialize)]
struct Foo;

...

Could be written as:

use serde::Deserialize;

#[derive(serde_derive::Deserialize)]
struct Foo;
...
@lolbinarycat lolbinarycat added the A-lint Area: New lints label Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

No branches or pull requests

1 participant