Skip to content

rustfmt removes inner attributes from inline const blocks #6158

@matthieu-m

Description

@matthieu-m

Clippy unfortunately warns about asserts whose conditions can be evaluated at compile-time even in inline const blocks. It's a known issue, it'll hopefully be solved at some point.

In the meantime, if one wishes to perform such compile-time asserts without disabling the lint globally, one can simply allow the offending lint:

fn main() {
    const {
        #![allow(clippy::assertions_on_constants)]

        assert!(1 < 2);
    }
}

Unfortunately, running rustfmt on the above will simply remove the attribute (try it on the playground), resulting in:

fn main() {
    const {
        assert!(1 < 2);
    }
}

And then Clippy nags at us again :'(

With inline const blocks due to being stabilized for 1.79 (in 6 weeks), it would be nice to fix rustfmt to not eat their code away.

Meta

rustfmt version:

1.7.0-nightly (2024-05-03 d2d24e3)

Metadata

Metadata

Assignees

Labels

C-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEgood first issueIssues up for grabs, also good candidates for new rustfmt contributors

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions