rust-lang/rustfmt

Macro attributes containing consts not formatted correctly

Opened this issue · 1 comments

A real-world example from nutype:

This gets formatted just fine:

#[nutype(validate(len_char_min = 5, len_char_max = 20))]
struct Email(String);

But this does not:

#[nutype(validate(len_char_min = 5, len_char_max = 20, regex = EMAIL_REGEX))]
struct Email(String);

It looks like that rustfmt is not liking the EMAIL_REGEX here, but I'm not sure why.

Tested on rustfmt 1.8.0-nightly (3ed6e3cc69 2024-10-17).

Unfortunately this isn't an issue with rustfmt. It's an issue with the compiler. Specifically the ast::Attribute::meta method, which is returning None for your second example.

rustfmt uses the value it gets back from that call here to format the attribute, otherwise it'll leave the attribute unformatted.

if let Some(ref meta) = self.meta() {