Skip to content

rustfmt formats a macro when it should not #6418

Open
@jaskij

Description

@jaskij

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions