rustfmt formats a macro when it should not
Open
Nobody has claimed this yet.
A-macros
I-poor-formatting
P-low
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 24
Description
rustfmt is formatting - changing indentation - inside a macro, in what is not valid Rust code.
In the code below, if you change the indentation inside the proptest! macro, rustfmt will change it back to the way it is currently, when it should not. Repo with the repro.
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Item {
pub first_long_name_a: u16,
pub item_count: u16,
pub area: u16,
pub address: u16,
}
#[cfg(test)]
mod tests {
use proptest::prelude::*;
use super::Item;
proptest! {
#[test]
fn read_item_chars(s in "\\PC*") {
let pi = Item{
first_long_name_a: 0,item_count: 0,area: 0,address: 0,};
}
}
}
Tested on both 1.82 and nightly.
$ cargo fmt --version
rustfmt 1.7.1-stable (f6e511e 2024-10-15)
$ cargo +nightly fmt --version
rustfmt 1.8.0-nightly (33c245b9e9 2024-12-10)
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 behavior in the linked proptest repository and running the supplied stable and nightly cargo fmt versions. Done means rustfmt leaves indentation inside the proptest! macro unchanged when that content is not valid Rust code.
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
- 42/100