Comment alignment breaks when exceeding the max_width
Open
Nobody has claimed this yet.
A-comments
P-low
SO-max_width
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
I've got the following piece of code, formatted by rustfmt:
pub struct InterruptsQueue {
pub vfio_event_fd: RawFd, // event fd
pub vfio_epoll_fd: RawFd, // epoll fd
pub interrupt_enabled: bool, // Whether interrupt for this queue is enabled or not
pub instr_counter: u64, // Instruction counter to avoid unnecessary calls to elapsed time
pub last_time_checked: Instant, // Last time the interrupt flag was checked
pub rx_pkts: u64, // The number of received packets since the last check
pub interval: u64, // The interval to check the interrupt flag
pub moving_avg: InterruptMovingAvg, // The moving average of the hybrid interrupt
}
In my opinion it would be great to get the following formatting:
pub struct InterruptsQueue {
pub vfio_event_fd: RawFd, // event fd
pub vfio_epoll_fd: RawFd, // epoll fd
pub interrupt_enabled: bool, // Whether interrupt for this queue is enabled or not
pub instr_counter: u64, // Instruction counter to avoid unnecessary calls to elapsed time
pub last_time_checked: Instant, // Last time the interrupt flag was checked
pub rx_pkts: u64, // The number of received packets since the last check
pub interval: u64, // The interval to check the interrupt flag
pub moving_avg: InterruptMovingAvg, // The moving average of the hybrid interrupt
}
Another option would be to not indent the comments at all. Is this fixable? I'm using version 1.4.4 of rustfmt.
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 reported struct formatting with rustfmt 1.4.4 and compare the current output with the requested alignment. Trace the comment-formatting entry point and any relevant formatter tests; done means comments remain aligned when the declaration exceeds max_width, or the documented alternative behavior is implemented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100