Skip to content

rustfmt removes crucial code from macro calls (regression) #6424

@nazar-pc

Description

@nazar-pc

Probably related to #6418, but not 100% sure.

rustfmt recently started formatting code like this incorrectly:

frame_support::construct_runtime!(
    pub struct Test {
        System: frame_system = 0,
        SelfDomainId: pallet_domain_id = 1,
    }
);

Specifically, it removes = NUMBER for some reason, resulting in this:

frame_support::construct_runtime!(
    pub struct Test {
        System: frame_system,
        SelfDomainId: pallet_domain_id,
    }
);

This is incorrect and not an equivalent change.

Affected version:

rustfmt 1.8.0-nightly (426d173423 2024-12-21)

Version that I used previously and that worked correctly:

rustfmt 1.8.0-nightly (4392847410 2024-10-21)

Activity

ytmimi

ytmimi commented on Dec 22, 2024

@ytmimi
Contributor

Thanks for the report. I tracked this change in behavior back to rust-lang/rust#129514

nazar-pc

nazar-pc commented on Dec 22, 2024

@nazar-pc
Author

Note that it also removes values which are not contiguous (let's say if = 0 is replaced with = 60), it just removes them all regardless.

ytmimi

ytmimi commented on Dec 22, 2024

@ytmimi
Contributor

@nazar-pc sorry, but I'm having a hard time understanding what you're getting at. Could you provide a code snippet?

nazar-pc

nazar-pc commented on Dec 22, 2024

@nazar-pc
Author

Sure:

frame_support::construct_runtime!(
    pub struct Test {
        System: frame_system = 60,
        SelfDomainId: pallet_domain_id = 1,
    }
);

In this case both will be removed too. I just assumed that in some cases it might remove things due to considering them being "the default", but no.

ytmimi

ytmimi commented on Dec 22, 2024

@ytmimi
Contributor

Thanks for the update. No, I don't think that's the case. An explanation for what's going on here can be found at rust-lang/rust#134668

added a commit that references this issue on Dec 23, 2024
c9c90dc
added a commit that references this issue on Dec 23, 2024
nazar-pc

nazar-pc commented on Dec 24, 2024

@nazar-pc
Author

Works correctly again in this version:

rustfmt 1.8.0-nightly (bdc6b3de48 2024-12-23)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @nazar-pc@ytmimi

        Issue actions

          rustfmt removes crucial code from macro calls (regression) · Issue #6424 · rust-lang/rustfmt