rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Formatting inside the `lazy_static!` macro did not work when the macro is used with the crate name: `lazy_static::lazy_static!`

Open nejcgalof opened this issue 1 year ago • 3 comments

Formatting inside the lazy_static! macro did not work when the macro was used with the crate name: lazy_static::lazy_static!.

For example, that code is formatted well.

use lazy_static::lazy_static;
...
lazy_static! {
    static ref EXAMPLE: u8 = 42;
}

But when using the crate name directly with the macro, the macro is not formatted at all.

lazy_static::lazy_static! {
    static ref EXAMPLE: u8 = 42;
}

My prediction is that the problem is in that code, because the macro must match directly with the keyword: lazy_static!.

nejcgalof avatar Aug 19 '24 21:08 nejcgalof

That's likely the issue. Is it an issue to use lazy_static! instead of lazy_static::lazy_static! in your code?

ytmimi avatar Aug 19 '24 21:08 ytmimi

It is not a problem for my code to use lazy_static! instead of lazy_static::lazy_static!. I report the issue anyway if someone has the same issue. For example, if my code exceeds the maximum width in that section, the rest of the code is not formatted with my IDE. It would be good to solve that problem because the code is valid in both cases.

nejcgalof avatar Aug 19 '24 21:08 nejcgalof

Appreciate you taking the time to file the issue, and I'm glad to hear that there isn't any restriction that requires you to use lazy_static::lazy_static! instead of lazy_static!.

ytmimi avatar Aug 19 '24 21:08 ytmimi