Skip to content

presence of lint attributes changes const block formatting #6341

Open
@eric-seppanen

Description

@eric-seppanen

If I ask cargo fmt from 1.81.0 to format this code, I get:

const COUNT: u8 = 5;

pub struct Thing;

impl Thing {
    pub fn set() {
        #[allow(clippy::assertions_on_constants)]
        const {
            assert!(COUNT == 5)
        };
    }
}

Under 1.80.0 I get:

const COUNT: u8 = 5;

pub struct Thing;

impl Thing {
    pub fn set() {
        #[allow(clippy::assertions_on_constants)]
        const { assert!(COUNT == 5) };
    }
}

Weirdly, if I remove the lint attribute, then both 1.81.0 and 1.80.0 format the const block on a single line.

I'm on Ubuntu 22.04, with no rustfmt.toml and the rustfmt versions are:

$ .rustup/toolchains/1.80.0-x86_64-unknown-linux-gnu/bin/rustfmt -V
rustfmt 1.7.0-stable (0514789 2024-07-21)
$ .rustup/toolchains/1.81.0-x86_64-unknown-linux-gnu/bin/rustfmt -V
rustfmt 1.7.1-stable (eeb90cd 2024-09-04)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions