rust-lang / rust-lang/rustfmt

[Feature Request]: Derive entry per crate

Open
#6,836 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-feature-request P-low SO-merge_derives
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

Feature Request

Derive entry per crate

Summary

Introduce separate derive macro entries grouped by their originating crate. Instead of combining all derives into a single attribute, derives would be organized into multiple #[derive(...)] blocks based on the crate they come from.

Motivation

Grouping derives by crate improves both readability and maintainability of the code. When derives from different ecosystems (e.g., serialization, archiving, standard traits) are separated, it becomes immediately clear which functionality is provided by which dependency.

This structure also makes it easier to:

  1. Navigate and audit dependencies: Developers can quickly identify which crate is responsible for specific derives.
  2. Modify or remove functionality: Adjusting or removing derives tied to a specific crate becomes straightforward without affecting unrelated ones.
  3. Reduce cognitive load: Large, mixed derive lists can be difficult to scan; grouping them provides a more structured and predictable layout.
  4. Improve consistency in larger codebases: Enforcing crate-based grouping encourages a standardized style across teams and projects.

Overall, this change promotes clearer intent, better organization, and easier long-term maintenance, especially in projects that rely on multiple derive-heavy libraries.

Related configuration options

merge_derives

Examples
#[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)] // Rkyv derives
#[derive(serde::Serialize, serde::Deserialize)] // Serde derives
#[derive(Debug, Clone)] // Built-in derives
pub struct Donation {
    verification_token: Uuid,
    message_id: Uuid,
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the merge_derives configuration and the derive-formatting entry points in rustfmt. Use the Donation example as the expected shape: derives should be emitted in separate #[derive(...)] blocks grouped by originating crate, while built-in derives remain distinct.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.