rust-lang / rust-lang/rustfmt

Feature request: reorder_type_constraints

Open
#5,116 8 comments 5 reactions 1 assignee View on GitHub

@0xangelo is already working on this.

Since Apr 19, 2022.

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

Description

Requested feature(s):

EDIT: (1) is a duplicate of #4112, which was a duplicate of #1867 - ignore this and focus on #2.

  1. Use reorder_derive_items to have rustfmt change:
#[derive(PartialEq, Copy, Display, Clone)]

Into:

#[derive(Clone, Copy, Display, PartialEq)]

That is, alphabetically sort the derived types.

  1. Use reorder_type_constraints to have rustfmt change:
pub fn<T: PartialEq + Copy + Debug + 'static + Clone>foo(...) { ... }

Into:

pub fn<T: 'static + Clone + Copy + Debug + PartialEq>foo(...) { ... }

That is, alphabetically sort the contsraint types (and sort lifetimes before types).

Motivation:

When there are more than 2-3 types in either derive or a constraint, it is tedius and error-prone to manually ensure they all appear in the same order. However it is useful for them to be in a deterministic order as this makes it easier to read a list, and more importantly to see the difference between two lists.

Options

Perhaps "standard" traits should be sorted before all other traits?

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.