attributes on expressions end up with confusing line breaks
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Thread on Zulip
Some code I'm working on right now that ends up with terrible formatting when using rustfmt on stable:
(note the code is in an attribute macro, so it works just fine on stable.)
let new_entry = #[hdl(sim)]
BTBEntry {
start_pc,
target_pc: target_pc.unwrap_or(0u64),
fallthrough_offset,
insn_kind,
addr_kind,
};
let entry_mut = &mut this.branch_target_buffer.branch_pc_to_target_map[btb_entry_index];
*entry_mut = #[hdl(sim)]
HdlSome(new_entry);
It was previously stated that the formatting rules for attributes is designed for items, not expressions:
@joshtriplett said:
That style guide provision was written specifically to apply to "items", not to expressions.
So I think we should change it to work better with expressions. I propose:
Put short attributes on the same line for expression attributes, except for lambdas, so attributes on lambdas would still be on a separate line, but attributes for things like #[a] a + #[b] b could be on the same line
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 reproducing the two expression-attribute examples with rustfmt on stable, then read the linked Zulip thread for the existing formatting rationale. Done means agreeing on and implementing clearer placement for short expression attributes while keeping lambda attributes on a separate line, with formatting coverage for these cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100