Feature request: Add an option to place the arguments of function-like attributes on the same line until `attr_fn_like_width` is exceeded.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
When there are many arguments in the #[derive(...)] attribute, placing one argument per line makes the code vertically long and difficult to read.
Could you consider adding an option to place the arguments on the same line until the attr_fn_like_width is exceeded, as shown in the example below?
Example
Current behaviour (rustfmt 1.7.0-stable (3f5fd8d 2024-08-06)):
use derive_more::{
Add, AddAssign, AsMut, AsRef, Deref, DerefMut, Div, DivAssign, From, Into, Mul, MulAssign, Neg,
Rem, RemAssign, Sub, SubAssign,
};
#[repr(transparent)]
#[derive(
Copy,
Clone,
Debug,
PartialEq,
PartialOrd,
Deref,
DerefMut,
Neg,
Add,
AddAssign,
Sub,
SubAssign,
Mul,
MulAssign,
Div,
DivAssign,
Rem,
RemAssign,
From,
Into,
AsRef,
AsMut,
)]
pub struct Meters(pub f32);
fn main() {}
Expected behaviour (when attr_fn_like_width=70):
use derive_more::{
Add, AddAssign, AsMut, AsRef, Deref, DerefMut, Div, DivAssign, From, Into, Mul, MulAssign, Neg,
Rem, RemAssign, Sub, SubAssign,
};
#[repr(transparent)]
#[derive(
Copy, Clone, Debug, PartialEq, PartialOrd, Deref, DerefMut, Neg,
Add, AddAssign, Sub, SubAssign, Mul, MulAssign, Div, DivAssign,
Rem, RemAssign, From, Into, AsRef, AsMut,
)]
pub struct Meters(pub f32);
fn main() {}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating rustfmt's formatting path for function-like attributes and the existing attr_fn_like_width option. Reproduce the issue with the provided derive example, then determine how grouped arguments should wrap at the configured width. Done means the example matches the expected output without regressing other function-like attributes.
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
- 35/100