Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro attributes containing consts not formatted correctly #6374

Open
musjj opened this issue Oct 23, 2024 · 1 comment
Open

Macro attributes containing consts not formatted correctly #6374

musjj opened this issue Oct 23, 2024 · 1 comment

Comments

@musjj
Copy link

musjj commented Oct 23, 2024

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).

@ytmimi
Copy link
Contributor

ytmimi commented Oct 28, 2024

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() {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants